presence: pass str parameters via pointer to couple of functions
authorDaniel-Constantin Mierla <miconda@gmail.com>
Tue, 14 Apr 2020 10:12:08 +0000 (12:12 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Tue, 14 Apr 2020 10:15:48 +0000 (12:15 +0200)
src/modules/presence/bind_presence.h
src/modules/presence/hash.c
src/modules/presence/hash.h
src/modules/presence/presence.c
src/modules/presence/presence.h
src/modules/presence/presentity.c
src/modules/presence/presentity.h
src/modules/presence/publish.c

index 2f8b3d3..0b786ac 100644 (file)
@@ -35,7 +35,7 @@
 #include "presentity.h"
 #include "../../core/sr_module.h"
 
-typedef int (*update_watchers_t)(str pres_uri, pres_ev_t *ev, str *rules_doc);
+typedef int (*update_watchers_t)(str *pres_uri, pres_ev_t *ev, str *rules_doc);
 typedef str *(*pres_get_presentity_t)(
                str pres_uri, pres_ev_t *ev, str *etag, str *contact);
 typedef void (*pres_free_presentity_t)(str *presentity, pres_ev_t *ev);
index ea50ab6..0b63534 100644 (file)
@@ -625,7 +625,7 @@ int delete_phtable(str *pres_uri, int event)
        return 0;
 }
 
-int update_phtable(presentity_t *presentity, str pres_uri, str body)
+int update_phtable(presentity_t *presentity, str *pres_uri, str *body)
 {
        char *sphere = NULL;
        unsigned int hash_code;
@@ -641,11 +641,11 @@ int update_phtable(presentity_t *presentity, str pres_uri, str body)
        }
 
        /* search for record in hash table */
-       hash_code = core_case_hash(&pres_uri, NULL, phtable_size);
+       hash_code = core_case_hash(pres_uri, NULL, phtable_size);
 
        lock_get(&pres_htable[hash_code].lock);
 
-       p = search_phtable(&pres_uri, presentity->event->evp->type, hash_code);
+       p = search_phtable(pres_uri, presentity->event->evp->type, hash_code);
        if(p == NULL) {
                lock_release(&pres_htable[hash_code].lock);
                goto done;
index 6d13018..8c2441a 100644 (file)
@@ -53,8 +53,8 @@ struct presentity;
                size += source.len;                   \
        } while(0)
 
-#define PKG_MEM_TYPE 1 << 1
-#define SHM_MEM_TYPE 1 << 2
+#define PKG_MEM_TYPE (1 << 1)
+#define SHM_MEM_TYPE (1 << 2)
 
 extern int pres_delete_same_subs;
 
@@ -132,7 +132,7 @@ pres_entry_t *search_phtable(str *pres_uri, int event, unsigned int hash_code);
 
 int insert_phtable(str *pres_uri, int event, char *sphere);
 
-int update_phtable(struct presentity *presentity, str pres_uri, str body);
+int update_phtable(struct presentity *presentity, str *pres_uri, str *body);
 
 int delete_phtable(str *pres_uri, int event);
 
index 4e42e99..107563b 100644 (file)
@@ -124,7 +124,6 @@ static int fixup_presence(void **param, int param_no);
 static int fixup_subscribe(void **param, int param_no);
 static int update_pw_dialogs(
                subs_t *subs, unsigned int hash_code, subs_t **subs_array);
-int update_watchers_status(str pres_uri, pres_ev_t *ev, str *rules_doc);
 static int w_pres_auth_status(struct sip_msg *_msg, char *_sp1, char *_sp2);
 static int w_pres_refresh_watchers(
                struct sip_msg *msg, char *puri, char *pevent, char *ptype);
@@ -658,7 +657,7 @@ int pres_refresh_watchers(
                        goto error;
                }
 
-               if(update_watchers_status(*pres, ev, rules_doc) < 0) {
+               if(update_watchers_status(pres, ev, rules_doc) < 0) {
                        LM_ERR("failed to update watchers\n");
                        goto error;
                }
@@ -824,7 +823,7 @@ int pres_db_delete_status(subs_t *s)
        return 0;
 }
 
-int update_watchers_status(str pres_uri, pres_ev_t *ev, str *rules_doc)
+int update_watchers_status(str *pres_uri, pres_ev_t *ev, str *rules_doc)
 {
        subs_t subs;
        db_key_t query_cols[6], result_cols[5];
@@ -863,7 +862,7 @@ int update_watchers_status(str pres_uri, pres_ev_t *ev, str *rules_doc)
        }
 
        memset(&subs, 0, sizeof(subs_t));
-       subs.pres_uri = pres_uri;
+       subs.pres_uri = *pres_uri;
        subs.event = ev;
        subs.auth_rules_doc = rules_doc;
 
@@ -871,7 +870,7 @@ int update_watchers_status(str pres_uri, pres_ev_t *ev, str *rules_doc)
        query_cols[n_query_cols] = &str_presentity_uri_col;
        query_vals[n_query_cols].nul = 0;
        query_vals[n_query_cols].type = DB1_STR;
-       query_vals[n_query_cols].val.str_val = pres_uri;
+       query_vals[n_query_cols].val.str_val = *pres_uri;
        n_query_cols++;
 
        query_cols[n_query_cols] = &str_event_col;
@@ -905,7 +904,7 @@ int update_watchers_status(str pres_uri, pres_ev_t *ev, str *rules_doc)
        }
 
        LM_DBG("found %d record-uri in watchers_table\n", result->n);
-       hash_code = core_case_hash(&pres_uri, &ev->name, shtable_size);
+       hash_code = core_case_hash(pres_uri, &ev->name, shtable_size);
        subs.db_flag = hash_code;
 
        /* must do a copy as sphere_check requires database queries */
@@ -1627,7 +1626,7 @@ static int ki_pres_update_watchers(
                return -1;
        }
        ret = 1;
-       if(update_watchers_status(*pres_uri, ev, rules_doc) < 0) {
+       if(update_watchers_status(pres_uri, ev, rules_doc) < 0) {
                LM_ERR("updating watchers in presence\n");
                ret = -1;
        }
index 151647c..1e54496 100644 (file)
@@ -103,7 +103,7 @@ extern sruid_t pres_sruid;
 
 extern db_locking_t pres_db_table_lock;
 
-int update_watchers_status(str pres_uri, pres_ev_t *ev, str *rules_doc);
+int update_watchers_status(str *pres_uri, pres_ev_t *ev, str *rules_doc);
 int pres_auth_status(struct sip_msg *msg, str watcher_uri, str presentity_uri);
 int _api_pres_refresh_watchers(str *pres, str *event, int type);
 
index 03ec6ee..7e742f5 100644 (file)
@@ -1103,7 +1103,7 @@ int update_presentity(struct sip_msg *msg, presentity_t *presentity, str *body,
                        if(pres_sphere_enable
                                        && presentity->event->evp->type == EVENT_PRESENCE) {
                                if(publ_cache_enabled
-                                               && update_phtable(presentity, pres_uri, *body) < 0) {
+                                               && update_phtable(presentity, &pres_uri, body) < 0) {
                                        LM_ERR("failed to update sphere for presentity\n");
                                        goto error;
                                }
@@ -1374,7 +1374,7 @@ int pres_htable_restore(void)
                        if(pres_sphere_enable && event == EVENT_PRESENCE) {
                                body.s = (char *)row_vals[body_col].val.string_val;
                                body.len = strlen(body.s);
-                               sphere = extract_sphere(body);
+                               sphere = extract_sphere(&body);
                        }
 
                        if(insert_phtable(&uri, event, sphere) < 0) {
@@ -1401,7 +1401,7 @@ error:
        return -1;
 }
 
-char *extract_sphere(str body)
+char *extract_sphere(str *body)
 {
 
        /* check for a rpid sphere element */
@@ -1410,7 +1410,7 @@ char *extract_sphere(str body)
        char *cont, *sphere = NULL;
 
 
-       doc = xmlParseMemory(body.s, body.len);
+       doc = xmlParseMemory(body->s, body->len);
        if(doc == NULL) {
                LM_ERR("failed to parse xml body\n");
                return NULL;
@@ -1580,7 +1580,7 @@ char *get_sphere(str *pres_uri)
                goto error;
        }
 
-       sphere = extract_sphere(body);
+       sphere = extract_sphere(&body);
 
        pa_dbf.free_result(pa_db, result);
 
@@ -1872,7 +1872,7 @@ int _api_update_presentity(str *event, str *realm, str *user, str *etag,
        pres = new_presentity(realm, user, expires, ev, etag, sender);
 
        if(pres_sphere_enable) {
-               sphere = extract_sphere(*body);
+               sphere = extract_sphere(body);
        }
        if(pres) {
                ret = update_presentity(
index 6d2b8ee..b2d39aa 100644 (file)
@@ -68,7 +68,7 @@ char *generate_ETag(int publ_count);
 
 int pres_htable_restore(void);
 
-char *extract_sphere(str body);
+char *extract_sphere(str *body);
 
 char *get_sphere(str *pres_uri);
 typedef char *(*pres_get_sphere_t)(str *pres_uri);
index aebb299..41c0486 100644 (file)
@@ -387,7 +387,7 @@ int ki_handle_publish_uri(struct sip_msg *msg, str *sender_uri)
 
                if(pres_sphere_enable && event->evp->type == EVENT_PRESENCE
                                && get_content_type(msg) == SUBTYPE_PIDFXML) {
-                       sphere = extract_sphere(body);
+                       sphere = extract_sphere(&body);
                }
        }
        memset(&puri, 0, sizeof(struct sip_uri));
@@ -538,7 +538,7 @@ int update_hard_presentity(
                xmlDocPtr doc;
 
                if(pres_sphere_enable) {
-                       sphere = extract_sphere(*pidf_doc);
+                       sphere = extract_sphere(pidf_doc);
                }
 
                doc = xmlParseMemory(pidf_doc->s, pidf_doc->len);