Skip to content

Commit

Permalink
presence: fix several issues when using build_notify_body_t
Browse files Browse the repository at this point in the history
* use the custom content type body if provided
* populate the actual pres_ev_t list element with the build_notify_body_t
  function
* use a proper free function for the notify body string in case of error
* improve comment-docs for build_notify_body_t
  • Loading branch information
rvlad-patrascu committed Jan 9, 2020
1 parent cd78b83 commit 4deff0d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions modules/presence/event_list.c
Expand Up @@ -226,6 +226,7 @@ int add_event(pres_ev_t* event)
ev->aux_free_body= event->aux_free_body;
ev->free_body= event->free_body;
ev->build_empty_pres_info= event->build_empty_pres_info;
ev->build_notify_body= event->build_notify_body;
ev->default_expires= event->default_expires;

if(not_in_list)
Expand Down
5 changes: 3 additions & 2 deletions modules/presence/event_list.h
Expand Up @@ -73,13 +73,14 @@ typedef int (get_rules_doc_t)(str* user, str* domain, str** rules_doc);
* subscribe, instead of pushing a notify with a body built from the published
* presentities, you can dynamically build with this function whatever
* body you want to be returned with the body
* A free_body_t function must also be provided if this function is used.
* Input data: presentity SIP URI and the SUBSCRIBE's body
* Output data: * the body (may be empty string if nothing to return); it must
* Output data: * the body (may be NULL if nothing to return); it must
* be a pkg allocated str and separate pkg allocated body
* * the content-type string - must be a pkg mem chunk
* holding the CT body; note that the str itself is managed by
* the upper/calling layer, so just use/write into it.
* Returns : body str upon success, NULL upon error
* Returns : body str or NULL (on error or no body to be returned)
*/
typedef str* (build_notify_body_t)(str *pres_uri, str *subs_body,
str *ct_type);
Expand Down
15 changes: 10 additions & 5 deletions modules/presence/notify.c
Expand Up @@ -219,12 +219,16 @@ int build_str_hdr(subs_t* subs, int is_body, str* hdr, str *ct_body,
p += CRLF_LEN;
}

if(is_body && subs->event->content_type.s && subs->event->content_type.len)
if (!ct_body->len &&
subs->event->content_type.s && subs->event->content_type.len)
ct_body = &subs->event->content_type;

if(is_body && ct_body->len)
{
memcpy(p,"Content-Type: ", 14);
p += 14;
memcpy(p, subs->event->content_type.s , subs->event->content_type.len);
p += subs->event->content_type.len;
memcpy(p, ct_body->s , ct_body->len);
p += ct_body->len;
memcpy(p, CRLF, CRLF_LEN);
p += CRLF_LEN;
}
Expand Down Expand Up @@ -2052,6 +2056,7 @@ int send_notify_request(subs_t* subs, subs_t * watcher_subs,
} else if (subs->event->build_notify_body) {
notify_body = subs->event->build_notify_body(
&subs->pres_uri, &subs->subs_body, &ct_body);
free_fct = subs->event->free_body;
} else {
notify_body = get_p_notify_body(subs->pres_uri,
subs->event, 0, 0, (subs->contact.s)?&subs->contact:NULL,
Expand Down Expand Up @@ -2200,8 +2205,8 @@ int send_notify_request(subs_t* subs, subs_t * watcher_subs,
if(subs->event->type& WINFO_TYPE)
xmlFree(notify_body->s);
else
if(subs->event->apply_auth_nbody== NULL && subs->event->agg_nbody== NULL)
pkg_free(notify_body->s);
if(free_fct)
free_fct(notify_body->s);
else
subs->event->free_body(notify_body->s);
}
Expand Down

0 comments on commit 4deff0d

Please sign in to comment.