📄 jrequest.c
字号:
{ } else if (osip_strcasecmp (u_header->gname, "to") == 0) { } else if (osip_strcasecmp (u_header->gname, "call-id") == 0) { } else if (osip_strcasecmp (u_header->gname, "cseq") == 0) { } else if (osip_strcasecmp (u_header->gname, "via") == 0) { } else if (osip_strcasecmp (u_header->gname, "contact") == 0) { } else osip_message_set_header (request, u_header->gname, u_header->gvalue); osip_list_remove (&url->url_headers, 0); osip_uri_param_free (u_header); } } if (proxy != NULL && proxy[0] != 0) { /* equal to a pre-existing route set */ /* if the pre-existing route set contains a "lr" (compliance with bis-08) then the req_uri should contains the remote target URI */ osip_uri_param_t *lr_param; osip_route_t *o_proxy; osip_route_init (&o_proxy); i = osip_route_parse (o_proxy, proxy); if (i != 0) { osip_route_free (o_proxy); osip_message_free (request); return i; } osip_uri_uparam_get_byname (o_proxy->url, "lr", &lr_param); if (lr_param != NULL) /* to is the remote target URI in this case! */ { osip_uri_clone (request->to->url, &(request->req_uri)); /* "[request] MUST includes a Route header field containing the route set values in order." */ osip_list_add (&request->routes, o_proxy, 0); } else /* if the first URI of route set does not contain "lr", the req_uri is set to the first uri of route set */ { request->req_uri = o_proxy->url; o_proxy->url = NULL; osip_route_free (o_proxy); /* add the route set */ /* "The UAC MUST add a route header field containing the remainder of the route set values in order. The UAC MUST then place the remote target URI into the route header field as the last value */ osip_message_set_route (request, to); } } else /* No route set (outbound proxy) is used */ { /* The UAC must put the remote target URI (to field) in the req_uri */ i = osip_uri_clone (request->to->url, &(request->req_uri)); if (i != 0) { osip_message_free (request); return i; } } } /* set To and From */ i = osip_message_set_from (request, from); if (i != 0 || request->from == NULL) { if (i >= 0) i = OSIP_SYNTAXERROR; osip_message_free (request); return i; } /* add a tag */ osip_from_set_tag (request->from, osip_from_tag_new_random ()); /* set the cseq and call_id header */ { osip_call_id_t *callid; osip_cseq_t *cseq; char *num; char *cidrand; /* call-id is always the same for REGISTRATIONS */ i = osip_call_id_init (&callid); if (i != 0) { osip_message_free (request); return i; } cidrand = osip_call_id_new_random (); osip_call_id_set_number (callid, cidrand); if (doing_register) register_callid_number = cidrand; request->call_id = callid; i = osip_cseq_init (&cseq); if (i != 0) { osip_message_free (request); return i; } num = osip_strdup (doing_register ? "1" : "20"); osip_cseq_set_number (cseq, num); osip_cseq_set_method (cseq, osip_strdup (method)); request->cseq = cseq; if (cseq->method == NULL || cseq->number == NULL) { osip_message_free (request); return OSIP_NOMEM; } } i = _eXosip_request_add_via (request, transport, locip); if (i != 0) { osip_message_free (request); return i; } /* always add the Max-Forward header */ osip_message_set_max_forwards (request, "70"); /* a UA should start a request with 70 */ if (0 == strcmp ("REGISTER", method)) { } else if (0 == strcmp ("INFO", method)) { } else if (0 == strcmp ("OPTIONS", method)) { osip_message_set_accept (request, "application/sdp"); } osip_message_set_user_agent (request, eXosip.user_agent); /* else if ... */ *dest = request; return OSIP_SUCCESS;}intgenerating_register (eXosip_reg_t * jreg, osip_message_t ** reg, char *transport, char *from, char *proxy, char *contact, int expires){ int i; char locip[65]; char firewall_ip[65]; char firewall_port[10]; if (eXosip.eXtl == NULL) return OSIP_NO_NETWORK; firewall_ip[0] = '\0'; firewall_port[0] = '\0'; if (eXosip.eXtl->tl_get_masquerade_contact != NULL) { eXosip.eXtl->tl_get_masquerade_contact (firewall_ip, sizeof (firewall_ip), firewall_port, sizeof (firewall_port)); } i = generating_request_out_of_dialog (reg, "REGISTER", NULL, transport, from, proxy); if (i != 0) return i; memset (locip, '\0', sizeof (locip)); eXosip_guess_ip_for_via (eXosip.eXtl->proto_family, locip, 49); if (locip[0] == '\0') { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: no default interface defined\n")); osip_message_free (*reg); *reg = NULL; return OSIP_NO_NETWORK; } if (contact == NULL) { osip_contact_t *new_contact = NULL; osip_uri_t *new_contact_url = NULL; i = osip_contact_init (&new_contact); if (i == 0) i = osip_uri_init (&new_contact_url); new_contact->url = new_contact_url; if (i == 0 && (*reg)->from != NULL && (*reg)->from->url != NULL && (*reg)->from->url->username != NULL) { new_contact_url->username = osip_strdup ((*reg)->from->url->username); } if (i == 0 && (*reg)->from != NULL && (*reg)->from->url != NULL) { /* serach for correct ip */ if (firewall_ip[0] != '\0') { char *c_address = (*reg)->req_uri->host; struct addrinfo *addrinfo; struct __eXosip_sockaddr addr; i = eXosip_get_addrinfo (&addrinfo, (*reg)->req_uri->host, 5060, IPPROTO_UDP); if (i == 0) { memcpy (&addr, addrinfo->ai_addr, addrinfo->ai_addrlen); eXosip_freeaddrinfo (addrinfo); c_address = inet_ntoa (((struct sockaddr_in *) &addr)->sin_addr); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "eXosip: here is the resolved destination host=%s\n", c_address)); } if (eXosip_is_public_address (c_address)) { new_contact_url->host = osip_strdup (firewall_ip); new_contact_url->port = osip_strdup (firewall_port); } else { new_contact_url->host = osip_strdup (locip); new_contact_url->port = osip_strdup (firewall_port); } } else { new_contact_url->host = osip_strdup (locip); new_contact_url->port = osip_strdup (firewall_port); } if (transport != NULL && osip_strcasecmp (transport, "UDP") != 0) { osip_uri_uparam_add (new_contact_url, osip_strdup ("transport"), osip_strdup (transport)); } if (jreg->r_line[0] != '\0') { osip_uri_uparam_add (new_contact_url, osip_strdup ("line"), osip_strdup (jreg->r_line)); } osip_list_add (&(*reg)->contacts, new_contact, -1); } } else { osip_message_set_contact (*reg, contact); } { char exp[10]; /* MUST never be ouside 1 and 3600 */ snprintf (exp, 9, "%i", expires); osip_message_set_expires (*reg, exp); } osip_message_set_content_length (*reg, "0"); return OSIP_SUCCESS;}#ifndef MINISIZEintgenerating_publish (osip_message_t ** message, const char *to, const char *from, const char *route){ int i; if (to != NULL && *to == '\0') return OSIP_BADPARAMETER; if (route != NULL && *route == '\0') route = NULL; i = generating_request_out_of_dialog (message, "PUBLISH", to, "UDP", from, route); if (i != 0) return i; /* osip_message_set_organization(*message, "Jack's Org"); */ return OSIP_SUCCESS;}#endifstatic intdialog_fill_route_set (osip_dialog_t * dialog, osip_message_t * request){ /* if the pre-existing route set contains a "lr" (compliance with bis-08) then the req_uri should contains the remote target URI */ int i; int pos = 0; osip_uri_param_t *lr_param; osip_route_t *route; char *last_route; /* AMD bug: fixed 17/06/2002 */ route = (osip_route_t *) osip_list_get (&dialog->route_set, 0); osip_uri_uparam_get_byname (route->url, "lr", &lr_param); if (lr_param != NULL) /* the remote target URI is the req_uri! */ { i = osip_uri_clone (dialog->remote_contact_uri->url, &(request->req_uri)); if (i != 0) return i; /* "[request] MUST includes a Route header field containing the route set values in order." */ /* AMD bug: fixed 17/06/2002 */ pos = 0; /* first element is at index 0 */ while (!osip_list_eol (&dialog->route_set, pos)) { osip_route_t *route2; route = osip_list_get (&dialog->route_set, pos); i = osip_route_clone (route, &route2); if (i != 0) return i; osip_list_add (&request->routes, route2, -1); pos++; } return OSIP_SUCCESS; } /* if the first URI of route set does not contain "lr", the req_uri is set to the first uri of route set */ i = osip_uri_clone (route->url, &(request->req_uri)); if (i != 0) return i; /* add the route set */ /* "The UAC MUST add a route header field containing the remainder of the route set values in order. */ pos = 0; /* yes it is */ while (!osip_list_eol (&dialog->route_set, pos)) /* not the first one in the list */ { osip_route_t *route2; route = osip_list_get (&dialog->route_set, pos); i = osip_route_clone (route, &route2); if (i != 0) return i; if (!osip_list_eol (&dialog->route_set, pos + 1)) osip_list_add (&request->routes, route2, -1); else osip_route_free (route2); pos++; } /* The UAC MUST then place the remote target URI into the route header field as the last value */ i = osip_uri_to_str (dialog->remote_contact_uri->url, &last_route);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -