?? xmlrpc.c
字號:
(*msg)->parse_error = octstr_format("XML-RPC compiler: could not parse boolean value '%s'", octstr_get_cstr(value)); return -1; } //xmlrpc_call_add_bool((*msg), (int) lval); xmlrpc_call_add_scalar((*msg), xr_bool, (void *) lval); debug("", 0, "XML-RPC: added boolean %d", (int) lval); break; case xr_string: //xmlrpc_call_add_string((*msg), value); xmlrpc_call_add_scalar((*msg), xr_string, (void *) value); debug("", 0, "XML-RPC: added string %s", octstr_get_cstr(value)); break; case xr_date: //xmlrpc_call_add_date((*msg), value); xmlrpc_call_add_scalar((*msg), xr_date, (void *) value); debug("", 0, "XML-RPC: added date %s", octstr_get_cstr(value)); break; case xr_base64: //xmlrpc_call_add_base64((*msg), value); xmlrpc_call_add_scalar((*msg), xr_base64, (void *) value); debug("", 0, "XML-RPC: added base64 %s", octstr_get_cstr(value)); break; case xr_struct: if (parse_struct(doc, node->xmlChildrenNode, msg) == -1) { debug("", 0, "%s", octstr_get_cstr((*msg)->parse_error)); //(*msg)->parse_status = XMLRPC_PARSING_FAILED; //(*msg)->parse_error = octstr_format("XML-RPC compiler: could not parse struct"); return -1; } //debug("", 0, "XML-RPC: added struct %s", octstr_get_cstr(value)); break; case xr_double: default: (*msg)->parse_status = XMLRPC_PARSING_FAILED; (*msg)->parse_error = octstr_format("XML-RPC compiler: bogus parsing exception in parse_value!"); return -1; break; } octstr_destroy(value); return 0;}static int parse_value(xmlDocPtr doc, xmlNodePtr node, XMLRPCMethodCall **msg){ int status = 0; /* call for the parser function of the node type. */ switch (node->type) { case XML_ELEMENT_NODE: status = parse_value_element(doc, node, msg); break; case XML_TEXT_NODE: case XML_COMMENT_NODE: case XML_PI_NODE: /* Text nodes, comments and PIs are ignored. */ break; /* * XML has also many other node types, these are not needed with * XML-RPC. Therefore they are assumed to be an error. */ default: (*msg)->parse_status = XMLRPC_PARSING_FAILED; (*msg)->parse_error = octstr_format("XML-RPC compiler: Unknown XML node in the XML-RPC source."); return -1; break; } if (node->next != NULL) if (parse_value(doc, node->next, msg) == -1) return -1; return status;}static int parse_param_element(xmlDocPtr doc, xmlNodePtr node, XMLRPCMethodCall **msg){ Octstr *name; size_t i; /* * check if the element is allowed at this level */ name = octstr_create(node->name); if (octstr_len(name) == 0) { octstr_destroy(name); return -1; } i = 0; while (i < NUMBER_OF_PARAM_ELEMENTS) { if (octstr_case_compare(name, octstr_imm(param_elements[i].name)) == 0) break; ++i; } if (i == NUMBER_OF_PARAM_ELEMENTS) { (*msg)->parse_status = XMLRPC_PARSING_FAILED; (*msg)->parse_error = octstr_format("XML-RPC compiler: unknown tag '%s' " "in XML source at level <param>", octstr_get_cstr(name)); octstr_destroy(name); return -1; } octstr_destroy(name); /* * now check which type it is and process * * valid tags at this level are: * value [0] */ if (i == 0) { /* this has been a <param> tag */ if (parse_value(doc, node->xmlChildrenNode, msg) == -1) return -1; } else { /* we should never be here */ (*msg)->parse_status = XMLRPC_PARSING_FAILED; (*msg)->parse_error = octstr_format("XML-RPC compiler: bogus parsing exception in parse_param!"); return -1; } return 0;}static int parse_param(xmlDocPtr doc, xmlNodePtr node, XMLRPCMethodCall **msg, int *n){ int status = 0; /* call for the parser function of the node type. */ switch (node->type) { case XML_ELEMENT_NODE: /* a <param> can only have one value element type */ if ((*n) > 0) { (*msg)->parse_status = XMLRPC_PARSING_FAILED; (*msg)->parse_error = octstr_format("XML-RPC compiler: param may only have one value!"); return -1; } status = parse_param_element(doc, node, msg); (*n)++; break; case XML_TEXT_NODE: case XML_COMMENT_NODE: case XML_PI_NODE: /* Text nodes, comments and PIs are ignored. */ break; /* * XML has also many other node types, these are not needed with * XML-RPC. Therefore they are assumed to be an error. */ default: (*msg)->parse_status = XMLRPC_PARSING_FAILED; (*msg)->parse_error = octstr_format("XML-RPC compiler: Unknown XML node in the XML-RPC source."); return -1; break; } if (node->next != NULL) if (parse_param(doc, node->next, msg, n) == -1) return -1; return status;}static int parse_params_element(xmlDocPtr doc, xmlNodePtr node, XMLRPCMethodCall **msg){ Octstr *name; size_t i; int n = 0; /* * check if the element is allowed at this level * within <params> we only have one or more <param> */ name = octstr_create(node->name); if (octstr_len(name) == 0) { octstr_destroy(name); return -1; } i = 0; while (i < NUMBER_OF_PARAMS_ELEMENTS) { if (octstr_case_compare(name, octstr_imm(params_elements[i].name)) == 0) break; ++i; } if (i == NUMBER_OF_PARAMS_ELEMENTS) { (*msg)->parse_status = XMLRPC_PARSING_FAILED; (*msg)->parse_error = octstr_format("XML-RPC compiler: unknown tag '%s' " "in XML source at level <params>", octstr_get_cstr(name)); octstr_destroy(name); return -1; } octstr_destroy(name); /* * now check which type it is and process * * valid tags at this level are: * param [0] */ if (i == 0) { /* this has been a <param> tag */ if (parse_param(doc, node->xmlChildrenNode, msg, &n) == -1) return -1; } else { /* we should never be here */ (*msg)->parse_status = XMLRPC_PARSING_FAILED; (*msg)->parse_error = octstr_format("XML-RPC compiler: bogus parsing exception in parse_params!"); return -1; } return 0;}static int parse_params(xmlDocPtr doc, xmlNodePtr node, XMLRPCMethodCall **msg){ int status = 0; /* call for the parser function of the node type. */ switch (node->type) { case XML_ELEMENT_NODE: status = parse_params_element(doc, node, msg); break; case XML_TEXT_NODE: case XML_COMMENT_NODE: case XML_PI_NODE: /* Text nodes, comments and PIs are ignored. */ break; /* * XML has also many other node types, these are not needed with * XML-RPC. Therefore they are assumed to be an error. */ default: (*msg)->parse_status = XMLRPC_PARSING_FAILED; (*msg)->parse_error = octstr_format("XML-RPC compiler: unknown XML node in XML-RPC source."); return -1; break; } if (node->next != NULL) if (parse_params(doc, node->next, msg) == -1) return -1; return status;}static int parse_methodcall_element(xmlDocPtr doc, xmlNodePtr node, XMLRPCMethodCall **msg){ Octstr *name; Octstr *value; size_t i; /* * check if the element is allowed at this level */ name = octstr_create(node->name); if (octstr_len(name) == 0) { octstr_destroy(name); return -1; } i = 0; while (i < NUMBER_OF_METHODCALL_ELEMENTS) { if (octstr_case_compare(name, octstr_imm(methodcall_elements[i].name)) == 0) break; ++i; } if (i == NUMBER_OF_METHODCALL_ELEMENTS) { (*msg)->parse_status = XMLRPC_PARSING_FAILED; (*msg)->parse_error = octstr_format("XML-RPC compiler: unknown tag '%s' in XML source " "at level <methodCall>", octstr_get_cstr(name)); octstr_destroy(name); return -1; } octstr_destroy(name); /* * now check which type it is and process * * valid tags at this level are: * methodCall [0] * params [1] */ if (i == 0) { /* this has been the <methodName> tag */ value = octstr_create(xmlNodeListGetString(doc, node->xmlChildrenNode, 1)); /* destroy current msg->method_name and redefine */ octstr_destroy((*msg)->method_name); (*msg)->method_name = octstr_duplicate(value); octstr_destroy(value); } else { /* * ok, this has to be an <params> tag, otherwise we would * have returned previosly */ if (parse_params(doc, node->xmlChildrenNode, msg) == -1) return -1; } return 0;}static int parse_methodcall(xmlDocPtr doc, xmlNodePtr node, XMLRPCMethodCall **msg){ int status = 0; /* call for the parser function of the node type. */ switch (node->type) { case XML_ELEMENT_NODE: status = parse_methodcall_element(doc, node, msg); break; case XML_TEXT_NODE: case XML_COMMENT_NODE: case XML_PI_NODE: /* Text nodes, comments and PIs are ignored. */ break; /* * XML has also many other node types, these are not needed with * XML-RPC. Therefore they are assumed to be an error. */ default: (*msg)->parse_status = XMLRPC_PARSING_FAILED; (*msg)->parse_error = octstr_format("XML-RPC compiler: unknown XML node " "in the XML-RPC source."); return -1; break; } if (node->next != NULL) if (parse_methodcall(doc, node->next, msg) == -1) return -1; return status;}static int parse_document(xmlDocPtr document, XMLRPCMethodCall **msg){ xmlNodePtr node; Octstr *name; node = xmlDocGetRootElement(document); /* * check if this is at least a valid root element */ name = octstr_create(node->name); if (octstr_len(name) == 0) { octstr_destroy(name); return -1; } if (octstr_case_compare(name, octstr_imm("METHODCALL")) != 0) { (*msg)->parse_status = XMLRPC_PARSING_FAILED; (*msg)->parse_error = octstr_format("XML-RPC compiler: wrong root element <%s>, " "<methodCall> expected!", octstr_get_cstr(name)); octstr_destroy(name); return -1; } octstr_destroy(name); return parse_methodcall(document, node->xmlChildrenNode, msg);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -