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

📄 torture_sip.c

📁 Sofia SIP is an open-source SIP User-Agent library, compliant with the IETF RFC3261 specification.
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * This file is part of the Sofia-SIP package * * Copyright (C) 2005 Nokia Corporation. * * Contact: Pekka Pessi <pekka.pessi@nokia.com> * * 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., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * *//**@ingroup sip_test @internal * * @CFILE torture_sip.c   * * Unit-testing functions for SIP. * * @author Pekka Pessi <Pekka.Pessi@nokia.com>. * * @date Created: Tue Mar  6 18:33:42 2001 ppessi */#include "config.h"#include <stdio.h>#include <string.h>#include <stddef.h>#include <stdlib.h>/* Avoid casting sip_t to msg_pub_t and sip_header_t to msg_header_t */#define MSG_PUB_T       struct sip_s#define MSG_HDR_T       union sip_header_u#include <sofia-sip/su_types.h>#include <sofia-sip/su_tag.h>#include <sofia-sip/su_tag_class.h>#include <sofia-sip/su_tag_io.h>#include "sofia-sip/sip_parser.h"#include <sofia-sip/sip_util.h>#include <sofia-sip/sip_status.h>#include <sofia-sip/sip_tag.h>#include <sofia-sip/url_tag.h>#include <sofia-sip/msg_addr.h>#include <sofia-sip/msg_mclass.h>#include <sofia-sip/msg_mclass_hash.h>#include <sofia-sip/sip_extra.h>int tstflags;#define TSTFLAGS tstflags#include <sofia-sip/tstdef.h>char const *name = "torture_sip.c";msg_mclass_t *test_mclass = NULL;static msg_t *read_message(int flags, char const string[]);static int test_identity(void){  su_home_t *home;  sip_alert_info_t *ai;  sip_reply_to_t *rplyto;  sip_remote_party_id_t *rpid;  sip_p_asserted_identity_t *paid;  sip_p_preferred_identity_t *ppid;  msg_t *msg;  sip_t *sip;  BEGIN();  msg_href_t const *href;  msg_mclass_t const *def0, *def1, *ext;  def0 = sip_default_mclass();  /* Check that Refer-Sub has been added to our parser */  TEST_1(href = msg_find_hclass(def0, "Refer-Sub", NULL));  TEST_P(href->hr_class, sip_refer_sub_class);  /* Check that Reply-To is not there */  TEST_P(msg_find_hclass(def0, "Reply-To", NULL), def0->mc_unknown);  TEST_1(ext = sip_extend_mclass(NULL));  /* Update default parser */  TEST_1(sip_update_default_mclass(ext) == 0);  def1 = sip_default_mclass();  TEST_1(def0 != def1);  TEST_1(ext == def1);  TEST_1(href = msg_find_hclass(def1, "Reply-To", NULL));  TEST_P(href->hr_class, sip_reply_to_class);  TEST_1(test_mclass = msg_mclass_clone(def0, 0, 0));  msg = read_message(MSG_DO_EXTRACT_COPY,     "BYE sip:foo@bar SIP/2.0\r\n"    "To: <sip:foo@bar>;tag=deadbeef\r\n"    "From: <sip:bar@foo>;\r\n"    "Call-ID: 0ha0isndaksdj@10.1.2.3\r\n"    "CSeq: 8 SUBSCRIBE\r\n"    "Via: SIP/2.0/UDP 135.180.130.133\r\n"    "Alert-Info: <http://test.com/tune>;walz, <http://test.com/buzz>\r\n"    "Reply-To: Arska <sip:arska@gov.ca.us>;humppa\r\n"    "P-Asserted-Identity: <sip:test@test.domain.com>\r\n"    "P-Preferred-Identity: <sip:test@test.domain.com>, <tel:+358708008000>\r\n"    "Remote-Party-ID: <sip:test2@test.domain.com>\r\n"    "Content-Length: 0\r\n"    "\r\n");  sip = sip_object(msg);  TEST_1(!sip_alert_info(sip));  TEST_1(!sip_reply_to(sip));  TEST_1(!sip_p_asserted_identity(sip));  TEST_1(!sip_p_preferred_identity(sip));  TEST_1(!sip_remote_party_id(sip));  msg_destroy(msg);  TEST_1(msg_mclass_insert_header(test_mclass, 				  sip_p_asserted_identity_class, 0) > 0);  TEST_1(msg_mclass_insert_header(test_mclass, 				  sip_p_preferred_identity_class, 0) > 0);  msg = read_message(MSG_DO_EXTRACT_COPY,     "BYE sip:foo@bar SIP/2.0\r\n"    "To: <sip:foo@bar>;tag=deadbeef\r\n"    "From: <sip:bar@foo>;\r\n"    "Call-ID: 0ha0isndaksdj@10.1.2.3\r\n"    "CSeq: 8 SUBSCRIBE\r\n"    "Via: SIP/2.0/UDP 135.180.130.133\r\n"    "Alert-Info: <http://test.com/tune>;walz, <http://test.com/buzz>\r\n"    "Reply-To: Arska <sip:arska@gov.ca.us>;humppa\r\n"    "P-Asserted-Identity: <sip:test@test.domain.com>\r\n"    "P-Preferred-Identity: <sip:test@test.domain.com>, <tel:+358708008000>\r\n"    "Remote-Party-ID: <sip:test2@test.domain.com>\r\n"    "Content-Length: 0\r\n"    "\r\n");  sip = sip_object(msg);  TEST_1(!sip_alert_info(sip));  TEST_1(!sip_reply_to(sip));  TEST_1(sip_p_asserted_identity(sip));  TEST_1(sip_p_preferred_identity(sip));  TEST_1(!sip_remote_party_id(sip));  TEST_1(home = msg_home(msg));    TEST_1((paid = sip_p_asserted_identity_make(home, "sip:joe@example.com")));  TEST_1((paid = sip_p_asserted_identity_make	  (home, "Jaska <sip:joe@example.com>, Helmi <tel:+3587808000>")));  TEST_1(paid->paid_next);  TEST_1((ppid = sip_p_preferred_identity_make(home, "sip:joe@example.com")));  TEST_1((ppid = sip_p_preferred_identity_make	  (home, "Jaska <sip:joe@example.com>, Helmi <tel:+3587808000>")));  msg_destroy(msg);  /* Now with extensions */  TEST_1(test_mclass = msg_mclass_clone(def1, 0, 0));  msg = read_message(MSG_DO_EXTRACT_COPY,     "BYE sip:foo@bar SIP/2.0\r\n"    "To: <sip:foo@bar>;tag=deadbeef\r\n"    "From: <sip:bar@foo>;\r\n"    "Call-ID: 0ha0isndaksdj@10.1.2.3\r\n"    "CSeq: 8 SUBSCRIBE\r\n"    "Via: SIP/2.0/UDP 135.180.130.133\r\n"    "Alert-Info: <http://test.com/tune>;walz, <http://test.com/buzz>\r\n"    "Reply-To: Arska <sip:arska@gov.ca.us>;humppa\r\n"    "P-Asserted-Identity: <sip:test@test.domain.com>\r\n"    "P-Preferred-Identity: <sip:test@test.domain.com>, <tel:+358708008000>\r\n"    "Remote-Party-ID: <sip:test2@test.domain.com>\r\n"    "Content-Length: 0\r\n"    "\r\n");  sip = sip_object(msg);  TEST_1(ai = sip_alert_info(sip));  TEST_S(ai->ai_url->url_host, "test.com");  TEST_1(rplyto = sip_reply_to(sip));  TEST_S(rplyto->rplyto_url->url_host, "gov.ca.us");  TEST_1(paid = sip_p_asserted_identity(sip));  TEST_1(ppid = sip_p_preferred_identity(sip));  TEST_1(rpid = sip_remote_party_id(sip));  TEST_S(rpid->rpid_url->url_host, "test.domain.com");  msg_destroy(msg);  {    su_home_t *home = su_home_clone(NULL, sizeof *home);    char *s;    char const canonic[] =       "\"Jaska Jokunen\" <sip:jaska.jokunen@example.com>;"      "screen=yes;party=called;id-type=user;privacy=\"name,uri-network\"";    char const canonic2[] =       "Jaska Jokunen <sip:jaska.jokunen@example.com>;"      "screen=yes;party=called;id-type=user;privacy=\"name,uri-network\"";    sip_remote_party_id_t *rpid, *d;    TEST_1(rpid = sip_remote_party_id_make(home, canonic));    TEST_S(rpid->rpid_display, "\"Jaska Jokunen\"");    TEST_S(rpid->rpid_url->url_user, "jaska.jokunen");    TEST_S(rpid->rpid_params[0], "screen=yes");    TEST_S(rpid->rpid_screen, "yes");    TEST_S(rpid->rpid_party, "called");    TEST_S(rpid->rpid_id_type, "user");    TEST_S(rpid->rpid_privacy, "\"name,uri-network\"");    TEST_1(s = sip_header_as_string(home, (void*)rpid));    TEST_S(s, canonic);    TEST_1(d = sip_remote_party_id_dup(home, rpid));    TEST_S(d->rpid_display, rpid->rpid_display);    TEST_S(d->rpid_params[0], rpid->rpid_params[0]);    TEST_1(rpid = sip_remote_party_id_make(home, canonic2));    TEST_S(rpid->rpid_display, "Jaska Jokunen");    TEST_1(s = sip_header_as_string(home, (void*)rpid));    TEST_S(s, canonic2);    TEST_1(d = sip_remote_party_id_dup(home, rpid));    TEST_S(d->rpid_display, rpid->rpid_display);    su_home_check(home);        su_home_zap(home);  }  END();}int test_url_headers(void){  BEGIN();  su_home_t *home;  char *s, *d;  tagi_t *t;  url_t *url;  sip_from_t const *f;  sip_accept_t const *ac;  sip_payload_t const *body;  sip_refer_sub_t rs[1];  TEST_1(home = su_home_new(sizeof *home));  sip_refer_sub_init(rs)->rs_value = "false";  s = sip_headers_as_url_query    (home,     SIPTAG_SUBJECT_STR("kuik"),     SIPTAG_REFER_SUB(rs),     TAG_END());  TEST_1(s);  TEST_S(s, "subject=kuik&refer-sub=false");  s = sip_headers_as_url_query    (home,     SIPTAG_TO_STR("\"Joe\" <sip:joe@example.com>;tag=foofaa"),     SIPTAG_SUBJECT_STR("foo"),     TAG_END());  TEST_1(s);  TEST_S(s, "to=%22Joe%22%20%3Csip%3Ajoe@example.com%3E%3Btag%3Dfoofaa"	 "&subject=foo");  url = url_format(home, "sip:test@example.net?%s", s); TEST_1(url);  TEST_S(url->url_headers, s);  s = sip_headers_as_url_query    (home,     SIPTAG_FROM_STR("<sip:joe@example.com;user=ip>"),     SIPTAG_ACCEPT_STR(""),     SIPTAG_PAYLOAD_STR("hello"),     SIPTAG_ACCEPT_STR(""),     TAG_END());  TEST_S(s, "from=%3Csip%3Ajoe@example.com%3Buser%3Dip%3E"	 "&accept="	 "&body=hello"	 "&accept=");  d = url_query_as_header_string(home, s);  TEST_S(d, "from:<sip:joe@example.com;user=ip>\n"	 "accept:\n"	 "accept:\n"	 "\n"	 "hello");  t = sip_url_query_as_taglist(home, s, NULL); TEST_1(t);  TEST_P(t[0].t_tag, siptag_from);    TEST_1(f = (void *)t[0].t_value);  TEST_P(t[1].t_tag, siptag_accept);  TEST_1(ac = (void *)t[1].t_value);  TEST_P(t[2].t_tag, siptag_payload); TEST_1(body = (void *)t[2].t_value);  TEST_P(t[3].t_tag, siptag_accept);   s = "xyzzy=foo";  t = sip_url_query_as_taglist(home, s, NULL); TEST_1(t);  TEST_P(t[0].t_tag, siptag_header_str);  TEST_1(d = (void *)t[0].t_value);  TEST_S(d, "foo");  TEST_1(!sip_headers_as_url_query(home, SIPTAG_SEPARATOR_STR(""), TAG_END()));  TEST_VOID(su_home_unref(home));  END();}int test_manipulation(void){  BEGIN();  sip_content_length_t *l;  sip_payload_t *pl;  msg_t *msg, *msg0;  sip_t *sip;  msg0 = read_message(MSG_DO_EXTRACT_COPY,     "MESSAGE sip:foo@bar SIP/2.0\r\n"    "To: Joe User <sip:foo@bar>\r\n"    "From: \"Bar Owner\" <sip:bar@foo>;tag=foobar\r\n"    "Call-ID: 0ha0isndaksdj@10.1.2.3\r\n"    "CSeq: 8 MESSAGE\r\n"    "Via: SIP/2.0/UDP 135.180.130.133\r\n"    "Content-Length: 7\r\n"    "Content-Type: text/plain\r\n"    "\r\n"    "Heippa!");  TEST_1(msg0);  TEST_1(msg = msg_copy(msg0));  TEST_1(sip = sip_object(msg));  TEST_1(l = sip_content_length_make(msg_home(msg), "6"));  TEST_1(pl = sip_payload_make(msg_home(msg), "hello!"));  TEST_1(msg_header_replace(msg, NULL, 			    (void *)sip->sip_content_length, 			    (void *)l) >= 0);  TEST_1(msg_header_replace(msg, NULL, 			    (void *)sip->sip_payload, 			    (void *)pl) >= 0);  TEST(msg_serialize(msg, NULL), 0);  TEST_1(msg_prepare(msg) > 0);  msg_destroy(msg);  msg_destroy(msg0);  END();}int test_methods(void){  int i;  char name[32];  BEGIN();  for (i = 1; sip_method_names[i]; i++) {    TEST_S(sip_method_names[i], sip_method_name(i, "foo"));  }  {    char version[] = "protocol /  version  ";    char *end = version + strlen(version);    char *s = version;    char const *result = NULL;    TEST(sip_version_d(&s, &result), 0);    TEST_P(s, end);    TEST_S(result, "protocol/version");  }  {    char udp[] = "SIP/ 2.0  /  udp";    char tcp[] = "SIP / 2.0  /  tcp";    char tls[] = "SIP / 2.0  /  tls";    char sctp[] = "SIP / 2.0  /  scTp";    char dtls[] = "SIP/2.0/TLS-UDP";    char tls_sctp[] = "SIP/2.0/TLS-SCTP";    char *s, *end;    char const *result = NULL;    s = udp; end = s + strlen(s);    TEST_SIZE(sip_transport_d(&s, &result), 0); TEST_P(s, end);    TEST_S(result, sip_transport_udp);    s = tcp; end = s + strlen(s);    TEST_SIZE(sip_transport_d(&s, &result), 0); TEST_P(s, end);    TEST_S(result, sip_transport_tcp);

⌨️ 快捷键说明

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