88 #include <libxml/xmlmemory.h>    89 #include <libxml/parser.h>    90 #include <libxml/tree.h>    91 #include <libxml/debugXML.h>    92 #include <libxml/encoding.h>   108     "quality-of-service",
   115     "resultnotification-message",
   116     "resultnotification-response",
   117     "statusquery-message",
   118     "statusquery-response",
   119     "statusquery-result",
   122     "badmessage-response"   125 #define NUM_ELEMENTS sizeof(pap_elements)/sizeof(pap_elements[0])   138     { 
"product-name", NULL },
   140     { 
"deliver-before-timestamp", NULL },
   141     { 
"deliver-after-timestamp", NULL },
   142     { 
"source-reference", NULL },
   143     { 
"progress-notes-requested", 
"true" },
   144     { 
"progress-notes-requested", 
"false" },
   145     { 
"ppg-notify-requested-to", NULL },
   146     { 
"address-value", NULL },
   147     { 
"priority", 
"high" },
   148     { 
"priority", 
"medium" },
   149     { 
"priority", 
"low" },
   150     { 
"delivery-method", 
"confirmed" },
   151     { 
"delivery-method", 
"preferconfirmed" },
   152     { 
"delivery-method", 
"unconfirmed" },
   153     { 
"delivery-method", 
"notspecified" },
   155     { 
"network-required", 
"true" },
   156     { 
"network-required", 
"false" },
   158     { 
"bearer-required", 
"true" },
   159     { 
"bearer-required", 
"false" },
   160     { 
"sender-address", NULL },
   161     { 
"sender-name", NULL },
   162     { 
"reply-time", NULL },
   168     { 
"received-time", NULL },
   169     { 
"event-time", NULL },
   170     { 
"message-state", NULL },
   171     { 
"query-id", NULL },
   173     { 
"bad-message-fragment", NULL}
   176 #define NUM_ATTRIBUTES sizeof(pap_attributes)/sizeof(pap_attributes[0])   193 #define NUM_CODES sizeof(pap_codes)/sizeof(pap_codes[0])   214 #define NUM_BEARER_TYPES sizeof(pap_bearer_types)/sizeof(pap_bearer_types[0])   234 #define NUM_NETWORK_TYPES sizeof(pap_network_types)/ \   235                           sizeof(pap_network_types[0])   246                          long *type_of_address, 
int *is_any); 
   248                            WAPEvent **e, 
long *type_of_address, 
int *is_any);
   251                             long *type_of_address, 
int *is_any);
   260                                WAPEvent **e, 
long *type_of_address);
   280                                          long *type_of_address);
   283                                    long *type_of_address);
   307     unsigned char comma, 
unsigned char point, 
unsigned char c, 
   308     long fragment_parsed, 
long fragment_length);
   324 #ifdef XML_USE_BUFFER_CONTENT   325 #define create_octstr_from_node(node) (octstr_create(node->content->content))   327 #define create_octstr_from_node(node) (octstr_create(node->content))   357         warning(0, 
"PAP COMPILER: pap_compile: pap source contained a \\0"   383     warning(0, 
"PAP COMPILER: pap_compile: parse error in pap source");
   425     long type_of_address;
   428     node = xmlDocGetRootElement(doc_p);
   431     if ((ret = 
parse_node(node, e, &type_of_address, &is_any)) < 0)
   434     (*e)->u.Push_Message.address_type = type_of_address;
   437         warning(0, 
"wrong type of address for requested bearer");
   439     } 
else if (ret == -1) {
   440         info(0, 
"reverting to default bearer and network");
   445     if (!
set_anys(e, type_of_address, is_any)) {
   446         warning(0, 
"unable to handle any values in qos");
   449         debug(
"wap.push.pap.compiler", 0, 
"using defaults instead of anys");
   496     if ((*e)->type != Push_Message)
   499     (*e)->u.Push_Message.bearer_required = 
PAP_TRUE;
   502     switch (type_of_address) {
   522     if ((*e)->type != Push_Message)
   525     (*e)->u.Push_Message.network_required = 
PAP_TRUE;
   528     switch (type_of_address) {
   544     switch(type_of_address) {
   546     return "user defined address";
   548     return "a phone number";
   550     return "a IPv4 address";
   552     return "a IPv6 address";
   554     return "a WINA accepted address";
   556     return "unknown address";
   573     debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: doing semantic analysis"   575     if (e->
type != Push_Message) {
   579     if (e->
u.Push_Message.network_required != 
   580          e->
u.Push_Message.bearer_required) {
   581        debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: network-required and"   582              " bearer-required must have same value");
   588                      e->
u.Push_Message.bearer_required,
   589                      e->
u.Push_Message.bearer)) == 0) {
   590                 debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: bearer does"   591                       " not accept PLMN address");
   593             } 
else if (ret == -1) {
   594             debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: network or"   595                       "bearer missing, reverting to GSM+SMS");
   604                     e->
u.Push_Message.bearer)) == 0) {
   605                 debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: bearer does"   606                       " not accept IPv4 address");
   608             } 
else if (ret == -1) {
   609                 debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: network or"   610                       " bearer missing, reverting to GSM+CSD");
   618                  e->
u.Push_Message.bearer)) == 0) {
   619              debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: network or"   620                    " bearer does not accept IPv6 address");
   622         } 
else if (ret == -1) {
   623              debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: network or"   624                    " bearer missing, reverting Any+Any");
   642 #define NUMBER_OF_IP6_BEARERS sizeof(ip6_bearers)/sizeof(ip6_bearers[0])   652 #define NUMBER_OF_IP4_BEARERS sizeof(ip4_bearers)/sizeof(ip4_bearers[0])   663     if (!bearer_required)
   684     if (!bearer_required) {
   713     if (!bearer_required)
   749     switch (node->type) {
   750     case XML_COMMENT_NODE:        
   755     case XML_ELEMENT_NODE:
   756         if ((ret = 
parse_element(node, e, type_of_address, is_any)) < 0) {
   762         warning(0, 
"PAP COMPILER: parse_node: Unknown XML node in PAP source");
   766     if (node->children != NULL)
   767         if ((ret = 
parse_node(node->children, e, type_of_address, 
   772     if (node->next != NULL)
   773         if ((ret = 
parse_node(node->next, e, type_of_address, is_any)) < 0) {
   796     xmlAttrPtr attribute;
   803         debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: element name length"   816         debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: unknown element:");
   822     if (node->properties != NULL) {
   823         attribute = node->properties;
   824         while (attribute != NULL) {
   826                     type_of_address, is_any)) < 0) {
   830             attribute = attribute->next;
   857                            WAPEvent **e, 
long *type_of_address, 
int *is_any)
   866     if (attribute->children != NULL)
   880         debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: unknown attribute `%s' "   892                                type_of_address, is_any);
   909         debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: unknown attribute "   910               "value `%s' for attribute `%s' within XML entity `%s'", 
   961     debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: unknown pap"   983              octstr_imm(
"deliver-before-timestamp")) == 0) {
   984     (**e).u.Push_Message.deliver_before_timestamp = 
   989              octstr_imm(
"deliver-after-timestamp")) == 0) {
   990     (**e).u.Push_Message.deliver_after_timestamp = 
   999              octstr_imm(
"ppg-notify-requested-to")) == 0) {
  1000     (**e).u.Push_Message.ppg_notify_requested_to = 
  1005     debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: unknown push message"  1006           " element attribute");
  1020                                WAPEvent **e, 
long *type_of_address)
  1027     (**e).u.Push_Message.address_value = 
  1033     debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: unknown address element"  1046     (**e).u.Push_Message.network = (ros = 
parse_network(attr_value)) ? 
  1053     (**e).u.Push_Message.bearer = (ros = 
parse_bearer(attr_value)) ? 
  1059     debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: unknown quality of"  1060           " service attribute");
  1089          debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: problems with"  1095         debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: wrong any value");
  1116     (**e).u.Push_Response.reply_time = (ros = 
parse_date(attr_value)) ?
  1124     debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: unknown push response"  1125           " element attribute");
  1139         (**e).u.Progress_Note.stage = 
  1146     (**e).u.Progress_Note.time = (ros = 
parse_date(attr_value)) ?
  1151     debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: unknown progress note"  1152           " element attribute");
  1160     (**e).u.Bad_Message_Response.code = 
parse_code(attr_value);
  1167         (**e).u.Bad_Message_Response.bad_message_fragment = 
  1172     debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: unknown bad message"  1173           " response element attribute");
  1181     (**e).u.Push_Response.code = 
parse_code(attr_value);
  1188     debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: unknown response result"  1205         (**e).u.Push_Message.pi_push_id = 
octstr_format(
"%s", 
"erroneous");
  1206         (**e).u.Push_Message.address_value = 
octstr_format(
"%s", 
"erroneous");
  1210         (**e).u.Push_Response.pi_push_id = 
octstr_format(
"%s", 
"erroneous");
  1215             octstr_imm(
"badmessage-response")) == 0 && *e == NULL) {
  1244                             long *type_of_address, 
int *is_any)
  1247         debug(
"wap.push.pap.compiler", 0, 
"unknown value for an attribute");
  1294                           octstr_imm(
"progress-notes-requested")) == 0)
  1295             (**e).u.Push_Message.progress_notes_requested = 
  1304             (**e).u.Push_Message.priority = 
  1307             (**e).u.Push_Message.delivery_method = 
  1311             (**e).u.Push_Message.network_required = 
  1314             (**e).u.Push_Message.bearer_required = 
  1327     long attr_as_number;
  1340     warning(0, 
"PAP COMPILER: parse_code: no such return code, reversing to"  1358     return attr_as_number;
  1388     warning(0, 
"no such network");
  1397     long attr_as_number;
  1399     attr_as_number = -2;
  1405         warning(0, 
"in a requirement, value not a truth value");
  1407     return attr_as_number;
  1415     long attr_as_number;
  1417     attr_as_number = -2;
  1425         warning(0, 
"illegal priority");
  1427     return attr_as_number;
  1435     long attr_as_number;
  1437     attr_as_number = -2;
  1448         warning(0, 
"illegal delivery method");
  1450     return attr_as_number;
  1458     long attr_as_number;
  1460     attr_as_number = -2;
  1476          warning(0, 
"illegal ppg state");
  1478     return attr_as_number;
  1516             type_of_address)) == -2) {
  1517         warning(0, 
"illegal client address");
  1519     } 
else if (pos == -1) {
  1520         warning(0, 
"unimplemented feature");
  1524     info(0, 
"client address was <%s>, accepted", 
  1535                                          long *type_of_address)
  1588                                    long *type_of_address)
  1594     if ((pos = 
parse_type(address, &type_value, pos)) < 0) {
  1601         debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: constant TYPE"  1602               " missing from the client address");
  1608         goto not_implemented;
  1636         debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: wrong address type"  1637               " in the client address");
  1685     if (pos < 0 || i != 
size) {
  1686         debug(
"wap.push.pap.compiler", 0, 
"parse_constant: unparsable"  1687               " constant %s", field_name);
  1709         if (isalnum(c) || c == 
'-') {
  1758         debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: erroneous qualifiers"  1759               " in the client address");
  1777          if (!isdigit(c) && c != 
'-' && c != 
'.') {
  1778              debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: wrong separator"  1779                    " in a phone number (- and . allowed)");
  1787         debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER:a phone number must"  1805         debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: wrong separator in a"  1818         debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: missing separator at"  1819               " beginning of a client address (=)");
  1831         debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: wrong separator in a"  1844         debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: missing separator at"  1845               " beginning of a client address (=)");
  1886     debug(
"wap.push.pap.compiler", 0, 
"PAP COMPILER: a bearer not registered"  1907         if ((ret = 
issafe(address, pos)) == 1) {
  1910         } 
else if (ret == 0) {
  1986         if (c < 0x20 || (c > 0x2e && c < 0x30) || (c > 0x3c && c < 0x3e) ||
  2003         if (isalnum(c) || c == 
'-') {
  2026         debug(
"wap.push.pap.compiler", 0, 
"non-digit found in ip address,"  2027               " address unacceptable");
  2031     while (i <= 3 && ((c = 
octstr_get_char(*address, pos)) != 
'.' &&  c != 
'=')
  2037         debug(
"wap.push.pap.compiler", 0, 
"parse_ipv4_fragment: non-digit"  2038                   " in ipv4 address, address unacceptable");
  2064     while (i <= 4 && ((c = 
octstr_get_char(*address, pos)) != 
':' && c != 
'=')
  2107     for (i = 2; i > 0; i--) {
  2130     if ((isalnum(c) || c == 
'+' || c == 
'-' || c == 
'.' || c == 
'_') && 
  2150     for (i = 2; i > 0; i--) {
  2175     unsigned char comma, 
unsigned char point, 
unsigned char c, 
  2176     long fragment_parsed, 
long fragment_length)
  2178     if (fragment_parsed == fragment_length && c != 
comma && c != point)
 void error(int err, const char *fmt,...)
 
void info(int err, const char *fmt,...)
 
static long parse_type(Octstr **address, Octstr **type_value, long pos)
 
static int parse_state(Octstr *attr_value)
 
static Octstr * parse_bearer(Octstr *attr_value)
 
static void set_defaults(WAPEvent **e, long type_of_address)
 
static int parse_node(xmlNodePtr node, WAPEvent **e, long *type_of_address, int *is_any)
 
void octstr_convert_range(Octstr *ostr, long pos, long len, octstr_func_t map)
 
static int parse_attr_value(Octstr *element_name, Octstr *attr_name, Octstr *attr_value, WAPEvent **e, long *type_of_address, int *is_any)
 
static int parse_document(xmlDocPtr doc_p, WAPEvent **e)
 
gw_assert(wtls_machine->packet_to_send !=NULL)
 
static char * pap_network_types[]
 
static int parse_pap_value(Octstr *attr_name, Octstr *attr_value, WAPEvent **e)
 
static void set_bearer_defaults(WAPEvent **e, long type_of_address)
 
Octstr * parse_date(Octstr *date)
 
static int parse_bad_message_response_value(Octstr *attr_name, Octstr *attr_value, WAPEvent **e)
 
static int parse_requirement(Octstr *attr_value)
 
static void set_network_defaults(WAPEvent **e, long type_of_address)
 
static int uses_gsm_msisdn_address(long bearer_required, Octstr *bearer)
 
static char * pap_elements[]
 
static int parse_address_value(Octstr *attr_name, Octstr *attr_value, WAPEvent **e, long *type_of_address)
 
static long parse_ipv4(Octstr **address, long pos)
 
static char * ip4_bearers[]
 
static long parse_dom_fragment(Octstr **address, long pos)
 
static long accept_escaped(Octstr **address, long pos)
 
void octstr_strip_blanks(Octstr *text)
 
static long parse_ext_qualifiers(Octstr **address, long pos, Octstr *type_value)
 
static int parse_quality_of_service_value(Octstr *attr_name, Octstr *attr_value, WAPEvent **e, int *is_any)
 
#define octstr_get_cstr(ostr)
 
void wap_event_dump(WAPEvent *event)
 
static int parse_delivery_method(Octstr *attr_value)
 
long octstr_search_char(const Octstr *ostr, int ch, long pos)
 
#define NUMBER_OF_IP6_BEARERS
 
static int qualifiers(Octstr *address, long pos, Octstr *type)
 
static long parse_ppg_specifier(Octstr **address, long pos)
 
static int create_peek_window(Octstr **address, long *pos)
 
#define NUMBER_OF_IP4_BEARERS
 
static int wina_bearer_identifier(Octstr *type_value)
 
static int parse_code(Octstr *attr_value)
 
Octstr * octstr_imm(const char *cstr)
 
void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos)
 
static int uses_ipv4_address(long bearer_required, Octstr *bearer)
 
static int set_attribute_value(Octstr *element_name, Octstr *attr_value, Octstr *attr_name, WAPEvent **e)
 
static long handle_two_terminators(Octstr **address, long pos, unsigned char comma, unsigned char point, unsigned char c, long fragment_parsed, long fragment_length)
 
void wap_event_assert(WAPEvent *event)
 
static long parse_ipv4_fragment(Octstr **address, long pos)
 
void octstr_delete(Octstr *ostr1, long pos, long len)
 
static long parse_wappush_client_address(Octstr **address, long pos, long *type_of_address)
 
#define octstr_duplicate(ostr)
 
#define octstr_dump(ostr, level,...)
 
static void set_any_value(int *is_any, Octstr *attr_name, Octstr *attr_value)
 
static void wap_event_accept_or_create(Octstr *element_name, WAPEvent **e)
 
static int parse_priority(Octstr *attr_value)
 
int octstr_case_compare(const Octstr *os1, const Octstr *os2)
 
#define wap_event_create(type)
 
void warning(int err, const char *fmt,...)
 
static char * ip6_bearers[]
 
static Octstr * parse_network(Octstr *attr_value)
 
Octstr * octstr_format(const char *fmt,...)
 
void octstr_destroy(Octstr *ostr)
 
#define octstr_create(cstr)
 
int parse_address(Octstr **address, long *type_of_address)
 
static long parse_escaped_value(Octstr **address, long pos)
 
static long drop_character(Octstr **address, long pos)
 
static long parse_qualifier_value(Octstr **address, long pos)
 
static int event_semantically_valid(WAPEvent *e, long type_of_address)
 
static int parse_element(xmlNodePtr node, WAPEvent **e, long *type_of_address, int *is_any)
 
static long parse_global_phone_number(Octstr **address, long pos)
 
long octstr_len(const Octstr *ostr)
 
static long parse_ipv6(Octstr **address, long pos)
 
static int parse_push_message_value(Octstr *attr_name, Octstr *attr_value, WAPEvent **e)
 
static long parse_client_specifier(Octstr **address, long pos, long *type_of_address)
 
static Octstr * prepend_char(Octstr *address, unsigned char c)
 
void debug(const char *place, int err, const char *fmt,...)
 
static int parse_push_response_value(Octstr *attr_name, Octstr *attr_value, WAPEvent **e)
 
int octstr_hex_to_binary(Octstr *ostr)
 
static char * bearer_address[]
 
long octstr_parse_long(long *nump, Octstr *ostr, long pos, int base)
 
static long rest_unescaped(Octstr **address, long pos)
 
static int return_flag(Octstr *ros)
 
static char * pap_bearer_types[]
 
static long parse_qualifier_keyword(Octstr **address, long pos)
 
static int issafe(Octstr **address, long pos)
 
int parse_error(ParseContext *context)
 
static int parse_response_result_value(Octstr *attr_name, Octstr *attr_value, WAPEvent **e)
 
static long parse_ipv6_fragment(Octstr **address, long pos)
 
static int set_anys(WAPEvent **e, long type_of_address, int is_any)
 
static pap_attributes_t pap_attributes[]
 
#define create_octstr_from_node(node)
 
int octstr_get_char(const Octstr *ostr, long pos)
 
static int uses_ipv6_address(long bearer_required, Octstr *bearer)
 
static char * address_type(long type_of_address)
 
static long accept_safe(Octstr **address, long pos)
 
static long parse_constant(const char *field_name, Octstr **address, long pos)
 
int pap_compile(Octstr *pap_content, WAPEvent **e)
 
static int parse_progress_note_value(Octstr *attr_name, Octstr *attr_value, WAPEvent **e)
 
#define NUM_NETWORK_TYPES
 
void wap_event_destroy(WAPEvent *event)
 
static int parse_attribute(Octstr *element_name, xmlAttrPtr attribute, WAPEvent **e, long *type_of_address, int *is_any)
 
static size_t bearer_address_size
 
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)