📄 wap_push_pap_compiler.c
字号:
static int parse_attribute(Octstr *element_name, xmlAttrPtr attribute, WAPEvent **e, long *type_of_address, int *is_any){ Octstr *attr_name, *value, *nameos; size_t i; int ret; nameos = octstr_imm("erroneous"); attr_name = octstr_create(attribute->name); if (attribute->children != NULL) value = create_octstr_from_node(attribute->children); else value = octstr_imm("erroneous"); i = 0; while (i < NUM_ATTRIBUTES) { if (octstr_compare(attr_name, nameos = octstr_imm(pap_attributes[i].name)) == 0) break; ++i; } if (i == NUM_ATTRIBUTES) { debug("wap.push.pap.compiler", 0, "PAP COMPILER: unknown attribute `%s' " "within XML entity `%s'", octstr_get_cstr(attr_name), octstr_get_cstr(element_name)); goto error; }/* * Parse an attribute (it is, check cdata is has for a value) that is *not* an * enumeration. Legal values are defined in pap, chapter 9. */ if (pap_attributes[i].value == NULL) { ret = parse_attr_value(element_name, attr_name, value, e, type_of_address, is_any); if (ret == -2) { goto error; } else { goto parsed; } } while (octstr_compare(attr_name, nameos = octstr_imm(pap_attributes[i].name)) == 0) { if (octstr_compare(value, octstr_imm(pap_attributes[i].value)) == 0) break; ++i; } if (octstr_compare(attr_name, nameos) != 0) { debug("wap.push.pap.compiler", 0, "PAP COMPILER: unknown attribute " "value `%s' for attribute `%s' within XML entity `%s'", octstr_get_cstr(value), octstr_get_cstr(attr_name), octstr_get_cstr(element_name)); goto error; }/* * Check that the value of the attribute is one enumerated for this attribute * in pap, chapter 9. */ if (set_attribute_value(element_name, value, attr_name, e) == -1) goto error; octstr_destroy(attr_name); octstr_destroy(value); return 0;error: octstr_destroy(attr_name); octstr_destroy(value); return -2;parsed: octstr_destroy(attr_name); octstr_destroy(value); return ret;}/* * Attribute value parsing functions for the PAP element. * Defined in PAP, chapter 8.1. */static int parse_pap_value(Octstr *attr_name, Octstr *attr_value, WAPEvent **e){ Octstr *ros; if (*e != NULL) wap_event_dump(*e); ros = octstr_imm("erroneous"); if (octstr_compare(attr_name, octstr_imm("product-name")) == 0) { /* * XXX This is a kludge. * We can't add the product-name value to the WAPEvent, because * the wap_event_create() is created in the deeper layer, which * means as soon as we see <push-message> or <reponse-message>. * But we would have to decide which WAPEvent to create while * being on the higher <pap> level. * How's this to be solved?! -- Stipe */ return 0; } debug("wap.push.pap.compiler", 0, "PAP COMPILER: unknown pap" " element attribute `%s'", octstr_get_cstr(attr_name)); return -2;} /* * Value parsing functions return the newly created wap event containing * attribute value from pap source, if successfull; NULL otherwise . Value * types of attributes are defined in pap, chapter 9. */static int parse_push_message_value(Octstr *attr_name, Octstr *attr_value, WAPEvent **e){ Octstr *ros; ros = octstr_imm("erroneous"); if (octstr_compare(attr_name, octstr_imm("push-id")) == 0) { octstr_destroy((**e).u.Push_Message.pi_push_id); (**e).u.Push_Message.pi_push_id = octstr_duplicate(attr_value); return 0; } else if (octstr_compare(attr_name, octstr_imm("deliver-before-timestamp")) == 0) { (**e).u.Push_Message.deliver_before_timestamp = (ros = parse_date(attr_value)) ? octstr_duplicate(attr_value) : octstr_imm("erroneous"); return return_flag(ros); } else if (octstr_compare(attr_name, octstr_imm("deliver-after-timestamp")) == 0) { (**e).u.Push_Message.deliver_after_timestamp = (ros = parse_date(attr_value)) ? octstr_duplicate(attr_value) : octstr_imm("erroneous"); return return_flag(ros); } else if (octstr_compare(attr_name, octstr_imm("source-reference")) == 0) { (**e).u.Push_Message.source_reference = octstr_duplicate(attr_value); return 0; } else if (octstr_compare(attr_name, octstr_imm("ppg-notify-requested-to")) == 0) { (**e).u.Push_Message.ppg_notify_requested_to = octstr_duplicate(attr_value); return 0; } debug("wap.push.pap.compiler", 0, "PAP COMPILER: unknown push message" " element attribute"); return -2;} /* * When there is no legal address to be stored in field (either parsing was * unsuccessful or an unimplemented address format was requested by the push * initiator) we use value "erroneous". This is necessary, because this a * mandatory field. * * Output a) a newly created wap event * b) the type of the client address */static int parse_address_value(Octstr *attr_name, Octstr *attr_value, WAPEvent **e, long *type_of_address){ int ret; ret = -2; if (octstr_compare(attr_name, octstr_imm("address-value")) == 0) { octstr_destroy((**e).u.Push_Message.address_value); (**e).u.Push_Message.address_value = (ret = parse_address(&attr_value, type_of_address)) > -1 ? octstr_duplicate(attr_value) : octstr_imm("erroneous"); return ret; } debug("wap.push.pap.compiler", 0, "PAP COMPILER: unknown address element" " attribute"); return -2;}static int parse_quality_of_service_value(Octstr *attr_name, Octstr *attr_value, WAPEvent **e, int *is_any){ Octstr *ros; ros = octstr_imm("erroneous"); if (octstr_compare(attr_name, octstr_imm("network")) == 0) { (**e).u.Push_Message.network = (ros = parse_network(attr_value)) ? octstr_duplicate(attr_value) : octstr_imm("erroneous"); set_any_value(is_any, attr_name, attr_value); return return_flag(ros); } if (octstr_compare(attr_name, octstr_imm("bearer")) == 0) { (**e).u.Push_Message.bearer = (ros = parse_bearer(attr_value)) ? octstr_duplicate(attr_value) : octstr_imm("erroneous"); set_any_value(is_any, attr_name, attr_value); return return_flag(ros); } debug("wap.push.pap.compiler", 0, "PAP COMPILER: unknown quality of" " service attribute"); return -2;}static void set_any_value(int *is_any, Octstr *attr_name, Octstr *attr_value){ switch (*is_any) { case NEITHER: if (octstr_compare(attr_name, octstr_imm("bearer")) == 0 && octstr_case_compare(attr_value, octstr_imm("any")) == 0) *is_any = BEARER_ANY; else if (octstr_compare(attr_name, octstr_imm("network")) == 0 && octstr_case_compare(attr_value, octstr_imm("any")) == 0) *is_any = NETWORK_ANY; return; case BEARER_ANY: if (octstr_compare(attr_name, octstr_imm("network")) == 0 && octstr_case_compare(attr_value, octstr_imm("any")) == 0) *is_any = EITHER; return; case NETWORK_ANY: if (octstr_compare(attr_name, octstr_imm("bearer")) == 0 && octstr_case_compare(attr_value, octstr_imm("any")) == 0) *is_any = EITHER; return; case EITHER: debug("wap.push.pap.compiler", 0, "PAP COMPILER: problems with" " setting any"); *is_any = ERROR_ANY; return; default: debug("wap.push.pap.compiler", 0, "PAP COMPILER: wrong any value"); *is_any = ERROR_ANY; return; }}static int parse_push_response_value(Octstr *attr_name, Octstr *attr_value, WAPEvent **e){ Octstr *ros; int ret; ret = -2; ros = octstr_imm("erroneous"); if (octstr_compare(attr_name, octstr_imm("push-id")) == 0) { octstr_destroy((**e).u.Push_Response.pi_push_id); (**e).u.Push_Response.pi_push_id = octstr_duplicate(attr_value); return 0; } else if (octstr_compare(attr_name, octstr_imm("sender-address")) == 0) { (**e).u.Push_Response.sender_address = octstr_duplicate(attr_value); return 0; } else if (octstr_compare(attr_name, octstr_imm("reply-time")) == 0) { (**e).u.Push_Response.reply_time = (ros = parse_date(attr_value)) ? octstr_duplicate(attr_value) : NULL; return return_flag(ros); } else if (octstr_compare(attr_name, octstr_imm("sender-name")) == 0) { (**e).u.Push_Response.sender_name = octstr_duplicate(attr_value); return 0; } debug("wap.push.pap.compiler", 0, "PAP COMPILER: unknown push response" " element attribute"); return -2;}static int parse_progress_note_value(Octstr *attr_name, Octstr *attr_value, WAPEvent **e){ Octstr *ros; int ret; ret = -2; ros = octstr_imm("erroneous"); if (octstr_compare(attr_name, octstr_imm("stage")) == 0) { (**e).u.Progress_Note.stage = (ret = parse_state(attr_value)) ? ret : 0; return ret; } else if (octstr_compare(attr_name, octstr_imm("note")) == 0) { (**e).u.Progress_Note.note = octstr_duplicate(attr_value); return 0; } else if (octstr_compare(attr_name, octstr_imm("time")) == 0) { (**e).u.Progress_Note.time = (ros = parse_date(attr_value)) ? octstr_duplicate(attr_value) : octstr_imm("erroneous"); return return_flag(ros); } debug("wap.push.pap.compiler", 0, "PAP COMPILER: unknown progress note" " element attribute"); return -2;}static int parse_bad_message_response_value(Octstr *attr_name, Octstr *attr_value, WAPEvent **e){ if (octstr_compare(attr_name, octstr_imm("code")) == 0) { (**e).u.Bad_Message_Response.code = parse_code(attr_value); return 0; } else if (octstr_compare(attr_name, octstr_imm("desc")) == 0) { (**e).u.Bad_Message_Response.desc = octstr_duplicate(attr_value); return 0; } else if (octstr_compare(attr_name, octstr_imm("bad-message-fragment")) == 0) { (**e).u.Bad_Message_Response.bad_message_fragment = octstr_duplicate(attr_value); return 0; } debug("wap.push.pap.compiler", 0, "PAP COMPILER: unknown bad message" " response element attribute"); return -2;}static int parse_response_result_value(Octstr *attr_name, Octstr *attr_value, WAPEvent **e){ if (octstr_compare(attr_name, octstr_imm("code")) == 0) { (**e).u.Push_Response.code = parse_code(attr_value); return 0; } else if (octstr_compare(attr_name, octstr_imm("desc")) == 0) { (**e).u.Push_Response.desc = octstr_duplicate(attr_value); return 0; } debug("wap.push.pap.compiler", 0, "PAP COMPILER: unknown response result" " attribute"); return -2;} /* * Do not create multiple events. If *e points to NULL, we have not yet creat- * ed a wap event. Create a wap event mandatory fields set to error values * (these will be latter overwritten). This hack will disappear when we have * PAP validation. */static void wap_event_accept_or_create(Octstr *element_name, WAPEvent **e){ if (octstr_compare(element_name, octstr_imm("push-message")) == 0 && *e == NULL) { *e = wap_event_create(Push_Message); (**e).u.Push_Message.pi_push_id = octstr_format("%s", "erroneous"); (**e).u.Push_Message.address_value = octstr_format("%s", "erroneous"); } else if (octstr_compare(element_name, octstr_imm("push-response")) == 0 && *e == NULL) { *e = wap_event_create(Push_Response); (**e).u.Push_Response.pi_push_id = octstr_format("%s", "erroneous"); } else if (octstr_compare(element_name, octstr_imm("progress-note")) == 0 && *e == NULL) { *e = wap_event_create(Progress_Note); } else if (octstr_compare(element_name, octstr_imm("badmessage-response")) == 0 && *e == NULL) { *e = wap_event_create(Bad_Message_Response); } }static int return_flag(Octstr *ros){ if (ros) { return 0; } else { return -2; }}/* * Validates non-enumeration attributes and stores their value to a newly * created wap event e. (Even when attribute value parsing was not success- * full.) We do not accept NULL or empty attributes (if this kind of an * attribute is optional, we just drop it from the tokenised document). * * Output: a) a wap event, as created by subroutines * b) the type of the client address * c) is bearer or network set any * Returns 0, when success, * -1, when a non-implemented feature requested. * -2, when an error */static int parse_attr_value(Octstr *element_name, Octstr *attr_name, Octstr *attr_value, WAPEvent **e, long *type_of_address, int *is_any){ if (octstr_compare(attr_value, octstr_imm("erroneous")) == 0) { debug("wap.push.pap.compiler", 0, "unknown value for an attribute"); return -2; } wap_event_accept_or_create(element_name, e); if (octstr_compare(element_name, octstr_imm("pap")) == 0) { return parse_pap_value(attr_name, attr_value, e); } else if (octstr_compare(element_name, octstr_imm("push-message")) == 0) { return parse_push_message_value(attr_name, attr_value, e); } else if (octstr_compare(element_name, octstr_imm("address")) == 0) { return parse_address_value(attr_name, attr_value, e, type_of_address); } else if (octstr_compare(element_name, octstr_imm("quality-of-service")) == 0) { return parse_quality_of_service_value(attr_name, attr_value, e, is_any); } else if (octstr_compare(element_name, octstr_imm("push-response")) == 0) { return parse_push_response_value(attr_name, attr_value, e); } else if (octstr_compare(element_name, octstr_imm("progress-note")) == 0) { return parse_progress_note_value(attr_name, attr_value, e); } else if (octstr_compare(element_name, octstr_imm("badmessage-response")) == 0) { return parse_bad_message_response_value(attr_name, attr_value, e); } else if (octstr_compare(element_name, octstr_imm("response-result")) == 0) { return parse_response_result_value(attr_name, attr_value, e); } return -2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -