⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jrequest.c

📁 libosip2-3版本的osip源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    generating_request_out_of_dialog (reg, "REGISTER", NULL, transport, from,                                      proxy);  if (i != 0)    return -1;  i = _eXosip_find_protocol (*reg);  if (i == IPPROTO_UDP)    net = &eXosip.net_interfaces[0];  else if (i == IPPROTO_TCP)    net = &eXosip.net_interfaces[1];  else    {      net = &eXosip.net_interfaces[0];      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "eXosip: unsupported protocol\n"));      osip_message_free(*reg);      *reg=NULL;      return -1;    }  memset(locip, '\0', sizeof(locip));#ifdef SM  eXosip_get_localip_for ((*reg)->req_uri->host, locip, 49);#else  eXosip_guess_ip_for_via (net->net_ip_family, locip, 49);#endif  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 -1;    }  if (contact == NULL)    {      i = osip_from_init (&a_from);      if (i == 0)        i = osip_from_parse (a_from, from);      if (i == 0 && a_from != NULL          && a_from->url != NULL && a_from->url->username != NULL)        {          contact = (char *) osip_malloc (50 + strlen (a_from->url->username));          if (eXosip.net_interfaces[0].net_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);                  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))                {                  sprintf (contact, "<sip:%s@%s:%s>", a_from->url->username,                           eXosip.net_interfaces[0].net_firewall_ip,                           net->net_port);              } else                {                  sprintf (contact, "<sip:%s@%s:%s>", a_from->url->username,                           locip, net->net_port);                }          } else            {              sprintf (contact, "<sip:%s@%s:%s>", a_from->url->username,                       locip, net->net_port);            }          osip_message_set_contact (*reg, contact);          osip_free (contact);        }      osip_from_free (a_from);  } 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 0;}intgenerating_publish (osip_message_t ** message, const char *to,                    const char *from, const char *route){  int i;  if (to != NULL && *to == '\0')    return -1;  if (route != NULL && *route == '\0')    route = NULL;  i = generating_request_out_of_dialog (message, "PUBLISH", to, "UDP", from,                                        route);  if (i != 0)    return -1;  /* osip_message_set_organization(*message, "Jack's Org"); */  return 0;}static 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 -1;      /* "[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 -1;          osip_list_add (&request->routes, route2, -1);          pos++;        }      return 0;    }  /* 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 -1;  /* 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 -1;      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);  if (i != 0)    return -1;  i = osip_message_set_route (request, last_route);  osip_free (last_route);  if (i != 0)    {      return -1;    }  /* route header and req_uri set */  return 0;}int_eXosip_build_request_within_dialog (osip_message_t ** dest,                                     const char *method,                                     osip_dialog_t * dialog, const char *transport){  int i;  osip_message_t *request;  char locip[50];  struct eXosip_net *net;  *dest=NULL;  i = osip_message_init (&request);  if (i != 0)    return -1;  if (dialog->remote_contact_uri == NULL)    {      /* this dialog is probably not established! or the remote UA         is not compliant with the latest RFC       */      osip_message_free (request);      return -1;    }  if (0 == osip_strcasecmp (transport, "udp"))    net = &eXosip.net_interfaces[0];  else if (0 == osip_strcasecmp (transport, "tcp"))    net = &eXosip.net_interfaces[1];  else    {      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "eXosip: unsupported protocol -%s- (default to UDP)\n"));      net = &eXosip.net_interfaces[0];    }  memset(locip, '\0', sizeof(locip));#ifdef SM  eXosip_get_localip_for (dialog->remote_contact_uri->url->host, locip, 49);#else  eXosip_guess_ip_for_via (net->net_ip_family, locip, 49);#endif  if (locip[0]=='\0')    {      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "eXosip: no default interface defined\n"));      osip_message_free(request);      return -1;    }  /* prepare the request-line */  request->sip_method = osip_strdup (method);  request->sip_version = osip_strdup ("SIP/2.0");  request->status_code = 0;  request->reason_phrase = NULL;  /* and the request uri???? */  if (osip_list_eol (&dialog->route_set, 0))    {      /* The UAC must put the remote target URI (to field) in the req_uri */      i = osip_uri_clone (dialog->remote_contact_uri->url, &(request->req_uri));      if (i != 0)        goto grwd_error_1;  } else    {      /* fill the request-uri, and the route headers. */      dialog_fill_route_set (dialog, request);    }  /* To and From already contains the proper tag! */  i = osip_to_clone (dialog->remote_uri, &(request->to));  if (i != 0)    goto grwd_error_1;  i = osip_from_clone (dialog->local_uri, &(request->from));  if (i != 0)    goto grwd_error_1;  /* set the cseq and call_id header */  osip_message_set_call_id (request, dialog->call_id);  if (0 == strcmp ("ACK", method))    {      osip_cseq_t *cseq;      char *tmp;      i = osip_cseq_init (&cseq);      if (i != 0)        goto grwd_error_1;      tmp = osip_malloc (20);      sprintf (tmp, "%i", dialog->local_cseq);      osip_cseq_set_number (cseq, tmp);      osip_cseq_set_method (cseq, osip_strdup (method));      request->cseq = cseq;  } else    {      osip_cseq_t *cseq;      char *tmp;      i = osip_cseq_init (&cseq);      if (i != 0)        goto grwd_error_1;      dialog->local_cseq++;     /* we should we do that?? */      tmp = osip_malloc (20);      sprintf (tmp, "%i", dialog->local_cseq);      osip_cseq_set_number (cseq, tmp);      osip_cseq_set_method (cseq, osip_strdup (method));      request->cseq = cseq;    }  /* always add the Max-Forward header */  osip_message_set_max_forwards (request, "70"); /* a UA should start a request with 70 */  i = _eXosip_request_add_via(request, transport, locip);  if (i != 0)    goto grwd_error_1;  /* add specific headers for each kind of request... */  {    char contact[200];    if (net->net_firewall_ip[0] != '\0')      {        char *c_address = request->req_uri->host;        struct addrinfo *addrinfo;        struct __eXosip_sockaddr addr;        i =          eXosip_get_addrinfo (&addrinfo, request->req_uri->host, 5060,                               IPPROTO_UDP);        if (i == 0)          {            memcpy (&addr, addrinfo->ai_addr, addrinfo->ai_addrlen);            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))          {            sprintf (contact, "<sip:%s@%s:%s>",                     dialog->local_uri->url->username,                     eXosip.net_interfaces[0].net_firewall_ip, net->net_port);        } else          {            sprintf (contact, "<sip:%s@%s:%s>",                     dialog->local_uri->url->username, locip, net->net_port);          }    } else      {        sprintf (contact, "<sip:%s@%s:%s>", dialog->local_uri->url->username,                 locip, net->net_port);      }    osip_message_set_contact (request, contact);    /* Here we'll add the supported header if it's needed! */    /* the require header must be added by the upper layer if needed */  }  if (0 == strcmp ("NOTIFY", method))    {  } else if (0 == strcmp ("INFO", method))    {  } else if (0 == strcmp ("OPTIONS", method))    {      osip_message_set_accept (request, "application/sdp");  } else if (0 == strcmp ("ACK", method))    {      /* The ACK MUST contains the same credential than the INVITE!! */      /* TODO... */    }  osip_message_set_user_agent (request, eXosip.user_agent);  /*  else if ... */  *dest = request;  return 0;  /* grwd_error_2: */  dialog->local_cseq--;grwd_error_1:  osip_message_free (request);  *dest = NULL;  return -1;}/* this request is only build within a dialog!! */intgenerating_bye (osip_message_t ** bye, osip_dialog_t * dialog, char *transport){  int i;  i = _eXosip_build_request_within_dialog (bye, "BYE", dialog, transport);  if (i != 0)    return -1;  return 0;}/* It is RECOMMENDED to only cancel INVITE request */intgenerating_cancel (osip_message_t ** dest, osip_message_t * request_cancelled){  int i;  osip_message_t *request;  i = osip_message_init (&request);  if (i != 0)    return -1;  /* prepare the request-line */  osip_message_set_method (request, osip_strdup ("CANCEL"));  osip_message_set_version (request, osip_strdup ("SIP/2.0"));  osip_message_set_status_code (request, 0);  osip_message_set_reason_phrase (request, NULL);  i = osip_uri_clone (request_cancelled->req_uri, &(request->req_uri));  if (i != 0)    goto gc_error_1;  i = osip_to_clone (request_cancelled->to, &(request->to));  if (i != 0)    goto gc_error_1;  i = osip_from_clone (request_cancelled->from, &(request->from));  if (i != 0)    goto gc_error_1;  /* set the cseq and call_id header */  i = osip_call_id_clone (request_cancelled->call_id, &(request->call_id));  if (i != 0)    goto gc_error_1;  i = osip_cseq_clone (request_cancelled->cseq, &(request->cseq));  if (i != 0)    goto gc_error_1;  osip_free (request->cseq->method);  request->cseq->method = osip_strdup ("CANCEL");  /* copy ONLY the top most Via Field (this method is also used by proxy) */  {    osip_via_t *via;    osip_via_t *via2;    i = osip_message_get_via (request_cancelled, 0, &via);    if (i != 0)      goto gc_error_1;    i = osip_via_clone (via, &via2);    if (i != 0)      goto gc_error_1;    osip_list_add (&request->vias, via2, -1);  }  /* add the same route-set than in the previous request */  {    int pos = 0;    osip_route_t *route;    osip_route_t *route2;    while (!osip_list_eol (&request_cancelled->routes, pos))      {        route = (osip_route_t *) osip_list_get (&request_cancelled->routes, pos);        i = osip_route_clone (route, &route2);        if (i != 0)          goto gc_error_1;        osip_list_add (&request->routes, route2, -1);        pos++;      }  }  osip_message_set_max_forwards (request, "70");        /* a UA should start a request with 70 */  osip_message_set_user_agent (request, eXosip.user_agent);  *dest = request;  return 0;gc_error_1:  osip_message_free (request);  *dest = NULL;  return -1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -