/* * cyclically called to do the aging of the URL mapping table entries * and throw out expired entries. * Also we do the cyclic saving here - if required. */ void register_agemap(void) { int i; time_t t; /* expire old entries */ time(&t); DEBUGC(DBCLASS_BABBLE,"sip_agemap, t=%i",(int)t); for (i=0; i<URLMAP_SIZE; i++) { if ((urlmap[i].active == 1) && (urlmap[i].expires < t)) { DEBUGC(DBCLASS_REG,"cleaned entry:%i %s@%s", i, urlmap[i].masq_url->username, urlmap[i].masq_url->host); urlmap[i].active=0; osip_uri_free(urlmap[i].true_url); osip_uri_free(urlmap[i].masq_url); osip_uri_free(urlmap[i].reg_url); } } /* auto-save of registration table */ if ((configuration.autosave_registrations > 0) && ((last_save + configuration.autosave_registrations) < t)) { register_save(); last_save = t; } return; }
int eXosip_call_get_referto (int did, char *refer_to, size_t refer_to_len) { eXosip_dialog_t *jd = NULL; eXosip_call_t *jc = NULL; osip_transaction_t *tr = NULL; osip_uri_t *referto_uri; char atmp[256]; char *referto_tmp = NULL; int i; if (did <= 0) return OSIP_BADPARAMETER; eXosip_call_dialog_find (did, &jc, &jd); if (jc == NULL || jd == NULL || jd->d_dialog == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: No call here?\n")); return OSIP_NOTFOUND; } tr = eXosip_find_last_invite (jc, jd); if (tr == NULL || tr->orig_request == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: No transaction for call?\n")); return OSIP_NOTFOUND; } i = osip_uri_clone (jd->d_dialog->remote_uri->url, &referto_uri); if (i != 0) return i; snprintf (atmp, sizeof (atmp), "%s;to-tag=%s;from-tag=%s", jd->d_dialog->call_id, jd->d_dialog->remote_tag, jd->d_dialog->local_tag); osip_uri_uheader_add (referto_uri, osip_strdup ("Replaces"), osip_strdup (atmp)); i = osip_uri_to_str (referto_uri, &referto_tmp); if (i != 0) { osip_uri_free (referto_uri); return i; } snprintf (refer_to, refer_to_len, "%s", referto_tmp); osip_uri_free (referto_uri); return OSIP_SUCCESS; }
static int groups_load_members(grp_t *grp, char *members) { char *dest; int index = 0; char *tmp = members; char *sep; sep = strchr(members, '|'); /* find beginning of prefix */ while (sep!=NULL && index<MAX_MEMBERS) { dest = grp->members[index]; if (sep-tmp<254) osip_strncpy(dest, tmp, sep-tmp); else { OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL, "groups plugin: members url must be shorter than 254\n")); } index++; tmp = sep+1; sep = strchr(tmp, '|'); /* find beginning of prefix */ } dest = grp->members[index]; if (tmp!=NULL && strlen(tmp)<254) { osip_strncpy(dest, tmp, strlen(tmp)); } for (index=0; index<MAX_MEMBERS; index++) { int i; osip_uri_t *uri; dest = grp->members[index]; if (dest[0]=='\0') break; OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL, "groups plugin: members of %s: %s\n", grp->group, dest)); osip_uri_init(&uri); i = osip_uri_parse(uri, dest); osip_uri_free(uri); if (i!=0) { OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL, "groups plugin: Malformed members URL in group %s!\n", grp->group)); return -1; } } return 0; }
int osip_uri_clone (const osip_uri_t * url, osip_uri_t ** dest) { int i; osip_uri_t *ur; *dest = NULL; if (url == NULL) return -1; if (url->host == NULL && url->string == NULL) return -1; i = osip_uri_init (&ur); if (i == -1) /* allocation failed */ return -1; if (url->scheme != NULL) ur->scheme = osip_strdup (url->scheme); if (url->username != NULL) ur->username = osip_strdup (url->username); if (url->password != NULL) ur->password = osip_strdup (url->password); if (url->host != NULL) ur->host = osip_strdup (url->host); if (url->port != NULL) ur->port = osip_strdup (url->port); if (url->string != NULL) ur->string = osip_strdup (url->string); i = osip_list_clone(&url->url_params, &ur->url_params, (int *(*)(void *, void *)) &osip_uri_param_clone); if (i != 0) { osip_uri_free(ur); return -1; } i = osip_list_clone(&url->url_headers, &ur->url_headers, (int *(*)(void *, void *)) &osip_uri_param_clone); if (i != 0) { osip_uri_free(ur); return -1; } *dest = ur; return 0; }
void osip_message_free (osip_message_t * sip) { if (sip == NULL) return; osip_free (sip->sip_method); osip_free (sip->sip_version); if (sip->req_uri != NULL) osip_uri_free (sip->req_uri); osip_free (sip->reason_phrase); #ifndef MINISIZE osip_list_special_free (&sip->accepts, (void (*)(void *)) &osip_accept_free); #endif osip_list_special_free (&sip->authorizations, (void (*)(void *)) &osip_authorization_free); if (sip->call_id != NULL) osip_call_id_free (sip->call_id); #ifndef MINISIZE osip_list_special_free (&sip->accept_encodings, (void (*)(void *)) &osip_accept_encoding_free); osip_list_special_free (&sip->accept_languages, (void (*)(void *)) &osip_accept_language_free); osip_list_special_free (&sip->alert_infos, (void (*)(void *)) &osip_alert_info_free); osip_list_special_free (&sip->allows, (void (*)(void *)) &osip_allow_free); osip_list_special_free (&sip->authentication_infos, (void (*)(void *)) &osip_authentication_info_free); osip_list_special_free (&sip->content_encodings, (void (*)(void *)) &osip_content_encoding_free); osip_list_special_free (&sip->error_infos, (void (*)(void *)) &osip_error_info_free); osip_list_special_free (&sip->proxy_authentication_infos, (void (*)(void *)) &osip_proxy_authentication_info_free); #endif osip_list_special_free (&sip->call_infos, (void (*)(void *)) &osip_call_info_free); osip_list_special_free (&sip->contacts, (void (*)(void *)) &osip_contact_free); if (sip->content_length != NULL) osip_content_length_free (sip->content_length); if (sip->content_type != NULL) osip_content_type_free (sip->content_type); if (sip->cseq != NULL) osip_cseq_free (sip->cseq); if (sip->from != NULL) osip_from_free (sip->from); if (sip->mime_version != NULL) osip_mime_version_free (sip->mime_version); osip_list_special_free (&sip->proxy_authenticates, (void (*)(void *)) &osip_proxy_authenticate_free); osip_list_special_free (&sip->proxy_authorizations, (void (*)(void *)) &osip_proxy_authorization_free); osip_list_special_free (&sip->record_routes, (void (*)(void *)) &osip_record_route_free); osip_list_special_free (&sip->routes, (void (*)(void *)) &osip_route_free); if (sip->to != NULL) osip_to_free (sip->to); osip_list_special_free (&sip->vias, (void (*)(void *)) &osip_via_free); osip_list_special_free (&sip->www_authenticates, (void (*)(void *)) &osip_www_authenticate_free); osip_list_special_free (&sip->headers, (void (*)(void *)) &osip_header_free); osip_list_special_free (&sip->bodies, (void (*)(void *)) &osip_body_free); osip_free (sip->message); osip_free (sip); }
int main (int argc, char **argv) { FILE *urls_file; osip_uri_t *url; char *a_url; char *dest; char *res; urls_file = fopen (argv[1], "r"); if (urls_file == NULL) { fprintf (stdout, "Failed to open %s file.\nUsage: turls urls.txt\n", argv[1]); exit (0); } a_url = (char *) osip_malloc (200); res = fgets (a_url, 200, urls_file); /* lines are under 200 */ while (res != NULL) { int errcode; /* remove the last '\n' before parsing */ osip_strncpy (a_url + strlen (a_url) - 1, "\0", 1); if (0 != strncmp (a_url, "#", 1)) { /* allocate & init url */ osip_uri_init (&url); printf ("=================================================\n"); printf ("URL TO PARSE: |%s|\n", a_url); errcode = osip_uri_parse (url, a_url); if (errcode != -1) { if (osip_uri_to_str (url, &dest) != -1) { printf ("result: |%s|\n", dest); osip_uri_test_accessor_api (url); osip_free (dest); } } else printf ("Bad url format: %s\n", a_url); osip_uri_free (url); printf ("=================================================\n"); } res = fgets (a_url, 200, urls_file); /* lines are under 200 */ } osip_free (a_url); return 0; }
/* INPUT : osip_from_t *from | from. */ void osip_from_free (osip_from_t * from) { if (from == NULL) return; if (from->url != NULL) { osip_uri_free (from->url); } osip_free (from->displayname); osip_generic_param_freelist (&from->gen_params); osip_free (from); }
ChordId Node::getPredWithContact(osip_message_t *M) { osip_contact_t *osip_contact ; osip_generic_param_t *param ; osip_message_get_contact(M,0,&osip_contact) ; int i = osip_contact_param_get_byname (osip_contact, "predecessor", ¶m); osip_uri_t *uri; i=osip_uri_init(&uri); if (i!=0) { fprintf(stderr, "cannot allocate\n"); return -1; } i=osip_uri_parse(uri, param->gvalue); if (i!=0) { fprintf(stderr, "cannot parse uri\n"); } ChordId new_predessor( atoi(uri->username), constants, uri->host, uri->port ) ; osip_uri_free(uri); return new_predessor ; }
void osip_message_free (osip_message_t * sip) { int pos = 0; if (sip == NULL) return; osip_free (sip->sip_method); osip_free (sip->sip_version); if (sip->req_uri != NULL) { osip_uri_free (sip->req_uri); } osip_free (sip->reason_phrase); { osip_accept_t *accept; while (!osip_list_eol (&sip->accepts, pos)) { accept = (osip_accept_t *) osip_list_get (&sip->accepts, pos); osip_list_remove (&sip->accepts, pos); osip_accept_free (accept); } } { osip_accept_encoding_t *accept_encoding; while (!osip_list_eol (&sip->accept_encodings, pos)) { accept_encoding = (osip_accept_encoding_t *) osip_list_get (&sip->accept_encodings, pos); osip_list_remove (&sip->accept_encodings, pos); osip_accept_encoding_free (accept_encoding); } } { osip_accept_language_t *accept_language; while (!osip_list_eol (&sip->accept_languages, pos)) { accept_language = (osip_accept_language_t *) osip_list_get (&sip->accept_languages, pos); osip_list_remove (&sip->accept_languages, pos); osip_accept_language_free (accept_language); } } { osip_alert_info_t *alert_info; while (!osip_list_eol (&sip->alert_infos, pos)) { alert_info = (osip_alert_info_t *) osip_list_get (&sip->alert_infos, pos); osip_list_remove (&sip->alert_infos, pos); osip_alert_info_free (alert_info); } } { osip_allow_t *al; while (!osip_list_eol (&sip->allows, pos)) { al = (osip_allow_t *) osip_list_get (&sip->allows, pos); osip_list_remove (&sip->allows, pos); osip_allow_free (al); } } { osip_authentication_info_t *al; while (!osip_list_eol (&sip->authentication_infos, pos)) { al = (osip_authentication_info_t *) osip_list_get (&sip-> authentication_infos, pos); osip_list_remove (&sip->authentication_infos, pos); osip_authentication_info_free (al); } } { osip_authorization_t *al; while (!osip_list_eol (&sip->authorizations, pos)) { al = (osip_authorization_t *) osip_list_get (&sip->authorizations, pos); osip_list_remove (&sip->authorizations, pos); osip_authorization_free (al); } } if (sip->call_id != NULL) { osip_call_id_free (sip->call_id); } { osip_call_info_t *call_info; while (!osip_list_eol (&sip->call_infos, pos)) { call_info = (osip_call_info_t *) osip_list_get (&sip->call_infos, pos); osip_list_remove (&sip->call_infos, pos); osip_call_info_free (call_info); } } { osip_contact_t *contact; while (!osip_list_eol (&sip->contacts, pos)) { contact = (osip_contact_t *) osip_list_get (&sip->contacts, pos); osip_list_remove (&sip->contacts, pos); osip_contact_free (contact); } } { osip_content_encoding_t *ce; while (!osip_list_eol (&sip->content_encodings, pos)) { ce = (osip_content_encoding_t *) osip_list_get (&sip->content_encodings, pos); osip_list_remove (&sip->content_encodings, pos); osip_content_encoding_free (ce); } } if (sip->content_length != NULL) { osip_content_length_free (sip->content_length); } if (sip->content_type != NULL) { osip_content_type_free (sip->content_type); } if (sip->cseq != NULL) { osip_cseq_free (sip->cseq); } { osip_error_info_t *error_info; while (!osip_list_eol (&sip->error_infos, pos)) { error_info = (osip_error_info_t *) osip_list_get (&sip->error_infos, pos); osip_list_remove (&sip->error_infos, pos); osip_error_info_free (error_info); } } if (sip->from != NULL) { osip_from_free (sip->from); } if (sip->mime_version != NULL) { osip_mime_version_free (sip->mime_version); } { osip_proxy_authenticate_t *al; while (!osip_list_eol (&sip->proxy_authenticates, pos)) { al = (osip_proxy_authenticate_t *) osip_list_get (&sip-> proxy_authenticates, pos); osip_list_remove (&sip->proxy_authenticates, pos); osip_proxy_authenticate_free (al); } } { osip_proxy_authentication_info_t *al; while (!osip_list_eol (&sip->proxy_authentication_infos, pos)) { al = (osip_proxy_authentication_info_t *) osip_list_get (&sip-> proxy_authentication_infos, pos); osip_list_remove (&sip->proxy_authentication_infos, pos); osip_proxy_authentication_info_free (al); } } { osip_proxy_authorization_t *proxy_authorization; while (!osip_list_eol (&sip->proxy_authorizations, pos)) { proxy_authorization = (osip_proxy_authorization_t *) osip_list_get (&sip-> proxy_authorizations, pos); osip_list_remove (&sip->proxy_authorizations, pos); osip_proxy_authorization_free (proxy_authorization); } } { osip_record_route_t *record_route; while (!osip_list_eol (&sip->record_routes, pos)) { record_route = (osip_record_route_t *) osip_list_get (&sip->record_routes, pos); osip_list_remove (&sip->record_routes, pos); osip_record_route_free (record_route); } } { osip_route_t *route; while (!osip_list_eol (&sip->routes, pos)) { route = (osip_route_t *) osip_list_get (&sip->routes, pos); osip_list_remove (&sip->routes, pos); osip_route_free (route); } } if (sip->to != NULL) { osip_to_free (sip->to); } { osip_via_t *via; while (!osip_list_eol (&sip->vias, pos)) { via = (osip_via_t *) osip_list_get (&sip->vias, pos); osip_list_remove (&sip->vias, pos); osip_via_free (via); } } { osip_www_authenticate_t *al; while (!osip_list_eol (&sip->www_authenticates, pos)) { al = (osip_www_authenticate_t *) osip_list_get (&sip->www_authenticates, pos); osip_list_remove (&sip->www_authenticates, pos); osip_www_authenticate_free (al); } } { osip_header_t *header; while (!osip_list_eol (&sip->headers, pos)) { header = (osip_header_t *) osip_list_get (&sip->headers, pos); osip_list_remove (&sip->headers, pos); osip_header_free (header); } } { osip_body_t *body; while (!osip_list_eol (&sip->bodies, pos)) { body = (osip_body_t *) osip_list_get (&sip->bodies, pos); osip_list_remove (&sip->bodies, pos); osip_body_free (body); } } osip_free (sip->message); osip_free (sip); }
/* * handles register requests and updates the URL mapping table * * RETURNS: * STS_SUCCESS : successfully registered * STS_FAILURE : registration failed * STS_NEED_AUTH : authentication needed */ int register_client(sip_ticket_t *ticket, int force_lcl_masq) { int i, j, n, sts; int expires; time_t time_now; osip_contact_t *contact; osip_uri_t *url1_to, *url1_contact=NULL; osip_uri_t *url2_to; osip_header_t *expires_hdr; osip_uri_param_t *expires_param=NULL; /* * Authorization - do only if I'm not just acting as outbound proxy * but am ment to be the registrar */ if (force_lcl_masq == 0) { /* * RFC 3261, Section 16.3 step 6 * Proxy Behavior - Request Validation - Proxy-Authorization */ sts = authenticate_proxy(ticket->sipmsg); if (sts == STS_FAILURE) { /* failed */ WARN("proxy authentication failed for %s@%s", (ticket->sipmsg->to->url->username)? ticket->sipmsg->to->url->username : "******", ticket->sipmsg->to->url->host); return STS_FAILURE; } else if (sts == STS_NEED_AUTH) { /* needed */ DEBUGC(DBCLASS_REG,"proxy authentication needed for %s@%s", ticket->sipmsg->to->url->username, ticket->sipmsg->to->url->host); return STS_NEED_AUTH; } } /* fetch 1st Via entry and remember this address. Incoming requests for the registered address have to be passed on to that host. To: -> address to be registered Contact: -> host is reachable there Note: in case of un-REGISTER, the contact header may contain '*' only - which means "all registrations made by this UA" => Mapping is To: <1--n> Contact */ time(&time_now); DEBUGC(DBCLASS_BABBLE,"sip_register:"); /* * First make sure, we have a proper Contact header: * - url * - url -> hostname * * Libosip parses an: * "Contact: *" * the following way (Note: Display name!! and URL is NULL) * (gdb) p *((osip_contact_t*)(sip->contacts.node->element)) * $5 = {displayname = 0x8af8848 "*", url = 0x0, gen_params = 0x8af8838} */ osip_message_get_contact(ticket->sipmsg, 0, &contact); if ((contact == NULL) || (contact->url == NULL) || (contact->url->host == NULL)) { /* Don't have required Contact fields. This may be a Registration query or unregistering all registered records for this UA. We should simply forward this request to its destination. However, if this is an unregistration from a client that is not registered (Grandstream "unregister at startup" option) -> How do I handle this one? Right now we do a direction lookup and if this fails we generate an OK message by ourself (fake) */ DEBUGC(DBCLASS_REG, "empty Contact header - " "seems to be a registration query"); sts = sip_find_direction(ticket, NULL); if (sts != STS_SUCCESS) { /* answer the request myself. Most likely this is an UNREGISTER * request when the client just booted */ sts = register_response(ticket, STS_SUCCESS); return STS_SIP_SENT; } return STS_SUCCESS; } url1_contact=contact->url; /* evaluate Expires Header field */ osip_message_get_expires(ticket->sipmsg, 0, &expires_hdr); /* * look for an Contact expires parameter - in case of REGISTER * these two are equal. The Contact expires has higher priority! */ if (ticket->sipmsg->contacts.node && ticket->sipmsg->contacts.node->element) { osip_contact_param_get_byname( (osip_contact_t*) ticket->sipmsg->contacts.node->element, EXPIRES, &expires_param); } if (expires_param && expires_param->gvalue) { /* get expires from contact Header */ expires=atoi(expires_param->gvalue); if ((expires < 0) || (expires >= UINT_MAX )) expires=configuration.default_expires; } else if (expires_hdr && expires_hdr->hvalue) { /* get expires from expires Header */ expires=atoi(expires_hdr->hvalue); if ((expires < 0) || (expires >= UINT_MAX )) expires=configuration.default_expires; } else { char tmp[16]; /* it seems, the expires field is not present everywhere... */ DEBUGC(DBCLASS_REG,"no 'expires' header found - set time to %i sec", configuration.default_expires); expires=configuration.default_expires; sprintf(tmp,"%i",expires); osip_message_set_expires(ticket->sipmsg, tmp); } url1_to=ticket->sipmsg->to->url; /* * REGISTER */ if (expires > 0) { DEBUGC(DBCLASS_REG,"register: %s@%s expires=%i seconds", (url1_contact->username) ? url1_contact->username : "******", (url1_contact->host) ? url1_contact->host : "*NULL*", expires); /* * Update registration. There are two possibilities: * - already registered, then update the existing record * - not registered, then create a new record */ j=-1; for (i=0; i<URLMAP_SIZE; i++) { if (urlmap[i].active == 0) { if (j < 0) j=i; /* remember first hole */ continue; } url2_to=urlmap[i].reg_url; /* check address-of-record ("public address" of user) */ if (compare_url(url1_to, url2_to)==STS_SUCCESS) { DEBUGC(DBCLASS_REG, "found entry for %s@%s <-> %s@%s at " "slot=%i, exp=%li", (url1_contact->username) ? url1_contact->username : "******", (url1_contact->host) ? url1_contact->host : "*NULL*", (url2_to->username) ? url2_to->username : "******", (url2_to->host) ? url2_to->host : "*NULL*", i, (long)urlmap[i].expires-time_now); break; } } if ( (j < 0) && (i >= URLMAP_SIZE) ) { /* oops, no free entries left... */ ERROR("URLMAP is full - registration failed"); return STS_FAILURE; } if (i >= URLMAP_SIZE) { /* entry not existing, create new one */ i=j; /* write entry */ urlmap[i].active=1; /* Contact: field */ osip_uri_clone( ((osip_contact_t*) (ticket->sipmsg->contacts.node->element))->url, &urlmap[i].true_url); /* To: field */ osip_uri_clone( ticket->sipmsg->to->url, &urlmap[i].reg_url); DEBUGC(DBCLASS_REG,"create new entry for %s@%s <-> %s@%s at slot=%i", (url1_contact->username) ? url1_contact->username : "******", (url1_contact->host) ? url1_contact->host : "*NULL*", (urlmap[i].reg_url->username) ? urlmap[i].reg_url->username : "******", (urlmap[i].reg_url->host) ? urlmap[i].reg_url->host : "*NULL*", i); /* * try to figure out if we ought to do some masquerading */ osip_uri_clone( ticket->sipmsg->to->url, &urlmap[i].masq_url); n=configuration.mask_host.used; if (n != configuration.masked_host.used) { ERROR("# of mask_host is not equal to # of masked_host in config!"); n=0; } DEBUG("%i entries in MASK config table", n); for (j=0; j<n; j++) { DEBUG("compare [%s] <-> [%s]",configuration.mask_host.string[j], ticket->sipmsg->to->url->host); if (strcmp(configuration.mask_host.string[j], ticket->sipmsg->to->url->host)==0) break; } if (j<n) { /* we are masquerading this UA, replace the host part of the url */ DEBUGC(DBCLASS_REG,"masquerading UA %s@%s as %s@%s", (url1_contact->username) ? url1_contact->username : "******", (url1_contact->host) ? url1_contact->host : "*NULL*", (url1_contact->username) ? url1_contact->username : "******", configuration.masked_host.string[j]); urlmap[i].masq_url->host=realloc(urlmap[i].masq_url->host, strlen(configuration.masked_host.string[j])+1); strcpy(urlmap[i].masq_url->host, configuration.masked_host.string[j]); } } else { /* if new entry */ /* This is an existing entry */ /* * Some phones (like BudgeTones *may* dynamically grab a SIP port * so we might want to update the true_url and reg_url each time * we get an REGISTER */ /* Contact: field (true_url) */ osip_uri_free(urlmap[i].true_url); osip_uri_clone( ((osip_contact_t*) (ticket->sipmsg->contacts.node->element))->url, &urlmap[i].true_url); /* To: field (reg_url) */ osip_uri_free(urlmap[i].reg_url); osip_uri_clone( ticket->sipmsg->to->url, &urlmap[i].reg_url); } /* * for proxying: force device to be masqueraded * as with the outbound IP (masq_url) */ if (force_lcl_masq) { struct in_addr addr; char *addrstr; if (get_interface_ip(IF_OUTBOUND, &addr) != STS_SUCCESS) { return STS_FAILURE; } /* host part */ addrstr = utils_inet_ntoa(addr); DEBUGC(DBCLASS_REG,"masquerading UA %s@%s local %s@%s", (url1_contact->username) ? url1_contact->username : "******", (url1_contact->host) ? url1_contact->host : "*NULL*", (url1_contact->username) ? url1_contact->username : "******", addrstr); urlmap[i].masq_url->host=realloc(urlmap[i].masq_url->host, strlen(addrstr)+1); strcpy(urlmap[i].masq_url->host, addrstr); /* port number if required */ if (configuration.sip_listen_port != SIP_PORT) { urlmap[i].masq_url->port=realloc(urlmap[i].masq_url->port, 16); sprintf(urlmap[i].masq_url->port, "%i", configuration.sip_listen_port); } } /* give some safety margin for the next update */ if (expires > 0) expires+=30; /* update registration timeout */ urlmap[i].expires=time_now+expires; /* * un-REGISTER */ } else { /* expires > 0 */ /* * Remove registration * Siproxd will ALWAYS remove ALL bindings for a given * address-of-record */ for (i=0; i<URLMAP_SIZE; i++) { if (urlmap[i].active == 0) continue; url2_to=urlmap[i].reg_url; if (compare_url(url1_to, url2_to)==STS_SUCCESS) { DEBUGC(DBCLASS_REG, "removing registration for %s@%s at slot=%i", (url2_to->username) ? url2_to->username : "******", (url2_to->host) ? url2_to->host : "*NULL*", i); urlmap[i].expires=0; break; } } } return STS_SUCCESS; }
/* * SIP_REWRITE_CONTACT * * rewrite the Contact header * * RETURNS * STS_SUCCESS on success * STS_FAILURE on error */ int sip_rewrite_contact (sip_ticket_t *ticket, int direction) { osip_message_t *sip_msg=ticket->sipmsg; osip_contact_t *contact; int i, j; int replaced=0; if (sip_msg == NULL) return STS_FAILURE; /* at least one contact header present? */ osip_message_get_contact(sip_msg, 0, &contact); if (contact == NULL) return STS_FAILURE; /* loop for all existing contact headers in message */ for (j=0; contact != NULL; j++) { osip_message_get_contact(sip_msg, j, &contact); if (contact == NULL) break; if (contact->url == NULL) continue; /* search for an entry */ for (i=0;i<URLMAP_SIZE;i++){ if (urlmap[i].active == 0) continue; if ((direction == DIR_OUTGOING) && (compare_url(contact->url, urlmap[i].true_url)==STS_SUCCESS)) break; if ((direction == DIR_INCOMING) && (compare_url(contact->url, urlmap[i].masq_url)==STS_SUCCESS)) break; } /* found a mapping entry */ if (i<URLMAP_SIZE) { char *tmp; if (direction == DIR_OUTGOING) { DEBUGC(DBCLASS_PROXY, "rewriting Contact header %s@%s -> %s@%s", (contact->url->username)? contact->url->username : "******", (contact->url->host)? contact->url->host : "*NULL*", urlmap[i].masq_url->username, urlmap[i].masq_url->host); } else { DEBUGC(DBCLASS_PROXY, "rewriting Contact header %s@%s -> %s@%s", (contact->url->username)? contact->url->username : "******", (contact->url->host)? contact->url->host : "*NULL*", urlmap[i].true_url->username, urlmap[i].true_url->host); } /* remove old entry */ osip_list_remove(sip_msg->contacts,j); osip_contact_to_str(contact, &tmp); osip_contact_free(contact); /* clone the url from urlmap*/ osip_contact_init(&contact); osip_contact_parse(contact,tmp); osip_free(tmp); osip_uri_free(contact->url); if (direction == DIR_OUTGOING) { /* outgoing, use masqueraded url */ osip_uri_clone(urlmap[i].masq_url, &contact->url); } else { /* incoming, use true url */ osip_uri_clone(urlmap[i].true_url, &contact->url); } osip_list_add(sip_msg->contacts,contact,j); replaced=1; } } if (replaced == 0) { DEBUGC(DBCLASS_PROXY, "no Contact header rewritten"); return STS_FAILURE; } return STS_SUCCESS; }
int _eXosip_call_retry_request (eXosip_call_t * jc, eXosip_dialog_t * jd, osip_transaction_t * out_tr) { osip_transaction_t *tr = NULL; osip_message_t *msg = NULL; osip_event_t *sipevent; int cseq; osip_via_t *via; osip_contact_t *co; int pos; int i; int protocol = IPPROTO_UDP; if (jc == NULL) return OSIP_BADPARAMETER; if (jd != NULL) { if (jd->d_out_trs == NULL) return OSIP_BADPARAMETER; } if (out_tr == NULL || out_tr->orig_request == NULL || out_tr->last_response == NULL) return OSIP_BADPARAMETER; i = osip_message_clone (out_tr->orig_request, &msg); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: could not clone msg for authentication\n")); return i; } via = (osip_via_t *) osip_list_get (&msg->vias, 0); if (via == NULL || msg->cseq == NULL || msg->cseq->number == NULL) { osip_message_free (msg); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: missing via or cseq header\n")); return OSIP_SYNTAXERROR; } if (MSG_IS_STATUS_3XX (out_tr->last_response)) { co = NULL; pos = 0; while (!osip_list_eol (&out_tr->last_response->contacts, pos)) { co = (osip_contact_t *) osip_list_get (&out_tr->last_response->contacts, pos); if (co != NULL && co->url != NULL) { /* check tranport? Only allow UDP, right now */ osip_uri_param_t *u_param; int pos2; u_param = NULL; pos2 = 0; while (!osip_list_eol (&co->url->url_params, pos2)) { u_param = (osip_uri_param_t *) osip_list_get (&co->url->url_params, pos2); if (u_param == NULL || u_param->gname == NULL || u_param->gvalue == NULL) { u_param = NULL; /* skip */ } else if (0 == osip_strcasecmp (u_param->gname, "transport")) { if (0 == osip_strcasecmp (u_param->gvalue, "udp")) { u_param = NULL; protocol = IPPROTO_UDP; break; /* ok */ } else if (0 == osip_strcasecmp (u_param->gvalue, "tcp")) { protocol = IPPROTO_TCP; u_param = NULL; } break; } pos2++; } if (u_param == NULL || u_param->gname == NULL || u_param->gvalue == NULL) { break; /* default is udp! */ } } pos++; co = NULL; } if (co == NULL || co->url == NULL) { osip_message_free (msg); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: contact header\n")); return OSIP_SYNTAXERROR; } /* TODO: remove extra parameter from new request-uri check usual parameter like "transport" */ if (msg->req_uri != NULL && msg->req_uri->host != NULL && co->url->host != NULL && 0 == osip_strcasecmp (co->url->host, msg->req_uri->host)) { osip_uri_param_t *maddr_param = NULL; osip_uri_uparam_get_byname (co->url, "maddr", &maddr_param); if (maddr_param != NULL && maddr_param->gvalue != NULL) { /* This is a redirect server, the route should probably be removed? */ osip_route_t *route = NULL; osip_generic_param_t *tag = NULL; osip_message_get_route (msg, 0, &route); if (route != NULL) { osip_to_get_tag (msg->to, &tag); if (tag == NULL && route != NULL && route->url != NULL) { osip_list_remove (&msg->routes, 0); osip_route_free (route); } } } } /* replace request-uri with NEW contact address */ osip_uri_free (msg->req_uri); msg->req_uri = NULL; osip_uri_clone (co->url, &msg->req_uri); /* support for diversions headers/draft! */ { int count = 0; pos = 0; while (!osip_list_eol (&out_tr->last_response->headers, pos)) { osip_header_t *copy = NULL; osip_header_t *head = osip_list_get (&out_tr->last_response->headers, pos); if (head != NULL && 0 == osip_strcasecmp (head->hname, "diversion")) { i = osip_header_clone (head, ©); if (i == 0) { osip_list_add (&msg->headers, copy, count); count++; } } pos++; } } } /* remove all previous authentication headers */ osip_list_special_free (&msg->authorizations, (void *(*)(void *)) &osip_authorization_free); osip_list_special_free (&msg->proxy_authorizations, (void *(*)(void *)) &osip_proxy_authorization_free); /* increment cseq */ cseq = atoi (msg->cseq->number); osip_free (msg->cseq->number); msg->cseq->number = strdup_printf ("%i", cseq + 1); if (jd != NULL && jd->d_dialog != NULL) { jd->d_dialog->local_cseq++; } i = eXosip_update_top_via (msg); if (i != 0) { osip_message_free (msg); return i; } if (out_tr->last_response->status_code == 401 || out_tr->last_response->status_code == 407) eXosip_add_authentication_information (msg, out_tr->last_response); else eXosip_add_authentication_information (msg, NULL); osip_message_force_update (msg); if (0 != osip_strcasecmp (msg->sip_method, "INVITE")) { i = _eXosip_transaction_init (&tr, NICT, eXosip.j_osip, msg); } else { i = _eXosip_transaction_init (&tr, ICT, eXosip.j_osip, msg); } if (i != 0) { osip_message_free (msg); return i; } if (out_tr == jc->c_out_tr) { /* replace with the new tr */ osip_list_add (&eXosip.j_transactions, jc->c_out_tr, 0); jc->c_out_tr = tr; /* fix dialog issue */ if (jd != NULL) { REMOVE_ELEMENT (jc->c_dialogs, jd); eXosip_dialog_free (jd); jd = NULL; } } else { /* add the new tr for the current dialog */ osip_list_add (jd->d_out_trs, tr, 0); } sipevent = osip_new_outgoing_sipmessage (msg); #ifndef MINISIZE osip_transaction_set_your_instance (tr, __eXosip_new_jinfo (jc, jd, NULL, NULL)); #else osip_transaction_set_your_instance (tr, __eXosip_new_jinfo (jc, jd)); #endif osip_transaction_add_event (tr, sipevent); eXosip_update (); /* fixed? */ __eXosip_wakeup (); return OSIP_SUCCESS; }
static int __osip_message_startline_parsereq(osip_message_t * dest, const char *buf, const char **headers) { const char *p1; const char *p2; char *requesturi; int i; dest->sip_method = NULL; dest->status_code = 0; dest->reason_phrase = NULL; *headers = buf; /* The first token is the method name: */ p2 = strchr(buf, ' '); if (p2 == NULL) return OSIP_SYNTAXERROR; if (*(p2 + 1) == '\0' || *(p2 + 2) == '\0') return OSIP_SYNTAXERROR; if (p2 - buf == 0) { OSIP_TRACE(osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "No space allowed here\n")); return OSIP_SYNTAXERROR; } dest->sip_method = (char *) osip_malloc(p2 - buf + 1); if (dest->sip_method == NULL) return OSIP_NOMEM; osip_strncpy(dest->sip_method, buf, p2 - buf); /* The second token is a sip-url or a uri: */ p1 = strchr(p2 + 2, ' '); /* no space allowed inside sip-url */ if (p1 == NULL) { OSIP_TRACE(osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Uncompliant request-uri\n")); osip_free(dest->sip_method); dest->sip_method = NULL; return OSIP_SYNTAXERROR; } if (p1 - p2 < 2) { osip_free(dest->sip_method); dest->sip_method = NULL; return OSIP_SYNTAXERROR; } requesturi = (char *) osip_malloc(p1 - p2); if (requesturi == NULL) { osip_free(dest->sip_method); dest->sip_method = NULL; return OSIP_NOMEM; } osip_clrncpy(requesturi, p2 + 1, (p1 - p2 - 1)); i = osip_uri_init(&(dest->req_uri)); if (i != 0) { osip_free(requesturi); requesturi = NULL; osip_free(dest->sip_method); dest->sip_method = NULL; return OSIP_NOMEM; } i = osip_uri_parse(dest->req_uri, requesturi); osip_free(requesturi); if (i != 0) { osip_free(dest->sip_method); dest->sip_method = NULL; osip_uri_free(dest->req_uri); dest->req_uri = NULL; return OSIP_SYNTAXERROR; } /* find the the version and the beginning of headers */ { const char *hp = p1; while ((*hp != '\r') && (*hp != '\n')) { if (*hp) hp++; else { OSIP_TRACE(osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "No crlf found\n")); osip_free(dest->sip_method); dest->sip_method = NULL; osip_uri_free(dest->req_uri); dest->req_uri = NULL; return OSIP_SYNTAXERROR; } } if (hp - p1 < 2) { osip_free(dest->sip_method); dest->sip_method = NULL; osip_uri_free(dest->req_uri); dest->req_uri = NULL; return OSIP_SYNTAXERROR; } dest->sip_version = (char *) osip_malloc(hp - p1); if (dest->sip_version == NULL) { osip_free(dest->sip_method); dest->sip_method = NULL; osip_uri_free(dest->req_uri); dest->req_uri = NULL; return OSIP_NOMEM; } osip_strncpy(dest->sip_version, p1 + 1, (hp - p1 - 1)); if (0 != osip_strcasecmp(dest->sip_version, "SIP/2.0")) { OSIP_TRACE(osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Wrong version number\n")); } hp++; if ((*hp) && ('\r' == hp[-1]) && ('\n' == hp[0])) hp++; (*headers) = hp; } return OSIP_SUCCESS; }
/* This method returns: -2 if plugin consider this request should be totally discarded! -1 on error 0 nothing has been done 1 things has been done on psp_req element */ int cb_ls_localdb_search_user_location (psp_request_t * psp_req) { osip_route_t *route; ppl_uinfo_t *uinfo; int i; int numlocs = 0 /* DAB */ ; osip_message_t *request; request = psp_request_get_request(psp_req); /* default OUTPUT */ if (ISSET_R_ROUTE_MODE (ls_localdb_context->flag)) psp_request_set_property (psp_req, PSP_STAY_ON_PATH); else psp_request_set_property (psp_req, 0); /* mode */ if (ISSET_FORKING_MODE (ls_localdb_context->flag)) psp_request_set_mode (psp_req, PSP_FORK_MODE); else if (ISSET_SEQUENTIAL_MODE (ls_localdb_context->flag)) psp_request_set_mode (psp_req, PSP_SEQ_MODE); else if (ISSET_REDIRECT_MODE (ls_localdb_context->flag)) { psp_request_set_uas_status (psp_req, 302); psp_request_set_mode (psp_req, PSP_UAS_MODE); } else psp_request_set_mode (psp_req, PSP_FORK_MODE); psp_request_set_state (psp_req, PSP_MANDATE); /* THIS IS MANDATORY FOR ALL PLUGINS TO CHECK THAT! this is rarely used as a previous plugin 'ls_localdb' should have checked for it. In case you remove it. */ osip_message_get_route (request, 1, &route); if (route != NULL) { if (ISSET_SEQUENTIAL_MODE (ls_localdb_context->flag)) psp_request_set_mode (psp_req, PSP_SEQ_MODE); else psp_request_set_mode (psp_req, PSP_FORK_MODE); psp_request_set_state (psp_req, PSP_MANDATE); return 0; /* do nothing.. */ } if (request->req_uri->username == NULL) { /* Propose 484, but let's keep searching if another plugin can find the destination. */ psp_request_set_uas_status (psp_req, 484); psp_request_set_state (psp_req, PSP_CONTINUE); psp_request_set_mode (psp_req, PSP_UAS_MODE); return 0; } /* look for this URI in our list of users */ uinfo = ppl_uinfo_find_by_aor (request->req_uri); if (uinfo != NULL) { /* add all locations to the psp_req element */ binding_t *bind; binding_t *bindnext; location_t *loc; osip_uri_t *url; bind = uinfo->bindings; bindnext = uinfo->bindings; for (; bind != NULL; bind = bindnext) { bindnext = bind->next; i = ppl_uinfo_check_binding (bind); if (i != 0) { /* binding is expired */ ppl_uinfo_remove_binding (uinfo, bind); } } bind = uinfo->bindings; if (bind == NULL) { /* user is not around... */ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "ls_localdb plugin: User Exist but has no valid registration!\n")); psp_request_set_uas_status (psp_req, 480); psp_request_set_mode (psp_req, PSP_UAS_MODE); psp_request_set_state (psp_req, PSP_MANDATE); return 0; } bindnext = uinfo->bindings; /* DAB */ for (; bind != NULL; bind = bindnext) /* DAB */ { /* DAB */ /* If this is an INVITE Request, collect all locations DAB */ #ifdef EXPERIMENTAL_FORK if (MSG_IS_INVITE (request)) bindnext = bind->next; /* DAB */ else bindnext = NULL; /* DAB */ #else /* always accept only ONE location even for INVITE */ /* this is a limitation for stability reason as the forking mode is unfinished (calculation of the best response is not compliant to the rfc3261.txt behavior. */ bindnext = NULL; /* loop will be execute onece only */ #endif i = osip_uri_clone (bind->contact->url, &url); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "ls_localdb plugin: Could not clone contact info!\n")); psp_request_set_uas_status (psp_req, 400); psp_request_set_mode (psp_req, PSP_UAS_MODE); psp_request_set_state (psp_req, PSP_MANDATE); return -1; } i = location_init (&loc, url, 3600); if (i != 0) { osip_uri_free (url); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_BUG, NULL, "ls_localdb plugin: Could not create location info!\n")); psp_request_set_uas_status (psp_req, 400); psp_request_set_mode (psp_req, PSP_UAS_MODE); psp_request_set_state (psp_req, PSP_MANDATE); return -1; } /* new support for rfc3327.txt and Path header */ if (bind->path!=NULL) location_set_path(loc, osip_strdup(bind->path)); ADD_ELEMENT (psp_req->locations, loc); numlocs++; /* DAB */ } /* DAB */ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "ls_localdb plugin: %d locations found!\n", numlocs)); return 0; } /* no user location found in local database... */ psp_request_set_uas_status (psp_req, 404); psp_request_set_state (psp_req, PSP_CONTINUE); psp_request_set_mode (psp_req, PSP_UAS_MODE); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "ls_localdb plugin: No location found for known user: return 404 Not found!!\n")); return 0; }
uri_t::~uri_t () { osip_uri_free ( uri ) ; }
/* * SIP_REWRITE_CONTACT * * rewrite the Contact header * * RETURNS * STS_SUCCESS on success * STS_FAILURE on error */ int sip_rewrite_contact (sip_ticket_t *ticket, int direction, struct in_addr *local_ip) { osip_message_t *sip_msg=ticket->sipmsg; osip_contact_t *contact; int i; #if UNREG_WITHOUT_REG_HG522 char tmpUserName[128] = {0}; char tmpPort[6] = {0}; #endif if (sip_msg == NULL) return STS_FAILURE; osip_message_get_contact(sip_msg, 0, &contact); if (contact == NULL) { printsip("sip: rewrite_contact contact is NULL \r\n"); return STS_FAILURE; } for (i=0;i<URLMAP_SIZE;i++){ if (urlmap[i].active == 0) continue; if ((direction == DIR_OUTGOING) && (compare_url(contact->url, urlmap[i].true_url)==STS_SUCCESS)) break; if ((direction == DIR_INCOMING) && (compare_url(contact->url, urlmap[i].masq_url)==STS_SUCCESS)) break; #if UNREG_WITHOUT_REG_HG522 if ((direction == DIR_OUTGOING) && (NULL != contact->url) && (NULL != urlmap[i].true_url) && (NULL != contact->url->host) && (NULL != urlmap[i].true_url->host) && (strcmp(contact->url->host, urlmap[i].true_url->host) == 0)) { strcpy(tmpUserName, contact->url->username); if (NULL != contact->url->port) { strncpy(tmpPort, contact->url->port, 6); } break; } #endif } /* found a mapping entry */ if (i<URLMAP_SIZE) { char *tmp; if (NULL != contact->url) { printsip("************* sip: rewrote Contact header %s@%s:%s -> %s@%s:%s \r\n", (contact->url->username)? contact->url->username : "******", (contact->url->host)? contact->url->host : "*NULL*", (contact->url->port)? contact->url->port : "NULL port", urlmap[i].masq_url->username, urlmap[i].masq_url->host, (urlmap[i].masq_url->port)? urlmap[i].masq_url->port : "NULL port"); } /* remove old entry */ osip_list_remove(sip_msg->contacts,0); osip_contact_to_str(contact, &tmp); osip_contact_free(contact); /* clone the url from urlmap */ osip_contact_init(&contact); osip_contact_parse(contact,tmp); osip_free(tmp); osip_uri_free(contact->url); if (direction == DIR_OUTGOING) { /* outgoing, use masqueraded url */ osip_uri_clone(urlmap[i].masq_url, &contact->url); if (local_ip != NULL) { char *ip = malloc(20); strncpy(ip, inet_ntoa(*local_ip), 20); free(contact->url->host); contact->url->host = ip; } #if UNREG_WITHOUT_REG_HG522 if ('\0' != tmpUserName[0]) { char *username = malloc(strlen(tmpUserName)+1); strncpy(username, tmpUserName, strlen(tmpUserName)+1); free(contact->url->username); contact->url->username = username; } if ((NULL == urlmap[i].masq_url->port) && ('\0' != tmpPort[0])) { char *port = malloc(strlen(tmpPort)+1); strncpy(port, tmpPort, strlen(tmpPort)+1); contact->url->port = port; } #endif } else { /* incoming, use true url */ osip_uri_clone(urlmap[i].true_url, &contact->url); printsip("incoming: osip_uri_clone from %s \r\n", urlmap[i].true_url->host); } osip_list_add(sip_msg->contacts,contact,-1); } else { return STS_FAILURE; } return STS_SUCCESS; }
/* private plugin code */ static int plugin_regex_redirect(sip_ticket_t *ticket) { osip_uri_t *to_url=ticket->sipmsg->to->url; char *url_string=NULL; osip_uri_t *new_to_url; int i, sts; osip_contact_t *contact = NULL; /* character workspaces for regex */ #define WORKSPACE_SIZE 128 static char in[WORKSPACE_SIZE+1], rp[WORKSPACE_SIZE+1]; /* do apply to full To URI... */ sts = osip_uri_to_str(to_url, &url_string); if (sts != 0) { ERROR("osip_uri_to_str() failed"); return STS_FAILURE; } DEBUGC(DBCLASS_BABBLE, "To URI string: [%s]", url_string); /* perform search and replace of the regexes, first match hits */ for (i = 0; i < plugin_cfg.regex_pattern.used; i++) { regmatch_t *pmatch = NULL; pmatch = rmatch(url_string, WORKSPACE_SIZE, &re[i]); if (pmatch == NULL) continue; /* no match, next */ /* have a match, do the replacement */ INFO("Matched rexec rule: %s",plugin_cfg.regex_desc.string[i] ); strncpy (in, url_string, WORKSPACE_SIZE); in[WORKSPACE_SIZE]='\0'; strncpy (rp, plugin_cfg.regex_replace.string[i], WORKSPACE_SIZE); rp[WORKSPACE_SIZE]='\0'; sts = rreplace(in, WORKSPACE_SIZE, &re[i], pmatch, rp); if (sts != STS_SUCCESS) { ERROR("regex replace failed: pattern:[%s] replace:[%s]", plugin_cfg.regex_pattern.string[i], plugin_cfg.regex_replace.string[i]); osip_free(url_string); return STS_FAILURE; } /* only do first match */ break; } if (i >= plugin_cfg.regex_pattern.used) { /* no match */ osip_free(url_string); return STS_SUCCESS; } /* in: contains the new string */ sts = osip_uri_init(&new_to_url); if (sts != 0) { ERROR("Unable to initialize URI"); osip_free(url_string); return STS_FAILURE; } sts = osip_uri_parse(new_to_url, in); if (sts != 0) { ERROR("Unable to parse To URI: %s", in); osip_uri_free(new_to_url); osip_free(url_string); return STS_FAILURE; } /* use a "302 Moved temporarily" response back to the client */ /* new target is within the Contact Header */ /* remove all Contact headers in message */ for (i=0; (contact != NULL) || (i == 0); i++) { osip_message_get_contact(ticket->sipmsg, 0, &contact); if (contact) { osip_list_remove(&(ticket->sipmsg->contacts),0); osip_contact_free(contact); } } /* for i */ /* insert one new Contact header containing the new target address */ osip_contact_init(&contact); osip_list_add(&(ticket->sipmsg->contacts),contact,0); /* link the new_to_url into the Contact list */ contact->url = new_to_url; new_to_url = NULL; /* * Add the 'REDIRECTED_TAG=REDIRECTED_VAL' parameter to URI. Required to figure out * if this INVITE has already been processed (redirected) and * does not need further attention by this plugin. * THIS IS REQUIRED TO AVOID A LOOP */ osip_uri_param_add(&(contact->url->url_params), osip_strdup(REDIRECTED_TAG), osip_strdup(REDIRECTED_VAL)); INFO("redirecting %s -> %s", url_string, in); /* sent redirect message back to local client */ add_to_redirected_cache(&redirected_cache, ticket); sip_gen_response(ticket, 302 /*Moved temporarily*/); /* release resources and return */ osip_free(url_string); return STS_SIP_SENT; }
/* This method returns: -2 if plugin consider this request should be totally discarded! -1 on error 0 nothing has been done 1 things has been done on psp_req element */ int cb_groups_search_location(psp_request_t *psp_req) { location_t *loc; osip_route_t *route; int i; int index; int match; grp_t *grp=NULL; osip_uri_param_t *psp_param; osip_message_t *request; request = psp_request_get_request(psp_req); OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL, "groups plugin: entering cb_groups_search_location\n")); /* default OUTPUT */ if (ISSET_R_ROUTE_MODE(groups_context->flag)) psp_request_set_property(psp_req, PSP_STAY_ON_PATH); else psp_request_set_property(psp_req, 0); psp_request_set_mode(psp_req, PSP_SFULL_MODE); i=0; for (; !osip_list_eol(&request->routes, i); i++) { osip_message_get_route (request, i, &route); if (0 != psp_core_is_responsible_for_this_route(route->url)) { psp_request_set_mode (psp_req, PSP_SFULL_MODE); psp_request_set_state (psp_req, PSP_MANDATE); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "groups plugin: mandate statefull handling for route.\n")); return 0; } } psp_request_set_state(psp_req, PSP_MANDATE); if (i>1) { psp_request_set_uas_status(psp_req, 482); /* loop? */ psp_request_set_mode(psp_req, PSP_UAS_MODE); return 0; } if (i==1) { osip_message_get_route(request, 0, &route); /* should be the first one */ /* if this route header contains the "psp" parameter, it means the element does not come from a pre-route-set header (in this last case, we want to execute the plugin for the initial request) */ /* NON compliant UAs (not returning this parameter) are guilty. */ osip_uri_uparam_get_byname (route->url, "psp", &psp_param); if (psp_param!=NULL) { psp_request_set_state(psp_req, PSP_MANDATE); psp_request_set_mode (psp_req, PSP_SFULL_MODE); /* got it, leave this plugin. */ return 0; } } if (request->req_uri->username==NULL || request->req_uri->host==NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "groups plugin: No username in uri.\n")); psp_request_set_state(psp_req, PSP_PROPOSE); psp_request_set_uas_status(psp_req, 404); psp_request_set_mode(psp_req, PSP_UAS_MODE); return 0; } /* search for a group */ match=0; for (index=0; index<MAX_GROUPS; index++) { grp = &(groups_context->grps[index]); if (grp->group[0]!='\0') { if (osip_strcasecmp(grp->group, request->req_uri->username)==0) { if (grp->domain[0]=='\0') { match=1; break; } else if (osip_strcasecmp(grp->domain, request->req_uri->host)==0) { match=1; break; } } } grp=NULL; } if (match==1 && grp!=NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "groups plugin: A group match this call (%s).\n", grp->group)); for (index=0; index<MAX_MEMBERS; index++) { osip_uri_t *uri; int i; char *dest; dest = grp->members[index]; if (dest[0]=='\0') break; OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO3,NULL, "groups plugin: members of %s: %s\n", grp->group, dest)); osip_uri_init(&uri); i = osip_uri_parse(uri, dest); if (i==0) { i = location_init(&loc, uri, 3600); if (i!=0) { /* This can only happen in case we don't have enough memory */ osip_uri_free(uri); OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_BUG,NULL, "groups plugin: Could not create location info!\n")); } else { ADD_ELEMENT(psp_req->locations, loc); } } } return 0; } OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL, "groups plugin: Didn't do anything with this request?\n")); psp_request_set_state(psp_req, PSP_PROPOSE); psp_request_set_uas_status(psp_req, 404); psp_request_set_mode(psp_req, PSP_UAS_MODE); return 0; }