/* Relay a MESSAGE to a SIP client */ int xmpp_send_sip_msg(char *from, char *to, char *msg) { str msg_type = { "MESSAGE", 7 }; str hdr, fromstr, tostr, msgstr; char buf[512]; char buf_from[256]; ENC_SIP_URI(fromstr, buf_from, from); hdr.s = buf; hdr.len = snprintf(buf, sizeof(buf), "Content-type: text/plain" CRLF "Contact: %s" CRLF, from); tostr.s = uri_xmpp2sip(to, &tostr.len); if(tostr.s == NULL) { LM_ERR("Failed to translate xmpp uri to sip uri\n"); return -1; } msgstr.s = msg; msgstr.len = strlen(msg); return tmb.t_request( &msg_type, /* Type of the message */ 0, /* Request-URI */ &tostr, /* To */ &fromstr, /* From */ &hdr, /* Optional headers */ &msgstr, /* Message body */ (outbound_proxy.s)?&outbound_proxy:NULL,/* Outbound proxy*/ 0, /* Callback function */ 0, 0 /* Callback parameter */ ); }
int presence_subscribe(xmlNodePtr pres_node, int expires,int flag) { subs_info_t subs; char* type= NULL, *uri= NULL; str to_uri= {0, 0}; str from_uri= {0, 0}; char buf_from[256]; uri= XMLNodeGetAttrContentByName(pres_node, "to"); if(uri== NULL) { LM_ERR("failed to get to attribute from xml doc\n"); return -1; } to_uri.s = xmpp_uri_xmpp2sip(uri, &to_uri.len); if(to_uri.s == 0) { LM_ERR("failed to get from attribute from xml doc\n"); goto error; } xmlFree(uri); uri= XMLNodeGetAttrContentByName(pres_node, "from"); if(uri == NULL) { LM_ERR("failed to get from attribute from xml doc\n"); goto error; } ENC_SIP_URI(from_uri, buf_from, uri); xmlFree(uri); memset(&subs, 0, sizeof(subs_info_t)); subs.pres_uri= &to_uri; subs.watcher_uri= &from_uri; subs.contact= &server_address; if(presence_server.s) subs.outbound_proxy = &presence_server; /* type= XMLNodeGetAttrContentByName(pres_node, "type" ); if(strcmp(type, "subscribe")==0 ||strcmp(type, "probe")== 0) subs->flag|= INSERT_TYPE; else if(strcmp(type, "unsubscribe")== 0) subs->flag|= UPDATE_TYPE; xmlFree(type); type= NULL; */ subs.source_flag|= flag; subs.event= PRESENCE_EVENT; subs.expires= expires; if(presence_server.s && presence_server.len) subs.outbound_proxy = &presence_server; LM_DBG("XMPP subscription to [%.*s] , from [%.*s], expires= [%d]\n", subs.pres_uri->len, subs.pres_uri->s, subs.watcher_uri->len, subs.watcher_uri->s, expires); if(subs.outbound_proxy) LM_DBG("outbound_proxy= %.*s\n", subs.outbound_proxy->len, subs.outbound_proxy->s); if(pua_send_subscribe(&subs)< 0) { LM_ERR("while sending SUBSCRIBE\n"); goto error; } return 0; error: if(type) xmlFree(type); return -1; }
int build_publish(xmlNodePtr pres_node, int expires) { str* body= NULL; publ_info_t publ; char* resource= NULL; str pres_uri= {0, 0}; char* slash; char buf[256]; char* uri; uri = XMLNodeGetAttrContentByName(pres_node, "from"); if(uri == NULL) { LM_DBG("getting 'from' attribute\n"); return -1; } ENC_SIP_URI(pres_uri, buf, uri); xmlFree(uri); slash= memchr(pres_uri.s, '/', pres_uri.len); if(slash) { pres_uri.len= slash- pres_uri.s; resource= (char*)pkg_malloc((strlen(pres_uri.s)-pres_uri.len)*sizeof(char)); if(resource== NULL) { LM_ERR("no more memory\n"); return -1; } strcpy(resource, slash+1); slash= '\0'; } body= build_pidf(pres_node, pres_uri.s, resource); if(body== NULL) { LM_ERR("while constructing PUBLISH body\n"); goto error; } /* construct the publ_info_t structure */ memset(&publ, 0, sizeof(publ_info_t)); publ.pres_uri= &pres_uri; publ.body= body; LM_DBG("Publish for [%s] body:\n %.*s - %d\n", pres_uri.s, publ.body->len, publ.body->s, publ.body->len); publ.source_flag|= XMPP_PUBLISH; publ.expires= expires; publ.event= PRESENCE_EVENT; publ.extra_headers= NULL; publ.outbound_proxy = presence_server; if( pua_send_publish(&publ)< 0) { LM_ERR("while sending publish\n"); goto error; } if(resource) pkg_free(resource); if(body) { if(body->s) xmlFree(body->s); pkg_free(body); } return 0; error: if(resource) pkg_free(resource); if(body) { if(body->s) xmlFree(body->s); pkg_free(body); } return -1; }