1 /*
2 * This file is part of the Sofia-SIP package
3 *
4 * Copyright (C) 2005 Nokia Corporation.
5 *
6 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25 /**@internal
26 *
27 * @CFILE test_sdp.c
28 *
29 * Simple SDP tester
30 *
31 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
32 *
33 * @date Created : Fri Feb 18 10:25:08 2000 ppessi
34 */
35
36 #include "config.h"
37
38 #include <stddef.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <stdio.h>
42
43 #include "sofia-sip/sdp.h"
44
diff(const char * olds,const char * news,int * linep,int * pos)45 int diff(const char *olds, const char *news, int *linep, int *pos)
46 {
47 const char *o, *n;
48
49 *linep = 0;
50
51 for (o = olds, n = news; *o && *n && *o == *n ; o++, n++) {
52 if (*o == '\n') ++*linep;
53 }
54
55 *pos = o - olds;
56
57 return *o != *n;
58 }
59
main(int argc,char * argv[])60 int main(int argc, char *argv[])
61 {
62 char buffer[2048];
63 int n;
64 su_home_t *home = su_home_create();
65 int exitcode = 1;
66 FILE *f;
67
68 if (argv[1] && strcmp(argv[1], "-"))
69 f = fopen(argv[1], "rb");
70 else
71 f = stdin;
72
73 n = fread(buffer, 1, sizeof(buffer) - 1, f);
74 buffer[n] = 0;
75
76 if (feof(f)) {
77 sdp_parser_t *p = sdp_parse(home, buffer, n + 1, 0);
78
79 su_home_check(home);
80 su_home_check((su_home_t *)p);
81
82 if (sdp_session(p)) {
83 sdp_session_t *sdp, *dup;
84 sdp_printer_t *printer;
85
86 sdp = sdp_session(p);
87 dup = sdp_session_dup(home, sdp);
88 su_home_check(home);
89
90 sdp_parser_free(p), p = NULL;
91 su_home_check(home);
92
93 printer = sdp_print(home, dup, NULL, 0, 0);
94 su_home_check(home);
95
96 if (sdp_message(printer)) {
97 int line, pos;
98
99 if (diff(buffer, sdp_message(printer), &line, &pos)) {
100 fprintf(stdout, "test_sdp:%d: messages differ:\n", line);
101 fputs(buffer, stdout);
102 fprintf(stdout, ">>>new message:\n");
103 fputs(sdp_message(printer), stdout);
104 }
105 else {
106 exitcode = 0;
107 }
108 }
109 else {
110 fprintf(stderr, "test_sdp: %s\n", sdp_printing_error(printer));
111 }
112 sdp_printer_free(printer);
113
114 su_home_check(home);
115 }
116 else {
117 fprintf(stderr, "test_sdp: %s\n", sdp_parsing_error(p));
118 sdp_parser_free(p);
119 exit(1);
120 }
121 }
122 else {
123 if (ferror(f)) {
124 perror("test_sdp");
125 }
126 else {
127 fprintf(stderr, "test_sdp: maximum length of sdp messages is %u bytes\n",
128 (unsigned)sizeof(buffer));
129 }
130 exit(1);
131 }
132
133 su_home_unref(home);
134
135 return exitcode;
136 }
137