2 The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
3 Copyright (C) 2001,2002,2003 Aymeric MOIZARD jack@atosc.org
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <osipparser2/osip_rfc3264.h>
25 #include <osipparser2/osip_port.h>
27 #define AUDIO_CODEC 0x01
28 #define VIDEO_CODEC 0x02
29 #define T38_CODEC 0x04
30 #define APP_CODEC 0x08
32 int test_add_codec(struct osip_rfc3264 *cnf, int codec_type,
33 int payload, char *attribute);
34 sdp_message_t *get_test_remote_message(int index, FILE *torture_file, int verbose);
36 int test_add_codec(struct osip_rfc3264 *cnf, int codec_type,
37 int payload, char *attribute)
40 sdp_attribute_t *attr;
43 if (payload>127) return -1;
44 if (attribute==NULL || strlen(attribute)==0) return -1;
46 i = sdp_media_init(&med);
50 snprintf(tmp, 3, "%i", payload);
51 med->m_proto = strdup("RTP/AVP");
52 osip_list_add(med->m_payloads, tmp, -1);
54 i = sdp_attribute_init (&attr);
57 attr->a_att_field = strdup("rtpmap");
58 attr->a_att_value = strdup(attribute);
59 osip_list_add (med->a_attributes, attr, -1);
65 med->m_media = strdup("audio");
66 osip_rfc3264_add_audio_media(cnf, med, -1);
69 med->m_media = strdup("video");
70 osip_rfc3264_add_video_media(cnf, med, -1);
80 sdp_message_t *get_test_remote_message(int index, FILE *torture_file, int verbose)
82 sdp_message_t *remote_sdp;
90 tmp = (char *) osip_malloc (500);
91 marker = fgets (tmp, 500, torture_file); /* lines are under 500 */
92 while (marker != NULL && i < index)
94 if (0 == strncmp (tmp, "|", 1))
96 marker = fgets (tmp, 500, torture_file);
99 msg = (char *) osip_malloc (10000); /* msg are under 10000 */
105 "Error! The message's number you specified does not exist\n");
107 return NULL; /* end of file detected! */
109 /* this part reads an entire message, separator is "|" */
110 /* (it is unlinkely that it will appear in messages!) */
111 while (marker != NULL && strncmp (tmp, "|", 1))
113 osip_strncpy (tmpmsg, tmp, strlen (tmp));
114 tmpmsg = tmpmsg + strlen (tmp);
115 marker = fgets (tmp, 500, torture_file);
119 fprintf (stdout, "%s\n", msg);
121 i = sdp_message_init(&remote_sdp);
122 if (i!=0) return NULL;
124 i = sdp_message_parse(remote_sdp, msg);
125 if (i!=0) return NULL;
130 int main(int argc, char **argv)
132 struct osip_rfc3264 *cnf;
134 int verbose = 0; /* 0: verbose, 1 (or nothing: not verbose) */
139 if (0 == strncmp (argv[3], "-v", 2))
141 if (0 == strcmp (argv[3], "-vv"))
145 fprintf (stdout, "test %i : ============================ \n", atoi(argv[2]));
147 torture_file = fopen (argv[1], "r");
148 if (torture_file == NULL)
151 "Failed to open \"torture_sdps\" file.\nUsage: %s torture_file [-v]\n",
153 fprintf (stdout, "test %s : ============================ FAILED\n", argv[2]);
162 i = osip_rfc3264_init(&cnf);
165 fprintf(stderr, "Cannot Initialize Negotiator feature.\n");
166 osip_rfc3264_free(cnf);
167 fclose (torture_file);
168 fprintf (stdout, "test %s : ============================ FAILED\n", argv[2]);
172 test_add_codec(cnf, AUDIO_CODEC, 0, "0 PCMU/8000");
173 test_add_codec(cnf, AUDIO_CODEC, 8, "8 PCMA/8000");
174 test_add_codec(cnf, AUDIO_CODEC, 18, "18 G729/8000");
176 test_add_codec(cnf, VIDEO_CODEC, 97, "97 XXX/11111");
177 test_add_codec(cnf, VIDEO_CODEC, 31, "31 H261/90000");
180 osip_rfc3264_del_video_media(cnf, 0);
181 osip_rfc3264_del_audio_media(cnf, 1);
182 osip_rfc3264_del_audio_media(cnf, 2);
184 test_add_codec(cnf, AUDIO_CODEC, 8, "0 PCMA/8000");
185 test_add_codec(cnf, AUDIO_CODEC, 18, "18 G729/8000");
189 __osip_rfc3264_print_codecs(cnf);
192 sdp_message_t *remote_sdp;
193 sdp_media_t *audio_tab[10];
194 sdp_media_t *video_tab[10];
195 sdp_media_t *t38_tab[10];
196 sdp_media_t *app_tab[10];
202 char str_local_sdp[8192];
203 sdp_message_t *local_sdp;
207 remote_sdp = get_test_remote_message(atoi(argv[2]), torture_file, verbose);
210 fprintf(stderr, "Cannot Get remote SDP message for testing.\n");
211 osip_rfc3264_free(cnf);
212 fclose (torture_file);
213 fprintf (stdout, "test %s : ============================ FAILED\n", argv[2]);
217 i=osip_rfc3264_prepare_answer(cnf, remote_sdp, str_local_sdp, 8192);
220 fprintf(stderr, "Cannot Prepare local SDP answer from offer.\n");
221 osip_rfc3264_free(cnf);
222 fclose (torture_file);
223 fprintf (stdout, "test %s : ============================ FAILED\n", argv[2]);
226 sdp_message_init(&local_sdp);
227 i=sdp_message_parse(local_sdp, str_local_sdp);
230 fprintf(stderr, "Cannot Parse uncomplete SDP answer from offer.\n");
231 sdp_message_free(local_sdp);
232 osip_rfc3264_free(cnf);
233 fclose (torture_file);
234 fprintf (stdout, "test %s : ============================ FAILED\n", argv[2]);
239 while (0==osip_rfc3264_match(cnf, remote_sdp,
240 audio_tab, video_tab, t38_tab, app_tab, mline))
244 if (audio_tab[0]==NULL && video_tab[0]==NULL && t38_tab[0]==NULL && app_tab[0]==NULL)
247 fprintf(stdout, "The remote SDP does not match any local payloads.\n");
251 for (pos=0;audio_tab[pos]!=NULL;pos++)
254 sdp_media_t *med = audio_tab[pos];
255 char *str = (char *) osip_list_get (med->m_payloads, 0);
257 fprintf(stdout, "\tm=%s %s %s %s\n",
262 while (!osip_list_eol (med->a_attributes, pos2))
264 sdp_attribute_t *attr =
265 (sdp_attribute_t *) osip_list_get (med->a_attributes, pos2);
267 fprintf(stdout, "\ta=%s:%s\n",
273 fprintf(stdout, "\n");
275 i=osip_rfc3264_complete_answer(cnf, remote_sdp, local_sdp, audio_tab[pos], mline);
279 fprintf(stdout, "Error Adding support for codec in answer?\n");
284 fprintf(stdout, "support for codec added in answer:\n");
288 for (pos=0;video_tab[pos]!=NULL;pos++)
291 sdp_media_t *med = video_tab[pos];
292 char *str = (char *) osip_list_get (med->m_payloads, 0);
294 fprintf(stdout, "\tm=%s %s %s %s\n",
299 while (!osip_list_eol (med->a_attributes, pos2))
301 sdp_attribute_t *attr =
302 (sdp_attribute_t *) osip_list_get (med->a_attributes, pos2);
304 fprintf(stdout, "\ta=%s:%s\n",
310 fprintf(stdout, "\n");
312 i=osip_rfc3264_complete_answer(cnf, remote_sdp, local_sdp, video_tab[pos], mline);
316 fprintf(stdout, "Error Adding support for codec in answer?\n");
321 fprintf(stdout, "support for codec added in answer:\n");
330 fprintf(stdout, "Result in answer:\n");
331 sdp_message_to_str(local_sdp, &tmp);
335 fprintf(stdout, "\n%s\n", tmp);
341 fprintf(stdout, "ERROR\n");
345 osip_rfc3264_free(cnf);
346 fclose (torture_file);
347 fprintf (stdout, "test %s : ============================ OK\n", argv[2]);