Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
wap_events.c
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2008 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Kannel Group (http://www.kannel.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  * endorse or promote products derived from this software without
29  * prior written permission. For written permission, please
30  * contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  * nor may "Kannel" appear in their name, without prior written
34  * permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group. For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 /*
58  * wap_events.c - functions for manipulating wapbox events
59  *
60  * Aarno Syvšnen
61  * Lars Wirzenius
62  * Nikos Balkanas, Inaccess Networks (2009)
63  */
64 
65 
66 #include "gwlib/gwlib.h"
67 #include "wsp_caps.h"
68 #include "wap_events.h"
69 #include "wtls_pdu.h"
70 
72  const char *func) {
73  WAPEvent *event;
74 
75  gw_assert(type >= 0);
76  gw_assert(type < WAPEventNameCount);
77 
78  event = gw_malloc_trace(sizeof(WAPEvent), file, line, func);
79  event->type = type;
80 
81  switch (event->type) {
82  #define WAPEVENT(name, prettyname, fields) \
83  case name: \
84  { struct name *p = &event->u.name; fields } \
85  break;
86  #define OCTSTR(name) p->name = NULL;
87  #define OPTIONAL_OCTSTR(name) p->name = NULL;
88  #define INTEGER(name) p->name = 0;
89  #define WTLSPDUS(name) p->name = NULL;
90  #define HTTPHEADER(name) p->name = NULL;
91  #define ADDRTUPLE(name) p->name = NULL;
92  #define CAPABILITIES(name) p->name = NULL;
93  #include "wap_events.def"
94  default:
95  panic(0, "Unknown WAP event type %d", event->type);
96  }
97 
98  return event;
99 }
100 
101 
103  if (event == NULL)
104  return;
105 
106  wap_event_assert(event);
107 
108  switch (event->type) {
109  #define WAPEVENT(name, prettyname, fields) \
110  case name: \
111  { struct name *p = &event->u.name; fields; } \
112  break;
113  #define OCTSTR(name) octstr_destroy(p->name);
114  #define OPTIONAL_OCTSTR(name) octstr_destroy(p->name);
115  #define INTEGER(name) p->name = 0;
116 #ifdef HAVE_WTLS_OPENSSL
117  #define WTLSPDUS(name) wtls_pldList_destroy(p->name);
118 #endif /* HAVE_WTLS_OPENSSL */
119  #define HTTPHEADER(name) http_destroy_headers(p->name);
120  #define ADDRTUPLE(name) wap_addr_tuple_destroy(p->name);
121  #define CAPABILITIES(name) wsp_cap_destroy_list(p->name);
122  #include "wap_events.def"
123  default:
124  panic(0, "Unknown WAPEvent type %d", (int) event->type);
125  }
126  gw_free(event);
127 }
128 
129 
130 void wap_event_destroy_item(void *event) {
131  wap_event_destroy(event);
132 }
133 
134 
136  WAPEvent *new;
137 
138  if (event == NULL)
139  return NULL;
140 
141  wap_event_assert(event);
142 
143  new = gw_malloc(sizeof(WAPEvent));
144  new->type = event->type;
145 
146  switch (event->type) {
147  #define WAPEVENT(name, prettyname, fields) \
148  case name: \
149  { struct name *p = &new->u.name; \
150  struct name *q = &event->u.name; \
151  fields } \
152  break;
153  #define OCTSTR(name) p->name = octstr_duplicate(q->name);
154  #define OPTIONAL_OCTSTR(name) p->name = octstr_duplicate(q->name);
155  #define INTEGER(name) p->name = q->name;
156  #define WTLSPDUS(name) debug("wap.events",0,"You need to implement wtls_pdulist_duplicate!");
157  #define HTTPHEADER(name) p->name = http_header_duplicate(q->name);
158  #define ADDRTUPLE(name) p->name = wap_addr_tuple_duplicate(q->name);
159  #define CAPABILITIES(name) p->name = wsp_cap_duplicate_list(q->name);
160  #include "wap_events.def"
161  default:
162  panic(0, "Unknown WAP event type %d", event->type);
163  }
164 
165  return new;
166 }
167 
168 
170  switch (type) {
171  #define WAPEVENT(name, prettyname, fields) \
172  case name: return prettyname;
173  #include "wap_events.def"
174  default:
175  panic(0, "Unknown WAPEvent type %d", (int) type);
176  return "unknown WAPEventName";
177  }
178 }
179 
180 
181 void wap_event_dump(WAPEvent *event) {
182  debug("wap.event", 0, "Dumping WAPEvent %p", (void *) event);
183  if (event != NULL) {
184  debug("wap.event", 0, " type = %s",
185  wap_event_name(event->type));
186  switch (event->type) {
187  #define WAPEVENT(name, prettyname, fields) \
188  case name: \
189  { struct name *p = &event->u.name; fields; break; }
190  #define OCTSTR(name) \
191  debug("wap.event", 0, "%s =", #name); \
192  octstr_dump(p->name, 1);
193  #define OPTIONAL_OCTSTR(name) \
194  if (p->name == NULL) \
195  debug("wap.event", 0, "%s = NULL", #name); \
196  else { \
197  debug("wap.event", 0, "%s =", #name); \
198  octstr_dump(p->name, 1); \
199  }
200  #define INTEGER(name) \
201  debug("wap.event", 0, " %s = %ld", #name, p->name);
202  #define WTLSPDUS(name) \
203  debug("wap.event",0,"You need to implement wtls_payloadlist_dump!");
204  #define HTTPHEADER(name) \
205  if (p->name == NULL) \
206  debug("wap.event", 0, "%s = NULL", #name); \
207  else \
208  http_header_dump(p->name);
209  #define ADDRTUPLE(name) wap_addr_tuple_dump(p->name);
210  #define CAPABILITIES(name) wsp_cap_dump_list(p->name);
211  #include "wap_events.def"
212  default:
213  debug("wap.event", 0, "Unknown type");
214  }
215  }
216  debug("wap.event", 0, "WAPEvent dump ends.");
217 }
218 
219 
221  gw_assert(event != NULL),
222  gw_assert(event->type >= 0);
223  gw_assert(event->type < WAPEventNameCount);
224 
225  switch (event->type) {
226 #define WAPEVENT(name, prettyname, fields) \
227  case name: \
228  { struct name *p = &event->u.name; fields; p = NULL; break; }
229 #define OCTSTR(name) \
230  gw_assert(p->name != NULL); \
231  /* This is a trick to make the Octstr module run its assertions */ \
232  gw_assert(octstr_len(p->name) >= 0);
233 #define OPTIONAL_OCTSTR(name) \
234  gw_assert(p->name == NULL || octstr_len(p->name) >= 0);
235 #define INTEGER(name)
236 #define WTLSPDUS(name)
237 #define HTTPHEADER(name)
238 #define ADDRTUPLE(name) \
239  gw_assert(p->name != NULL);
240 #define CAPABILITIES(name)
241 #include "wap_events.def"
242  default:
243  debug("wap.event", 0, "Unknown type");
244  }
245 }
int type
Definition: smsc_cimd2.c:215
void wap_event_dump(WAPEvent *event)
Definition: wap_events.c:181
FILE * file
Definition: log.c:133
WAPEventName
Definition: wap_events.h:77
void wap_event_assert(WAPEvent *event)
Definition: wap_events.c:220
void wap_event_destroy_item(void *event)
Definition: wap_events.c:130
const char * wap_event_name(WAPEventName type)
Definition: wap_events.c:169
gw_assert(wtls_machine->packet_to_send!=NULL)
WAPEvent * wap_event_duplicate(WAPEvent *event)
Definition: wap_events.c:135
WAPEvent * wap_event_create_real(WAPEventName type, const char *file, long line, const char *func)
Definition: wap_events.c:71
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
#define panic
Definition: log.h:87
WAPEventName type
Definition: wap_events.h:88
void wap_event_destroy(WAPEvent *event)
Definition: wap_events.c:102
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.