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 /**@CFILE test_extension.c
26  * @brief NUA-12: Test extension methods.
27  *
28  * @author Pekka Pessi <Pekka.Pessi@nokia.com>
29  *
30  * @date Created: Mon Nov 13 15:37:05 EET 2006
31  */
32 
33 #include "config.h"
34 
35 #include "test_nua.h"
36 
37 #include <sofia-sip/su_tag_class.h>
38 
39 #if HAVE_FUNC
40 #elif HAVE_FUNCTION
41 #define __func__ __FUNCTION__
42 #else
43 #define __func__ "test_extension"
44 #endif
45 
46 
respond_to_extension(CONDITION_PARAMS)47 int respond_to_extension(CONDITION_PARAMS)
48 {
49   msg_t *with = nua_current_request(nua);
50 
51   if (!(check_handle(ep, call, nh, SIP_500_INTERNAL_SERVER_ERROR)))
52     return 0;
53 
54   save_event_in_list(ctx, event, ep, call);
55 
56   switch (event) {
57   case nua_i_method:
58     RESPOND(ep, call, nh, SIP_200_OK,
59 	    NUTAG_WITH(with),
60 	    SIPTAG_SUBJECT_STR("extended"),
61 	    TAG_END());
62     return 1;
63   default:
64     return 0;
65   }
66 }
67 
test_extension(struct context * ctx)68 int test_extension(struct context *ctx)
69 {
70   BEGIN();
71 
72   struct endpoint *a = &ctx->a,  *b = &ctx->b;
73   struct call *a_call = a->call, *b_call = b->call;
74   struct event *e;
75   sip_t const *sip;
76 
77 
78 /* Test for EXTENSION
79 
80    A			B
81    |------EXTENSION---->|
82    |<--------501--------| (method not recognized)
83    |			|
84    |------EXTENSION---->|
85    |<-------200---------| (method allowed, responded)
86    |			|
87 */
88 
89   if (print_headings)
90     printf("TEST NUA-13.1: EXTENSION\n");
91 
92 
93   TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END()));
94 
95   /* Test first without NUTAG_METHOD() */
96   METHOD(a, a_call, a_call->nh,
97 	 TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)),
98 	 TAG_END());
99 
100   run_ab_until(ctx, -1, save_until_final_response, -1, NULL);
101 
102   /* Client events:
103      nua_method(), nua_r_method
104   */
105   TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_method);
106   TEST(e->data->e_status, 900);	/* Internal error */
107   TEST_1(!e->data->e_msg);
108   TEST_1(!e->next);
109 
110   free_events_in_list(ctx, a->events);
111   nua_handle_destroy(a_call->nh), a_call->nh = NULL;
112 
113   TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END()));
114 
115   METHOD(a, a_call, a_call->nh,
116 	 TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)),
117 	 NUTAG_METHOD("EXTENSION"),
118 	 TAG_END());
119 
120   run_ab_until(ctx, -1, save_until_final_response, -1, NULL);
121 
122   /* Client events:
123      nua_method(), nua_r_method
124   */
125   TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_method);
126   TEST(e->data->e_status, 501);
127   TEST_1(!e->next);
128 
129   free_events_in_list(ctx, a->events);
130   nua_handle_destroy(a_call->nh), a_call->nh = NULL;
131 
132   free_events_in_list(ctx, b->events);
133   nua_handle_destroy(b_call->nh), b_call->nh = NULL;
134 
135   nua_set_params(b->nua, NUTAG_ALLOW("EXTENSION"), TAG_END());
136 
137   run_b_until(ctx, nua_r_set_params, until_final_response);
138 
139   TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END()));
140 
141   METHOD(a, a_call, a_call->nh,
142 	 TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)),
143 	 NUTAG_METHOD("EXTENSION"),
144 	 TAG_END());
145 
146   run_ab_until(ctx, -1, save_until_final_response, -1, respond_to_extension);
147 
148   /* Client events:
149      nua_method(), nua_r_method
150   */
151   TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_method);
152   TEST(e->data->e_status, 200);
153   TEST_1(sip = sip_object(e->data->e_msg));
154   TEST_1(!e->next);
155 
156   /*
157    Server events:
158    nua_i_method
159   */
160   TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_i_method);
161   TEST(e->data->e_status, 100);
162   TEST_1(!e->next);
163 
164   free_events_in_list(ctx, a->events);
165   nua_handle_destroy(a_call->nh), a_call->nh = NULL;
166 
167   free_events_in_list(ctx, b->events);
168   nua_handle_destroy(b_call->nh), b_call->nh = NULL;
169 
170   nua_set_params(b->nua,
171 		 SIPTAG_ALLOW(b->allow),
172 		 NUTAG_APPL_METHOD(NULL),
173 		 NUTAG_APPL_METHOD(b->appl_method),
174 		 TAG_END());
175   run_b_until(ctx, nua_r_set_params, until_final_response);
176 
177   if (print_headings)
178     printf("TEST NUA-13.1: PASSED\n");
179   END();
180 }
181