void dialog_publish(char *state, struct to_body* entity, struct to_body *peer, str *callid, unsigned int initiator, unsigned int lifetime, str *localtag, str *remotetag) { str* body= NULL; publ_info_t publ; int ret_code; body= build_dialoginfo(state, entity, peer, callid, initiator, localtag, remotetag); if(body == NULL || body->s == NULL) { LM_ERR("failed to construct dialoginfo body\n"); goto error; } memset(&publ, 0, sizeof(publ_info_t)); publ.pres_uri= &entity->uri; publ.body = body; publ.id = *callid; publ.content_type.s= "application/dialog-info+xml"; publ.content_type.len= 27; publ.expires= lifetime; /* make UPDATE_TYPE, as if this "publish dialog" is not found by pua it will fallback to INSERT_TYPE anyway */ publ.flag|= UPDATE_TYPE; publ.source_flag|= DIALOG_PUBLISH; publ.event|= DIALOG_EVENT; publ.extra_headers= NULL; publ.outbound_proxy = presence_server; print_publ(&publ); ret_code = pua_send_publish(&publ); switch (ret_code) { case ERR_PUBLISH_NO_ERROR: case ERR_PUBLISH_NO_RECORD: break; default: LM_ERR("sending publish failed for pres_uri [%.*s] to server [%.*s]\n", publ.pres_uri->len, publ.pres_uri->s, publ.outbound_proxy.len, publ.outbound_proxy.s); } error: if(body) { if(body->s) xmlFree(body->s); pkg_free(body); } return; }
void ul_publish(ucontact_t* c, int type, void* param) { str* body= NULL; str uri= {NULL, 0}; char* at= NULL; publ_info_t* publ= NULL; int size= 0; str content_type; int error; if(destroy_modules_phase()) return; content_type.s= "application/pidf+xml"; content_type.len= 20; if(pua_ul_publish==0 && pua_ul_bmask==0) { LM_INFO("should not send ul publish\n"); return; } if(pua_ul_bmask!=0 && (c->cflags & pua_ul_bmask)==0) { LM_INFO("not marked for publish\n"); return; } if(type & UL_CONTACT_DELETE) { LM_DBG("\nDELETE type\n"); } else { if(type & UL_CONTACT_INSERT) { LM_DBG("\nINSERT type\n"); } else { if(type & UL_CONTACT_UPDATE) { LM_DBG("\nUPDATE type\n"); } else { if(type & UL_CONTACT_EXPIRE) { LM_DBG("\nEXPIRE type\n"); } } } } if(type & UL_CONTACT_INSERT) { body= build_pidf(c); if(body == NULL || body->s == NULL) goto error; } else body = NULL; uri.s = (char*)pkg_malloc(sizeof(char)*(c->aor->len+default_domain.len+6)); if(uri.s == NULL) goto error; memcpy(uri.s, "sip:", 4); uri.len = 4; memcpy(uri.s+ uri.len, c->aor->s, c->aor->len); uri.len+= c->aor->len; at = memchr(c->aor->s, '@', c->aor->len); if(!at) { uri.s[uri.len++]= '@'; memcpy(uri.s+ uri.len, default_domain.s, default_domain.len); uri.len+= default_domain.len; } LM_DBG("uri= %.*s\n", uri.len, uri.s); size= sizeof(publ_info_t)+ sizeof(str)+( uri.len +c->callid.len+ 12 + content_type.len)*sizeof(char); if(body) size+= sizeof(str)+ body->len* sizeof(char); publ= (publ_info_t*)pkg_malloc(size); if(publ== NULL) { LM_ERR("no more share memory\n"); goto error; } memset(publ, 0, size); size= sizeof(publ_info_t); publ->pres_uri= (str*)((char*)publ + size); size+= sizeof(str); publ->pres_uri->s= (char*)publ+ size; memcpy(publ->pres_uri->s, uri.s, uri.len); publ->pres_uri->len= uri.len; size+= uri.len; if(body) { publ->body= (str*)( (char*)publ + size); size+= sizeof(str); publ->body->s= (char*)publ + size; memcpy(publ->body->s, body->s, body->len); publ->body->len= body->len; size+= body->len; } publ->id.s= (char*)publ+ size; memcpy(publ->id.s, "UL_PUBLISH.", 11); memcpy(publ->id.s+11, c->callid.s, c->callid.len); publ->id.len= 11+ c->callid.len; size+= publ->id.len; publ->content_type.s= (char*)publ+ size; memcpy(publ->content_type.s, content_type.s, content_type.len); publ->content_type.len= content_type.len; size+= content_type.len; if(type & UL_CONTACT_EXPIRE || type & UL_CONTACT_DELETE) publ->expires= 0; else publ->expires= c->expires - (int)time(NULL); if(type & UL_CONTACT_INSERT) publ->flag|= INSERT_TYPE; else publ->flag|= UPDATE_TYPE; publ->source_flag|= UL_PUBLISH; publ->event|= PRESENCE_EVENT; publ->extra_headers= NULL; print_publ(publ); if((error=_pu_pua.send_publish(publ))< 0) { LM_ERR("failed sending publish for ul event %d\n", type); if((type & UL_CONTACT_UPDATE) && error == ERR_PUBLISH_NO_BODY) { /* This error can occur if Kamailio was restarted/stopped and for any reason couldn't store a pua * entry in 'pua' DB table. It can also occur if 'pua' table is cleaned externally while Kamailio * is stopped so cannot retrieve these entries from DB when restarting. * In these cases, when a refresh registration for that user creates an UPDATE action in pua_usrloc, * pua 'ul_publish()' would fail since the appropiate entry doesn't exist in pua hast table ("New * PUBLISH and no body found - invalid request"). * This code solves this problem by invoking an INSERT action if an UPDATE action failed due to the * above error. It will however generate a new presentity entry in the presence server (until the * previous one expires), but this is a minor issue. */ LM_ERR("UPDATE action generated a PUBLISH without body -> invoking INSERT action\n"); ul_publish(c, UL_CONTACT_INSERT, param); goto error; } } error: pua_ul_publish = 0; if(publ) pkg_free(publ); if(body) { if(body->s) xmlFree(body->s); pkg_free(body); } if(uri.s) pkg_free(uri.s); return; }
void dialog_publish(char *state, str* ruri, str *entity, str *peer, str *callid, unsigned int initiator, unsigned int lifetime, str *localtag, str *remotetag, str *localtarget, str *remotetarget, unsigned short do_pubruri_localcheck) { str* body= NULL; str uri= {NULL, 0}; publ_info_t* publ= NULL; int size= 0; str content_type; struct sip_uri ruri_uri; if (parse_uri(ruri->s, ruri->len, &ruri_uri) < 0) { LM_ERR("failed to parse the PUBLISH R-URI\n"); return; } if(do_pubruri_localcheck) { /* send PUBLISH only if the receiver PUBLISH R-URI is local*/ if (!check_self(&(ruri_uri.host), 0, 0)) { LM_DBG("do not send PUBLISH to external URI %.*s\n",ruri->len, ruri->s); return; } } content_type.s= "application/dialog-info+xml"; content_type.len= 27; body= build_dialoginfo(state, entity, peer, callid, initiator, localtag, remotetag, localtarget, remotetarget); if(body == NULL || body->s == NULL) goto error; LM_DBG("publish uri= %.*s\n", ruri->len, ruri->s); size= sizeof(publ_info_t) + sizeof(str) /* *pres_uri */ + ( ruri->len /* pres_uri->s */ + callid->len + 16 /* id.s */ + content_type.len /* content_type.s */ )*sizeof(char); if(body) size+= sizeof(str)+ body->len* sizeof(char); publ= (publ_info_t*)pkg_malloc(size); if(publ== NULL) { LM_ERR("no more share memory\n"); goto error; } memset(publ, 0, size); size= sizeof(publ_info_t); publ->pres_uri= (str*)((char*)publ + size); size+= sizeof(str); publ->pres_uri->s= (char*)publ+ size; memcpy(publ->pres_uri->s, ruri->s, ruri->len); publ->pres_uri->len= ruri->len; size+= ruri->len; if(body) { publ->body= (str*)( (char*)publ + size); size+= sizeof(str); publ->body->s= (char*)publ + size; memcpy(publ->body->s, body->s, body->len); publ->body->len= body->len; size+= body->len; } publ->id.s= (char*)publ+ size; memcpy(publ->id.s, "DIALOG_PUBLISH.", 15); memcpy(publ->id.s+15, callid->s, callid->len); publ->id.len= 15+ callid->len; size+= publ->id.len; publ->content_type.s= (char*)publ+ size; memcpy(publ->content_type.s, content_type.s, content_type.len); publ->content_type.len= content_type.len; size+= content_type.len; publ->expires= lifetime; /* make UPDATE_TYPE, as if this "publish dialog" is not found by pua it will fallback to INSERT_TYPE anyway */ publ->flag|= UPDATE_TYPE; publ->source_flag|= DIALOG_PUBLISH; publ->event|= DIALOG_EVENT; publ->extra_headers= NULL; print_publ(publ); if(pua_send_publish(publ)< 0) { LM_ERR("while sending publish\n"); } error: if(publ) pkg_free(publ); if(body) { if(body->s) xmlFree(body->s); pkg_free(body); } if(uri.s) pkg_free(uri.s); return; }
void ul_publish(ucontact_t* c, int type, void* param) { str* body= NULL; str uri= {NULL, 0}; char* at= NULL; publ_info_t* publ= NULL; int size= 0; str content_type; content_type.s= "application/pidf+xml"; content_type.len= 20; if(pua_ul_publish== 0) { LM_INFO("should not send ul publish\n"); return; } if(type & UL_CONTACT_DELETE) LM_DBG("\nul_publish: DELETE type\n"); else if(type & UL_CONTACT_INSERT) LM_DBG("\nul_publish: INSERT type\n"); else if(type & UL_CONTACT_UPDATE) LM_DBG("\nul_publish: UPDATE type\n"); else if(type & UL_CONTACT_EXPIRE) LM_DBG("\nul_publish: EXPIRE type\n"); if(type & UL_CONTACT_INSERT) { body= build_pidf(c); if(body == NULL || body->s == NULL) goto error; } else body = NULL; uri.s = (char*)pkg_malloc(sizeof(char)*(c->aor->len+default_domain.len+6)); if(uri.s == NULL) goto error; memcpy(uri.s, "sip:", 4); uri.len = 4; memcpy(uri.s+ uri.len, c->aor->s, c->aor->len); uri.len+= c->aor->len; at = memchr(c->aor->s, '@', c->aor->len); if(!at) { uri.s[uri.len++]= '@'; memcpy(uri.s+ uri.len, default_domain.s, default_domain.len); uri.len+= default_domain.len; } LM_DBG("ul_publish: uri= %.*s\n", uri.len, uri.s); size= sizeof(publ_info_t)+ sizeof(str)+( uri.len +c->callid.len+ 12 + content_type.len)*sizeof(char); if(body) size+= sizeof(str)+ body->len* sizeof(char); publ= (publ_info_t*)pkg_malloc(size); if(publ== NULL) { LM_ERR("no more share memory\n"); goto error; } memset(publ, 0, size); size= sizeof(publ_info_t); publ->pres_uri= (str*)((char*)publ + size); size+= sizeof(str); publ->pres_uri->s= (char*)publ+ size; memcpy(publ->pres_uri->s, uri.s, uri.len); publ->pres_uri->len= uri.len; size+= uri.len; if(body) { publ->body= (str*)( (char*)publ + size); size+= sizeof(str); publ->body->s= (char*)publ + size; memcpy(publ->body->s, body->s, body->len); publ->body->len= body->len; size+= body->len; } publ->id.s= (char*)publ+ size; memcpy(publ->id.s, "UL_PUBLISH.", 11); memcpy(publ->id.s+11, c->callid.s, c->callid.len); publ->id.len= 11+ c->callid.len; size+= publ->id.len; publ->content_type.s= (char*)publ+ size; memcpy(publ->content_type.s, content_type.s, content_type.len); publ->content_type.len= content_type.len; size+= content_type.len; if(type & UL_CONTACT_EXPIRE || type & UL_CONTACT_DELETE) publ->expires= 0; else publ->expires= c->expires - (int)time(NULL); if(type & UL_CONTACT_INSERT) publ->flag|= INSERT_TYPE; else publ->flag|= UPDATE_TYPE; publ->source_flag|= UL_PUBLISH; publ->event|= PRESENCE_EVENT; publ->extra_headers= NULL; print_publ(publ); if(pua_send_publish(publ)< 0) { LM_ERR("while sending publish\n"); } pua_ul_publish= 0; error: if(publ) pkg_free(publ); if(body) { if(body->s) xmlFree(body->s); pkg_free(body); } if(uri.s) pkg_free(uri.s); pua_ul_publish= 0; return; }