Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

msg.c File Reference

#include <errno.h>
#include <stdlib.h>
#include <sys/types.h>
#include <netinet/in.h>
#include "msg.h"
#include "gwlib/gwlib.h"
#include "msg-decl.h"

Include dependency graph for msg.c:

Include dependency graph

Go to the source code of this file.

Defines

#define INTEGER(name)   p->name = MSG_PARAM_UNDEFINED
#define OCTSTR(name)   p->name = NULL
#define UUID(name)   uuid_generate(p->name)
#define VOID(name)   p->name = NULL
#define MSG(type, stmt)   { struct type *p = &msg->type; stmt }
#define INTEGER(name)   p->name = q->name
#define OCTSTR(name)
#define UUID(name)   uuid_copy(p->name, q->name)
#define VOID(name)   p->name = q->name
#define MSG(type, stmt)
#define INTEGER(name)   p->name = 0
#define OCTSTR(name)   octstr_destroy(p->name)
#define UUID(name)   uuid_clear(p->name)
#define VOID(name)
#define MSG(type, stmt)   { struct type *p = &msg->type; stmt }
#define INTEGER(name)   debug("gw.msg", 0, "%*s %s.%s: %ld", level, "", t, #name, (long) p->name)
#define OCTSTR(name)
#define UUID(name)
#define VOID(name)   debug("gw.msg", 0, "%*s %s.%s: %p", level, "", t, #name, p->name)
#define MSG(tt, stmt)
#define INTEGER(name)   append_integer(os, p->name)
#define OCTSTR(name)   append_string(os, p->name)
#define UUID(name)   append_uuid(os, p->name)
#define VOID(name)
#define MSG(type, stmt)   case type: { struct type *p = &msg->type; stmt } break;
#define INTEGER(name)   if (parse_integer(&(p->name), os, &off) == -1) goto error
#define OCTSTR(name)   if (parse_string(&(p->name), os, &off) == -1) goto error
#define UUID(name)   if (parse_uuid(p->name, os, &off) == -1) goto error
#define VOID(name)
#define MSG(type, stmt)   case type: { struct type *p = &(msg->type); stmt } break;
#define MSG(t, stmt)   case t: return #t;

Functions

void append_integer (Octstr *os, long i)
void append_string (Octstr *os, Octstr *field)
void append_uuid (Octstr *os, uuid_t id)
int parse_integer (long *i, Octstr *packed, int *off)
int parse_string (Octstr **os, Octstr *packed, int *off)
int parse_uuid (uuid_t id, Octstr *packed, int *off)
char * type_as_str (Msg *msg)
Msgmsg_create_real (enum msg_type type, const char *file, long line, const char *func)
Msgmsg_duplicate (Msg *msg)
void msg_destroy (Msg *msg)
void msg_destroy_item (void *msg)
void msg_dump (Msg *msg, int level)
enum msg_type msg_type (Msg *msg)
Octstrmsg_pack (Msg *msg)
Msgmsg_unpack_real (Octstr *os, const char *file, long line, const char *func)
Msgmsg_unpack_wrapper (Octstr *os)


Define Documentation

#define INTEGER name   )     if (parse_integer(&(p->name), os, &off) == -1) goto error
 

#define INTEGER name   )     append_integer(os, p->name)
 

#define INTEGER name   )     debug("gw.msg", 0, "%*s %s.%s: %ld", level, "", t, #name, (long) p->name)
 

#define INTEGER name   )     p->name = 0
 

#define INTEGER name   )     p->name = q->name
 

#define INTEGER name   )     p->name = MSG_PARAM_UNDEFINED
 

#define MSG t,
stmt   )     case t: return #t;
 

#define MSG type,
stmt   )     case type: { struct type *p = &(msg->type); stmt } break;
 

#define MSG type,
stmt   )     case type: { struct type *p = &msg->type; stmt } break;
 

#define MSG tt,
stmt   ) 
 

Value:

if (tt == msg->type) \
        { char *t = #tt; struct tt *p = &msg->tt; stmt }

#define MSG type,
stmt   )     { struct type *p = &msg->type; stmt }
 

#define MSG type,
stmt   ) 
 

Value:

{ \
    struct type *p = &new->type; \
    struct type *q = &msg->type; \
    stmt }

#define MSG type,
stmt   )     { struct type *p = &msg->type; stmt }
 

#define OCTSTR name   )     if (parse_string(&(p->name), os, &off) == -1) goto error
 

#define OCTSTR name   )     append_string(os, p->name)
 

#define OCTSTR name   ) 
 

Value:

debug("gw.msg", 0, "%*s %s.%s:", level, "", t, #name); \
    octstr_dump(p->name, level + 1)

#define OCTSTR name   )     octstr_destroy(p->name)
 

#define OCTSTR name   ) 
 

Value:

if (q->name == NULL) p->name = NULL; \
    else p->name = octstr_duplicate(q->name);

#define OCTSTR name   )     p->name = NULL
 

#define UUID name   )     if (parse_uuid(p->name, os, &off) == -1) goto error
 

#define UUID name   )     append_uuid(os, p->name)
 

#define UUID name   ) 
 

Value:

uuid_unparse(p->name, buf); \
    debug("gw.msg", 0 , "%*s %s.%s: %s", level, "", t, #name, buf)

#define UUID name   )     uuid_clear(p->name)
 

#define UUID name   )     uuid_copy(p->name, q->name)
 

#define UUID name   )     uuid_generate(p->name)
 

#define VOID name   ) 
 

#define VOID name   ) 
 

#define VOID name   )     debug("gw.msg", 0, "%*s %s.%s: %p", level, "", t, #name, p->name)
 

#define VOID name   ) 
 

#define VOID name   )     p->name = q->name
 

#define VOID name   )     p->name = NULL
 


Function Documentation

void append_integer Octstr os,
long  i
[static]
 

Definition at line 264 of file msg.c.

References encode_network_long(), and octstr_append_data().

Referenced by append_string(), append_uuid(), and msg_pack().

00265 {
00266     unsigned char buf[4];
00267 
00268     encode_network_long(buf, i);
00269     octstr_append_data(os, (char *)buf, 4);
00270 }

Here is the call graph for this function:

void append_string Octstr os,
Octstr field
[static]
 

Definition at line 272 of file msg.c.

References append_integer(), octstr_insert(), and octstr_len().

00273 {
00274     if (field == NULL)
00275         append_integer(os, -1);
00276     else {
00277         append_integer(os, octstr_len(field));
00278         octstr_insert(os, field, octstr_len(os));
00279     }
00280 }

Here is the call graph for this function:

void append_uuid Octstr os,
uuid_t  id
[static]
 

Definition at line 282 of file msg.c.

References append_integer(), octstr_append_cstr(), UUID_STR_LEN, and uuid_unparse().

00283 {
00284     char buf[UUID_STR_LEN + 1];
00285 
00286     uuid_unparse(id, buf);
00287     append_integer(os, UUID_STR_LEN);
00288     octstr_append_cstr(os, buf);
00289 }

Here is the call graph for this function:

Msg* msg_create_real enum msg_type  type,
const char *  file,
long  line,
const char *  func
 

Definition at line 93 of file msg.c.

References file.

Referenced by msg_unpack_real().

00095 {
00096     Msg *msg;
00097 
00098     msg = gw_malloc_trace(sizeof(Msg), file, line, func);
00099 
00100     msg->type = type;
00101 #define INTEGER(name) p->name = MSG_PARAM_UNDEFINED
00102 #define OCTSTR(name) p->name = NULL
00103 #define UUID(name) uuid_generate(p->name)
00104 #define VOID(name) p->name = NULL
00105 #define MSG(type, stmt) { struct type *p = &msg->type; stmt }
00106 #include "msg-decl.h"
00107 
00108     return msg;
00109 }

void msg_destroy Msg msg  ) 
 

Definition at line 132 of file msg.c.

Referenced by bb_smscconn_receive(), bb_smscconn_send_failed(), bb_smscconn_sent(), boxc_receiver(), boxc_sender(), boxc_sent_pop(), check_concatenation(), cimd2_accept_message(), clear_old_concat_parts(), data_sm_to_msg(), deliver_sms_to_queue(), deliver_to_bearerbox_real(), destroy_concatMsg(), dispatch_datagram(), emi_receive_msg(), empty_msg_lists(), handle_pdu(), handle_split(), http_queue_thread(), main(), main_connection_loop(), msg_destroy_item(), msg_to_bb(), msg_unpack_real(), obey_request_thread(), ois_deliver_sm_invoke(), oisd_accept_message(), pdu_to_msg(), read_messages_from_bearerbox(), run_batch(), run_requests(), send_message(), send_pdu(), smpp_msg_destroy(), sms_receive(), sms_router(), sms_split(), smsbox_req_handle(), smsbox_req_sendota(), smsbox_sendota_post(), smsbox_thread(), smsc2_rout(), status_cb(), store_file_load(), store_file_save_ack(), store_spool_save_ack(), store_to_dict(), udp_sender(), url_result_thread(), wdp_to_wapboxes(), wrapper_sender(), and write_to_bearerbox_real().

00133 {
00134     if (msg == NULL)
00135         return;
00136 
00137 #define INTEGER(name) p->name = 0
00138 #define OCTSTR(name) octstr_destroy(p->name)
00139 #define UUID(name) uuid_clear(p->name)
00140 #define VOID(name)
00141 #define MSG(type, stmt) { struct type *p = &msg->type; stmt }
00142 #include "msg-decl.h"
00143 
00144     gw_free(msg);
00145 }

void msg_destroy_item void *  msg  ) 
 

Definition at line 147 of file msg.c.

References msg_destroy().

Referenced by cimd2_destroy(), empty_msg_lists(), oisd_destroy(), smasi_destroy(), smpp_destroy(), smscconn_send(), and store_file_init().

00148 {
00149     msg_destroy(msg);
00150 }

Here is the call graph for this function:

void msg_dump Msg msg,
int  level
 

Definition at line 152 of file msg.c.

References debug(), type_as_str(), and UUID_STR_LEN.

Referenced by boxc_sent_pop(), check_concatenation(), dump(), handle_pdu(), main(), obey_request_thread(), print_msg(), and store_file_load().

00153 {
00154     char buf[UUID_STR_LEN + 1];
00155 
00156     debug("gw.msg", 0, "%*sMsg object at %p:", level, "", (void *) msg);
00157     debug("gw.msg", 0, "%*s type: %s", level, "", type_as_str(msg));
00158 #define INTEGER(name) \
00159     debug("gw.msg", 0, "%*s %s.%s: %ld", level, "", t, #name, (long) p->name)
00160 #define OCTSTR(name) \
00161     debug("gw.msg", 0, "%*s %s.%s:", level, "", t, #name); \
00162     octstr_dump(p->name, level + 1)
00163 #define UUID(name) \
00164     uuid_unparse(p->name, buf); \
00165     debug("gw.msg", 0 , "%*s %s.%s: %s", level, "", t, #name, buf)
00166 #define VOID(name) \
00167      debug("gw.msg", 0, "%*s %s.%s: %p", level, "", t, #name, p->name)
00168 #define MSG(tt, stmt) \
00169     if (tt == msg->type) \
00170         { char *t = #tt; struct tt *p = &msg->tt; stmt }
00171 #include "msg-decl.h"
00172     debug("gw.msg", 0, "Msg object ends.");
00173 }

Here is the call graph for this function:

Msg* msg_duplicate Msg msg  ) 
 

Definition at line 111 of file msg.c.

References msg_create.

Referenced by add_msg_cb(), at2_add_msg_cb(), bb_smscconn_receive(), boxc_sent_push(), cgw_add_msg_cb(), check_concatenation(), cimd2_add_msg_cb(), clear_old_concat_parts(), httpsmsc_send(), main(), main_connection_loop(), oisd_add_msg_cb(), send_message(), send_msg_cb(), sms_split(), smsc2_rout(), smscconn_send(), soap_add_msg_cb(), store_to_dict(), wrapper_add_msg(), and wrapper_sender().

00112 {
00113     Msg *new;
00114 
00115     new = msg_create(msg->type);
00116 
00117 #define INTEGER(name) p->name = q->name
00118 #define OCTSTR(name) \
00119     if (q->name == NULL) p->name = NULL; \
00120     else p->name = octstr_duplicate(q->name);
00121 #define UUID(name) uuid_copy(p->name, q->name)
00122 #define VOID(name) p->name = q->name
00123 #define MSG(type, stmt) { \
00124     struct type *p = &new->type; \
00125     struct type *q = &msg->type; \
00126     stmt }
00127 #include "msg-decl.h"
00128 
00129     return new;
00130 }

Octstr* msg_pack Msg msg  ) 
 

Definition at line 181 of file msg.c.

References append_integer(), octstr_create, and panic.

Referenced by deliver_to_bearerbox_real(), init_bearerbox(), main(), send_msg(), send_pdu(), smsbox_thread(), and write_to_bearerbox_real().

00182 {
00183     Octstr *os;
00184 
00185     os = octstr_create("");
00186     append_integer(os, msg->type);
00187 
00188 #define INTEGER(name) append_integer(os, p->name)
00189 #define OCTSTR(name) append_string(os, p->name)
00190 #define UUID(name) append_uuid(os, p->name)
00191 #define VOID(name)
00192 #define MSG(type, stmt) \
00193     case type: { struct type *p = &msg->type; stmt } break;
00194 
00195     switch (msg->type) {
00196 #include "msg-decl.h"
00197     default:
00198         panic(0, "Internal error: unknown message type %d",
00199               msg->type);
00200     }
00201 
00202     return os;
00203 }

Here is the call graph for this function:

enum msg_type msg_type Msg msg  ) 
 

Definition at line 176 of file msg.c.

References msg_type().

Referenced by msg_type().

00177 {
00178     return msg->type;
00179 }

Here is the call graph for this function:

Msg* msg_unpack_real Octstr os,
const char *  file,
long  line,
const char *  func
 

Definition at line 206 of file msg.c.

References error(), file, msg_create_real(), msg_destroy(), panic, and parse_integer().

00207 {
00208     Msg *msg;
00209     int off;
00210     long i;
00211 
00212     msg = msg_create_real(0, file, line, func);
00213     if (msg == NULL)
00214         goto error;
00215 
00216     off = 0;
00217 
00218     if (parse_integer(&i, os, &off) == -1)
00219         goto error;
00220     msg->type = i;
00221 
00222 #define INTEGER(name) \
00223     if (parse_integer(&(p->name), os, &off) == -1) goto error
00224 #define OCTSTR(name) \
00225     if (parse_string(&(p->name), os, &off) == -1) goto error
00226 #define UUID(name) \
00227     if (parse_uuid(p->name, os, &off) == -1) goto error
00228 #define VOID(name)
00229 #define MSG(type, stmt) \
00230     case type: { struct type *p = &(msg->type); stmt } break;
00231 
00232     switch (msg->type) {
00233 #include "msg-decl.h"
00234     default:
00235         panic(0, "Internal error: unknown message type: %d",
00236               msg->type);
00237     }
00238 
00239     return msg;
00240 
00241 error:
00242     if (msg != NULL) msg_destroy(msg);
00243     error(0, "Msg packet was invalid.");
00244     return NULL;
00245 }

Here is the call graph for this function:

Msg* msg_unpack_wrapper Octstr os  )  [inline]
 

Definition at line 253 of file msg.c.

References msg_unpack.

Referenced by init_bearerbox(), and main().

00254 {
00255     return msg_unpack(os);
00256 }

int parse_integer long *  i,
Octstr packed,
int *  off
[static]
 

Definition at line 291 of file msg.c.

References decode_network_long(), error(), gw_assert, octstr_get_many_chars(), and octstr_len().

Referenced by msg_unpack_real(), and parse_string().

00292 {
00293     unsigned char buf[4];
00294 
00295     gw_assert(*off >= 0);
00296     if (*off + 4 > octstr_len(packed)) {
00297         error(0, "Packet too short while unpacking Msg.");
00298         return -1;
00299     }
00300 
00301     octstr_get_many_chars((char *)buf, packed, *off, 4);
00302     *i = decode_network_long(buf);
00303     *off += 4;
00304     return 0;
00305 }

Here is the call graph for this function:

int parse_string Octstr **  os,
Octstr packed,
int *  off
[static]
 

Definition at line 308 of file msg.c.

References octstr_copy, and parse_integer().

Referenced by parse_uuid().

00309 {
00310     long len;
00311 
00312     if (parse_integer(&len, packed, off) == -1)
00313         return -1;
00314 
00315     if (len == -1) {
00316         *os = NULL;
00317         return 0;
00318     }
00319 
00320     /* XXX check that len is ok */
00321 
00322     *os = octstr_copy(packed, *off, len);
00323     if (*os == NULL)
00324         return -1;
00325     *off += len;
00326 
00327     return 0;
00328 }

Here is the call graph for this function:

int parse_uuid uuid_t  id,
Octstr packed,
int *  off
[static]
 

Definition at line 331 of file msg.c.

References octstr_destroy(), octstr_get_cstr, parse_string(), and uuid_parse().

00332 {
00333    Octstr *tmp = NULL;
00334 
00335    if (parse_string(&tmp, packed, off) == -1) {
00336        octstr_destroy(tmp);
00337        return -1;
00338    }
00339 
00340    if (uuid_parse(octstr_get_cstr(tmp), id) == -1) {
00341        octstr_destroy(tmp);
00342        return -1;
00343    }
00344 
00345    octstr_destroy(tmp);
00346 
00347    return 0;
00348 }

Here is the call graph for this function:

char * type_as_str Msg msg  )  [static]
 

Definition at line 350 of file msg.c.

Referenced by msg_dump().

00351 {
00352     switch (msg->type) {
00353 #define MSG(t, stmt) case t: return #t;
00354 #include "msg-decl.h"
00355     default:
00356         return "unknown type";
00357     }
00358 }

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.