Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
test_pdu.c File Reference
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "gwlib/gwlib.h"
#include "wap/wtp_pdu.h"
#include "wap/wsp_pdu.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 71 of file test_pdu.c.

References debug(), error(), gwlib_init(), gwlib_shutdown(), octstr_compare(), octstr_destroy(), octstr_dump, octstr_duplicate, octstr_read_file(), wtp_pdu::type, wtp_pdu::u, warning(), wsp_pdu_destroy(), wsp_pdu_dump(), wsp_pdu_pack(), wsp_pdu_unpack(), wtp_pdu_destroy(), wtp_pdu_dump(), wtp_pdu_pack(), and wtp_pdu_unpack().

71  {
72  int i;
73  Octstr *packet = NULL;
74  Octstr *newpacket = NULL;
75  WTP_PDU *pdu = NULL;
76  Octstr *wsp_data = NULL;
77  WSP_PDU *wsp = NULL;
78 
79  gwlib_init();
80 
81  for (i = 1; i < argc; i++) {
82  octstr_destroy(packet); packet = NULL;
83  octstr_destroy(newpacket); newpacket = NULL;
84  octstr_destroy(wsp_data); wsp_data = NULL;
85  wtp_pdu_destroy(pdu); pdu = NULL;
86  wsp_pdu_destroy(wsp); wsp = NULL;
87 
88  packet = octstr_read_file(argv[i]);
89  pdu = wtp_pdu_unpack(packet);
90  if (!pdu) {
91  warning(0, "Unpacking PDU %s failed", argv[i]);
92  continue;
93  }
94  debug("test", 0, "PDU %s:", argv[i]);
95  wtp_pdu_dump(pdu, 0);
96  newpacket = wtp_pdu_pack(pdu);
97  if (!newpacket) {
98  warning(0, "Repacking PDU %s failed", argv[i]);
99  continue;
100  }
101  if (octstr_compare(packet, newpacket) != 0) {
102  error(0, "Repacking PDU %s changed it", argv[i]);
103  debug("test", 0, "Original:");
104  octstr_dump(packet, 1);
105  debug("test", 0, "New:");
106  octstr_dump(newpacket, 1);
107  continue;
108  }
109  if (pdu->type == Invoke) {
110  wsp_data = pdu->u.Invoke.user_data;
111  } else if (pdu->type == Result) {
112  wsp_data = pdu->u.Result.user_data;
113  } else {
114  continue;
115  }
116  wsp_data = octstr_duplicate(wsp_data);
117 
118  wsp = wsp_pdu_unpack(wsp_data);
119  if (!wsp) {
120  warning(0, "Unpacking WSP data in %s failed", argv[i]);
121  continue;
122  }
123  wsp_pdu_dump(wsp, 0);
124  octstr_destroy(newpacket);
125  newpacket = wsp_pdu_pack(wsp);
126  if (!newpacket) {
127  warning(0, "Repacking WSP data in %s failed", argv[i]);
128  continue;
129  }
130  if (octstr_compare(wsp_data, newpacket) != 0) {
131  error(0, "Repacking WSP data in %s changed it",
132  argv[i]);
133  debug("test", 0, "Original:");
134  octstr_dump(wsp_data, 1);
135  debug("test", 0, "New:");
136  octstr_dump(newpacket, 1);
137  continue;
138  }
139  }
140 
141  octstr_destroy(packet);
142  octstr_destroy(newpacket);
143  wtp_pdu_destroy(pdu);
144 
145  gwlib_shutdown();
146  return 0;
147 }
void error(int err, const char *fmt,...)
Definition: log.c:612
int type
Definition: wtp_pdu.h:84
Octstr * wsp_pdu_pack(WSP_PDU *pdu)
Definition: wsp_pdu.c:271
void wtp_pdu_dump(WTP_PDU *pdu, int level)
Definition: wtp_pdu.c:446
union wtp_pdu::@107 u
#define octstr_duplicate(ostr)
Definition: octstr.h:187
#define octstr_dump(ostr, level,...)
Definition: octstr.h:564
WTP_PDU * wtp_pdu_unpack(Octstr *data)
Definition: wtp_pdu.c:284
void warning(int err, const char *fmt,...)
Definition: log.c:624
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
void wsp_pdu_destroy(WSP_PDU *pdu)
Definition: wsp_pdu.c:102
Octstr * octstr_read_file(const char *filename)
Definition: octstr.c:1546
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
void gwlib_shutdown(void)
Definition: gwlib.c:94
Octstr * wtp_pdu_pack(WTP_PDU *pdu)
Definition: wtp_pdu.c:388
void wtp_pdu_destroy(WTP_PDU *pdu)
Definition: wtp_pdu.c:104
void wsp_pdu_dump(WSP_PDU *pdu, int level)
Definition: wsp_pdu.c:324
void gwlib_init(void)
Definition: gwlib.c:78
WSP_PDU * wsp_pdu_unpack(Octstr *data)
Definition: wsp_pdu.c:178
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:869
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.