示例#1
0
文件: soap.c 项目: stiks/iteliecd
auth_type* parse_auth_response (SoapCtx *response) {
    xmlXPathObjectPtr xpathObj = NULL;
    xmlNode* curNode = NULL;
    int i = 0;
    auth_type* ret;

    char* auth = NULL;
    char* token = NULL;

    xpathObj = soap_xpath_eval (response->env->root->doc, "//return");
    if(xpathObj == NULL) {
        printf("Unable to parse response\n");

        return NULL;
    }

    /* Parse response */
    if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr > 0) {
        for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
            curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;

            while (curNode) {
                if (xmlStrEqual(curNode->name, (const xmlChar *)"auth")) {
                    auth = (char *) xmlNodeGetContent(curNode);
                } else if (xmlStrEqual(curNode->name, (const xmlChar *)"token")) {
                    token = (char *) xmlNodeGetContent(curNode);
                }

                curNode = curNode->next;
            }

            if (auth) {
                if (strcmp (auth, "true") == 0) {
                    ret->auth = true;
                } else {
                    ret->auth = false;
                }
            }

            if (token) {
                ret->token = token;
            }

            free((void*)auth);
            free((void*)token);
        }
    }

    xmlXPathFreeObject (xpathObj);

    return ret;
}
示例#2
0
/* XXX: unused function? */
xmlNodePtr
_soap_env_get_body(SoapEnv * env)
{
  xmlNodePtr body;
  xmlNodeSetPtr nodeset;
  xmlXPathObjectPtr xpathobj;

  if (env == NULL)
  {
    log_error1("SoapEnv is NULL");
    return NULL;
  }

  if (env->root == NULL)
  {
    log_error1("SoapEnv contains no XML document");
    return NULL;
  }

  /* 
     find <Body> tag find out namespace xpath: //Envelope/Body/ */
  xpathobj = soap_xpath_eval(env->root->doc, "//Envelope/Body");

  if (!xpathobj)
  {
    log_error1("No Body (xpathobj)!");
    return NULL;
  }

  if (!(nodeset = xpathobj->nodesetval))
  {
    log_error1("No Body (nodeset)!");
    xmlXPathFreeObject(xpathobj);
    return NULL;
  }

  if (nodeset->nodeNr < 1)
  {
    log_error1("No Body (nodeNr)!");
    xmlXPathFreeObject(xpathobj);
    return NULL;
  }

  body = nodeset->nodeTab[0];   /* body is <Body> */
  xmlXPathFreeObject(xpathobj);
  return body;

}