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

📄 osip_message.c

📁 mediastreamer2是开源的网络传输媒体流的库
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)  Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Aymeric MOIZARD jack@atosc.org    This library is free software; you can redistribute it and/or  modify it under the terms of the GNU Lesser General Public  License as published by the Free Software Foundation; either  version 2.1 of the License, or (at your option) any later version.    This library is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public  License along with this library; if not, write to the Free Software  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#include <stdio.h>#include <stdlib.h>#include <osipparser2/osip_port.h>#include <osipparser2/osip_message.h>/* enable logging of memory accesses */const char *osip_protocol_version = "SIP/2.0";intosip_message_init (osip_message_t ** sip){  *sip = (osip_message_t *) osip_malloc (sizeof (osip_message_t));  if (*sip == NULL)    return OSIP_NOMEM;  memset (*sip, 0, sizeof (osip_message_t));#ifndef MINISIZE  osip_list_init (&(*sip)->accepts);  osip_list_init (&(*sip)->accept_encodings);  osip_list_init (&(*sip)->accept_languages);  osip_list_init (&(*sip)->alert_infos);  osip_list_init (&(*sip)->allows);  osip_list_init (&(*sip)->authentication_infos);#endif  osip_list_init (&(*sip)->authorizations);  (*sip)->call_id = NULL;#ifndef MINISIZE  osip_list_init (&(*sip)->call_infos);#endif  osip_list_init (&(*sip)->contacts);#ifndef MINISIZE  osip_list_init (&(*sip)->content_encodings);#endif  (*sip)->content_length = NULL;  (*sip)->content_type = NULL;  (*sip)->cseq = NULL;#ifndef MINISIZE  osip_list_init (&(*sip)->error_infos);#endif  (*sip)->from = NULL;  (*sip)->mime_version = NULL;  osip_list_init (&(*sip)->proxy_authenticates);#ifndef MINISIZE  osip_list_init (&(*sip)->proxy_authentication_infos);#endif  osip_list_init (&(*sip)->proxy_authorizations);  osip_list_init (&(*sip)->record_routes);  osip_list_init (&(*sip)->routes);  (*sip)->to = NULL;  osip_list_init (&(*sip)->vias);  osip_list_init (&(*sip)->www_authenticates);  osip_list_init (&(*sip)->bodies);  osip_list_init (&(*sip)->headers);  (*sip)->message_property = 3;  (*sip)->message = NULL;       /* buffer to avoid calling osip_message_to_str many times (for retransmission) */  (*sip)->message_length = 0;  (*sip)->application_data = NULL;  return OSIP_SUCCESS;                     /* ok */}voidosip_message_set_reason_phrase (osip_message_t * sip, char *reason){  sip->reason_phrase = reason;}voidosip_message_set_status_code (osip_message_t * sip, int status_code){  sip->status_code = status_code;}voidosip_message_set_method (osip_message_t * sip, char *sip_method){  sip->sip_method = sip_method;}voidosip_message_set_version (osip_message_t * sip, char *sip_version){  sip->sip_version = sip_version;}voidosip_message_set_uri (osip_message_t * sip, osip_uri_t * url){  sip->req_uri = url;}voidosip_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->call_infos, (void *(*)(void *)) &osip_call_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->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);}intosip_message_clone (const osip_message_t * sip, osip_message_t ** dest){  osip_message_t *copy;  int pos = 0;  int i;  *dest = NULL;  if (sip == NULL)    return OSIP_BADPARAMETER;  i = osip_message_init (&copy);  if (i != 0)    return i;  copy->sip_method = osip_strdup (sip->sip_method);  if (sip->sip_method!=NULL && copy->sip_method==NULL)  {	  osip_message_free (copy);	  return OSIP_NOMEM;  }  copy->sip_version = osip_strdup (sip->sip_version);  if (sip->sip_version!=NULL && copy->sip_version==NULL)  {	  osip_message_free (copy);	  return OSIP_NOMEM;  }  copy->status_code = sip->status_code;  copy->reason_phrase = osip_strdup (sip->reason_phrase);  if (sip->reason_phrase!=NULL && copy->reason_phrase==NULL)  {	  osip_message_free (copy);	  return OSIP_NOMEM;  }  if (sip->req_uri != NULL)    {      i = osip_uri_clone (sip->req_uri, &(copy->req_uri));      if (i != 0)	  {		  osip_message_free (copy);		  return i;	  }    }#ifndef MINISIZE  {    osip_accept_t *accept;    osip_accept_t *accept2;    pos = 0;    while (!osip_list_eol (&sip->accepts, pos))      {        accept = (osip_accept_t *) osip_list_get (&sip->accepts, pos);        i = osip_accept_clone (accept, &accept2);        if (i != 0)		{		  osip_message_free (copy);		  return i;		}        osip_list_add (&copy->accepts, accept2, -1);     /* insert as last element */        pos++;      }  }  {    osip_accept_encoding_t *accept_encoding;    osip_accept_encoding_t *accept_encoding2;    pos = 0;    while (!osip_list_eol (&sip->accept_encodings, pos))      {        accept_encoding =          (osip_accept_encoding_t *) osip_list_get (&sip->accept_encodings, pos);        i = osip_accept_encoding_clone (accept_encoding, &accept_encoding2);        if (i != 0)		{		  osip_message_free (copy);		  return i;		}        osip_list_add (&copy->accept_encodings, accept_encoding2, -1);        pos++;      }  }  {    osip_accept_language_t *accept_language;    osip_accept_language_t *accept_language2;    pos = 0;    while (!osip_list_eol (&sip->accept_languages, pos))      {        accept_language =          (osip_accept_language_t *) osip_list_get (&sip->accept_languages, pos);        i = osip_accept_language_clone (accept_language, &accept_language2);        if (i != 0)		{		  osip_message_free (copy);		  return i;		}        osip_list_add (&copy->accept_languages, accept_language2, -1);        pos++;      }  }  {    osip_alert_info_t *alert_info;    osip_alert_info_t *alert_info2;    pos = 0;    while (!osip_list_eol (&sip->alert_infos, pos))

⌨️ 快捷键说明

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