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

📄 torture_sip.c

📁 this is simple sip stack.
💻 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>/* 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>int tstflags;#define TSTFLAGS tstflags#include <sofia-sip/tstdef.h>char const *name = "torture_sip.c";static int test_methods(void);static int test_basic(void);static int test_sip_msg_class(msg_mclass_t const *mc);static int test_encoding(void);static int tag_test(void);static int parser_tag_test(void);static int response_phrase_test(void);static int parser_test(void);static int sip_header_test(void);static int test_bad_packet(void);static int test_sip_list_header(void);static int test_prack(void);static int test_accept(void);static int test_content_disposition(void);static int test_features(void);static int test_retry_after(void);static int test_session_expires(void);static int test_min_se(void);static int test_refer(void);static int test_events(void);static int test_reason(void);static int test_warning(void);static int test_route(void);static int test_request_disposition(void);static int test_caller_prefs(void);static int test_callerpref_scoring(void);static int test_sec_ext(void);static int test_utils(void);msg_mclass_t *test_mclass = NULL;static msg_t *read_message(int flags, char const string[]);void usage(void){  fprintf(stderr, 	  "usage: %s [-v]\n", 	  name);}char *lastpart(char *path){  if (strchr(path, '/'))     return strrchr(path, '/') + 1;  else    return path;}int main(int argc, char *argv[]){  int retval = 0;  int i;  name = lastpart(argv[0]);  /* Set our name */  for (i = 1; argv[i]; i++) {    if (strcmp(argv[i], "-v") == 0)      tstflags |= tst_verbatim;    else      usage();  }  if (!test_mclass)    test_mclass = msg_mclass_clone(sip_default_mclass(), 0, 0);    retval |= test_methods(); fflush(stdout);  retval |= test_basic(); fflush(stdout);  retval |= test_sip_msg_class(test_mclass); fflush(stdout);  retval |= test_encoding(); fflush(stdout);  retval |= test_events(); fflush(stdout);  retval |= test_reason(); fflush(stdout);  retval |= tag_test(); fflush(stdout);  retval |= parser_tag_test(); fflush(stdout);  retval |= response_phrase_test(); fflush(stdout);  retval |= parser_test(); fflush(stdout);  retval |= sip_header_test(); fflush(stdout);  retval |= test_bad_packet(); fflush(stdout);  retval |= test_sip_list_header(); fflush(stdout);  retval |= test_prack(); fflush(stdout);  retval |= test_accept(); fflush(stdout);  retval |= test_content_disposition(); fflush(stdout);  retval |= test_features(); fflush(stdout);  retval |= test_retry_after(); fflush(stdout);  retval |= test_session_expires(); fflush(stdout);  retval |= test_min_se(); fflush(stdout);  retval |= test_refer(); fflush(stdout);  retval |= test_route(); fflush(stdout);  retval |= test_request_disposition(); fflush(stdout);  retval |= test_caller_prefs(); fflush(stdout);  retval |= test_callerpref_scoring(); fflush(stdout);  retval |= test_warning(); fflush(stdout);  retval |= test_sec_ext(); fflush(stdout);  retval |= test_utils(); fflush(stdout);  return retval;}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(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(sip_transport_d(&s, &result), 0); TEST(s, end);    TEST_S(result, sip_transport_udp);    s = tcp; end = s + strlen(s);    TEST(sip_transport_d(&s, &result), 0); TEST(s, end);    TEST_S(result, sip_transport_tcp);    s = tls; end = s + strlen(s);    TEST(sip_transport_d(&s, &result), 0); TEST(s, end);    TEST_S(result, sip_transport_tls);    s = sctp; end = s + strlen(s);    TEST(sip_transport_d(&s, &result), 0); TEST(s, end);    TEST_S(result, sip_transport_sctp);    s = dtls; end = s + strlen(s);    TEST(sip_transport_d(&s, &result), 0); TEST(s, end);    TEST_S(result, "SIP/2.0/TLS-UDP");    s = tls_sctp; end = s + strlen(s);    TEST(sip_transport_d(&s, &result), 0); TEST(s, end);    TEST_S(result, "SIP/2.0/TLS-SCTP");  }  END();}/* Test <sip_basic.c> functions. */int test_basic(void){  su_home_t *home = su_home_new(sizeof *home);  BEGIN();  TEST_1(home);    {    sip_request_t *rq, *rq1;    rq = sip_request_make(home, "INVITE sip:joe@example.com SIP/2.1");    TEST_1(rq);    TEST(rq->rq_method, sip_method_invite);    TEST_S(rq->rq_method_name, "INVITE");    TEST_1(rq1 = sip_request_dup(home, rq));    su_free(home, rq);    su_free(home, rq1);        rq = sip_request_make(home, "invite sip:joe@example.com SIP/2.0");    TEST_1(rq);    TEST(rq->rq_method, sip_method_unknown);    TEST_S(rq->rq_method_name, "invite");    TEST_1(rq1 = sip_request_dup(home, rq));    su_free(home, rq);    su_free(home, rq1);    TEST_1(!sip_request_create(home, sip_method_unknown, NULL, 			       (void *)"sip:joe@example.com", NULL));    TEST_1(rq = sip_request_create(home, sip_method_unknown, "invite", 				   (void *)"sip:joe@example.com", NULL));    TEST(rq->rq_method, sip_method_unknown);    TEST_S(rq->rq_method_name, "invite");    su_free(home, rq);    TEST_1(rq = sip_request_create(home, sip_method_unknown, "INVITE", 				   (void *)"sip:joe@example.com", NULL));    TEST(rq->rq_method, sip_method_invite);    TEST_S(rq->rq_method_name, "INVITE");    su_free(home, rq);    TEST_1(rq = sip_request_create(home, sip_method_invite, "foobar", 				   (void *)"sip:joe@example.com", NULL));    TEST(rq->rq_method, sip_method_invite);    TEST_S(rq->rq_method_name, "INVITE");    su_free(home, rq);  }  {    sip_status_t *st;    TEST_1(st = sip_status_make(home, "SIP/2.0 200 OK"));    su_free(home, st);    TEST_1(st = sip_status_make(home, "SIP/2.0 200"));    su_free(home, st);    TEST_1(!sip_status_make(home, "SIP2.0 200 OK"));    TEST_1(!sip_status_create(home, 99, NULL, "SIP/2.1"));    TEST_1(!sip_status_create(home, 700, NULL, "SIP/2.1"));    TEST_1(st = sip_status_create(home, 200, "Ok", "SIP/2.2"));    su_free(home, st);    TEST_1(st = sip_status_create(home, 200, NULL, "SIP/2.0"));    su_free(home, st);    TEST_1(st = sip_status_create(home, 200, NULL, NULL));    su_free(home, st);    TEST_1(st = sip_status_create(home, 699, NULL, NULL));    su_free(home, st);  }  {    sip_payload_t *pl;    TEST_1(pl = sip_payload_create(home, "foo", 3));    su_free(home, pl);    TEST_1(pl = sip_payload_create(home, NULL, 3));    su_free(home, pl);  }  {    sip_separator_t *sep;    TEST_1(!sip_separator_make(home, "foo"));    TEST_1(sep = sip_separator_create(home));    su_free(home, sep);  }  /* Test name-addr things */  {    su_home_t home[1] = { SU_HOME_INIT(home) };    char const *display;    url_t url[1];    char const * const *params;    char const *comment;    char const na[] = "Raaka Arska <tel:+358501970>;param=1;humppa (test) ";    char const na2[] = "tel:+358501970;param=1;humppa (test) ";    char *s, buf[sizeof(na)], ebuf[sizeof(na) + 32];    s = strcpy(buf, na);    TEST_1(sip_name_addr_d(home, &s, &display, url, &params, &comment) >= 0);    TEST(s, buf + strlen(na));    TEST_1(display);    TEST(url->url_type, url_tel);    TEST_1(params);    TEST_1(comment);    TEST(sip_name_addr_e(ebuf, sizeof(ebuf), 0, display, 0, url, 			 params, comment), 	 strlen(na) - 1);    TEST_1(strncmp(na, ebuf, strlen(na) - 1) == 0);    s = strcpy(buf, na2);    TEST_1(sip_name_addr_d(home, &s, &display, url, &params, &comment) >= 0);    TEST_S(s, "");    TEST(s, buf + strlen(na2));    TEST_1(!display);    TEST(url->url_type, url_tel);    TEST_1(params);    TEST_1(comment);    su_home_deinit(home);  }  {    sip_from_t *f; sip_to_t *t, *t2;    TEST_1(f = sip_from_create(home, (void *)"sip:joe@bar"));    TEST_1(sip_from_add_param(home, f, NULL) == -1);    TEST_1(sip_from_add_param(home, f, "tag=tagged") == 0);    TEST_S(f->a_tag, "tagged");    TEST_1(sip_from_tag(home, f, "jxahudsf") == -1);    while (f->a_params && f->a_params[0])      msg_header_remove_param(f->a_common, f->a_params[0]);    TEST(f->a_tag, NULL);    TEST_1(sip_from_add_param(home, f, "test=1") == 0);    TEST_1(sip_from_tag(home, f, "jxahudsf") == 0);    TEST_S(f->a_tag, "jxahudsf");    su_free(home, f);    TEST_1(!sip_from_create(home, (void *)"sip:joe@[baa"));    TEST_1(f = sip_from_make(home, (void *)"sip:joe@bar (foo)"));    su_free(home, f);    TEST_1(f = sip_from_make(home, (void *)"<sip:joe@bar;tag=bar> (joe)"));    TEST_1(sip_from_tag(home, f, "tag=jxahudsf") == 0);    su_free(home, f);    TEST_1(t = sip_to_create(home, (void *)"<sip:joe@bar;tag=bar> (joe)"));    TEST_1(sip_to_tag(home, t, "tag=jxahudsf") == 0);    TEST_S(t->a_tag, "jxahudsf");    TEST(msg_header_replace_param(home, t->a_common, "tag=bar"), 1);    TEST_S(t->a_tag, "bar");    TEST_1(t2 = sip_to_dup(home, t));    TEST_S(t2->a_tag, "bar");    TEST(msg_header_remove_param(t->a_common, "tag"), 1);    TEST(t->a_tag, NULL);    TEST_1(sip_to_add_param(home, t, "tst=1") == 0);    TEST(t->a_tag, NULL);    su_free(home, t);  }  {    sip_call_id_t *i, *i0;    TEST_1(i = sip_call_id_create(home, "example.com"));    i->i_hash = 0;    TEST_1(i0 = sip_call_id_dup(home, i));    su_free(home, i);    TEST_1(i = sip_call_id_make(home, i0->i_id));    TEST(i->i_hash, i0->i_hash);    su_free(home, i);    su_free(home, i0);  }

⌨️ 快捷键说明

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