Module: kamailio
Branch: master
Commit: c858cecb4d6589bc53c474b0520a5d060bd3c55b
URL: 
https://github.com/kamailio/kamailio/commit/c858cecb4d6589bc53c474b0520a5d060bd3c55b

Author: Thomas <1258170+thomasseves...@users.noreply.github.com>
Committer: Henning Westerholt <h...@gilawa.com>
Date: 2025-04-04T18:04:27+02:00

pua_json: add support for as-feature-event

---

Modified: src/modules/pua_json/defs.h
Modified: src/modules/pua_json/pua_json_publish.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/c858cecb4d6589bc53c474b0520a5d060bd3c55b.diff
Patch: 
https://github.com/kamailio/kamailio/commit/c858cecb4d6589bc53c474b0520a5d060bd3c55b.patch

---

diff --git a/src/modules/pua_json/defs.h b/src/modules/pua_json/defs.h
index ebf0ba4a0b9..ad5a8eb1eb0 100644
--- a/src/modules/pua_json/defs.h
+++ b/src/modules/pua_json/defs.h
@@ -68,12 +68,20 @@
 #define MWI_JSON_FROM "From"
 #define MWI_JSON_TO "To"
 
+#define AS_FEATURE_JSON_CALLID "Call-ID"
+#define AS_FEATURE_JSON_FROM "From"
+#define AS_FEATURE_JSON_FROM_USER "From-User"
+#define AS_FEATURE_JSON_FROM_REALM "From-Realm"
+#define AS_FEATURE_JSON_DND_STATUS "DND-Status"
+#define AS_FEATURE_JSON_EXPIRES "Expires"
+
 #define TO_TAG_BUFFER_SIZE 128
 #define FROM_TAG_BUFFER_SIZE 128
 #define SENDER_BUFFER_SIZE 1024
 #define DIALOGINFO_BODY_BUFFER_SIZE 8192
 #define MWI_BODY_BUFFER_SIZE 2048
 #define PRESENCE_BODY_BUFFER_SIZE 4096
+#define AS_FEATURE_BODY_BUFFER_SIZE 4096
 
 #define MWI_BODY_VOICE_MESSAGE                                           \
        "Messages-Waiting: %.*s\r\nMessage-Account: %.*s\r\nVoice-Message: " \
@@ -139,4 +147,12 @@
 </dialog>\
 </dialog-info>"
 
+#define AS_FEATURE_BODY \
+       "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\
+<DoNotDisturbEvent 
xmlns=\"http://www.ecma-international.org/standards/ecma-323/csta/ed3\";>\
+<device>%.*s</device>\
+<doNotDisturbOn>%.*s</doNotDisturbOn>\
+</DoNotDisturbEvent>\
+"
+
 #endif /* _PUA_JSON_DEFS_H_ */
diff --git a/src/modules/pua_json/pua_json_publish.c 
b/src/modules/pua_json/pua_json_publish.c
index 359c5071858..3444210f39f 100644
--- a/src/modules/pua_json/pua_json_publish.c
+++ b/src/modules/pua_json/pua_json_publish.c
@@ -38,6 +38,7 @@ extern int pua_include_entity;
 str str_event_message_summary = str_init("message-summary");
 str str_event_dialog = str_init("dialog");
 str str_event_presence = str_init("presence");
+str str_event_as_feature_event = str_init("as-feature-event");
 
 str str_username_col = str_init("username");
 str str_domain_col = str_init("domain");
@@ -359,6 +360,62 @@ int pua_json_publish_dialoginfo_to_presentity(struct 
json_object *json_obj)
        return ret;
 }
 
+int pua_json_publish_as_feature_to_presentity(struct json_object *json_obj)
+{
+       int ret = 1;
+       int len;
+       str event = str_init("as-feature-event");
+       str from = {0, 0};
+       str from_user = {0, 0};
+       str from_realm = {0, 0};
+       str callid = {0, 0};
+       str dnd_status = {0, 0};
+       int expires = 0;
+       str as_feature_body = {0, 0};
+
+       char *body = (char *)pkg_malloc(AS_FEATURE_BODY_BUFFER_SIZE);
+
+       if(body == NULL) {
+               LM_ERR("Error allocating buffer for publish\n");
+               ret = -1;
+               goto error;
+       }
+
+       json_api.extract_field(json_obj, AS_FEATURE_JSON_CALLID, &callid);
+
+       json_api.extract_field(json_obj, AS_FEATURE_JSON_FROM, &from);
+       json_api.extract_field(json_obj, AS_FEATURE_JSON_FROM_USER, &from_user);
+       json_api.extract_field(json_obj, AS_FEATURE_JSON_FROM_REALM, 
&from_realm);
+
+       json_api.extract_field(json_obj, AS_FEATURE_JSON_DND_STATUS, 
&dnd_status);
+
+       struct json_object *ExpiresObj =
+                       json_api.get_object(json_obj, AS_FEATURE_JSON_EXPIRES);
+       if(ExpiresObj != NULL) {
+               expires = json_object_get_int(ExpiresObj);
+       }
+
+       if(!from_user.len || !dnd_status.len) {
+               LM_ERR("missing one of From-User / DND-Status\n");
+               goto error;
+       }
+
+       len = snprintf(body, AS_FEATURE_BODY_BUFFER_SIZE, AS_FEATURE_BODY,
+                       from_user.len, from_user.s, dnd_status.len, 
dnd_status.s);
+
+       as_feature_body.s = body;
+       as_feature_body.len = len;
+
+       pua_json_update_presentity(&event, &from_realm, &from_user, &callid, 
&from,
+                       &as_feature_body, expires, 1, 1);
+
+error:
+
+       if(body)
+               pkg_free(body);
+
+       return ret;
+}
 
 int pua_json_publish(struct sip_msg *msg, char *json)
 {
@@ -391,6 +448,11 @@ int pua_json_publish(struct sip_msg *msg, char *json)
                                                         event_package.len)
                                                         == 0) {
                        ret = pua_json_publish_presence_to_presentity(json_obj);
+               } else if(event_package.len == str_event_as_feature_event.len
+                                 && strncmp(event_package.s, 
str_event_as_feature_event.s,
+                                                        event_package.len)
+                                                        == 0) {
+                       ret = 
pua_json_publish_as_feature_to_presentity(json_obj);
                }
        }
 

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to