예제 #1
0
static void
testParseBadResponseXml(void) {
/*----------------------------------------------------------------------------
   Test parsing of data that is supposed to be a response, but in not
   even valid XML.
-----------------------------------------------------------------------------*/
    xmlrpc_env env;
    xmlrpc_value * valueP;
    int faultCode;
    const char * faultString;

    xmlrpc_env_init(&env);
       
    xmlrpc_parse_response2(&env,
                           unparseable_value, strlen(unparseable_value),
                           &valueP, &faultCode, &faultString);
        
    TEST_FAULT(&env, XMLRPC_PARSE_ERROR);
    xmlrpc_env_clean(&env);

    xmlrpc_env_init(&env);

        /* And again with the old interface */
    valueP = xmlrpc_parse_response(&env, unparseable_value,
                                   strlen(unparseable_value));
    TEST_FAULT(&env, XMLRPC_PARSE_ERROR);
    xmlrpc_env_clean(&env);
    TEST(valueP == NULL);
}
예제 #2
0
static void
testParseGoodResponse(void) {

    xmlrpc_env env;
    xmlrpc_value * valueP;
    int faultCode;
    const char * faultString;

    xmlrpc_env_init(&env);

    xmlrpc_parse_response2(&env, good_response_xml, strlen(good_response_xml),
                           &valueP, &faultCode, &faultString);

    TEST_NO_FAULT(&env);
    TEST(faultString == NULL);

    validateParseResponseResult(valueP);

    xmlrpc_DECREF(valueP);

    /* Try it again with old interface */

    valueP = xmlrpc_parse_response(&env,
                                   good_response_xml,
                                   strlen(good_response_xml));
    TEST_NO_FAULT(&env);
    TEST(valueP != NULL);

    validateParseResponseResult(valueP);

    xmlrpc_DECREF(valueP);

    xmlrpc_env_clean(&env);

}    
예제 #3
0
xmlrpc_value *
xmlrpc_parse_response(xmlrpc_env * const envP,
                      const char * const xmlData,
                      size_t       const xmlDataLen) {
/*----------------------------------------------------------------------------
   This exists for backward compatibility.  It is like
   xmlrpc_parse_response2(), except that it merges the concepts of a
   failed RPC and an error in executing the RPC.
-----------------------------------------------------------------------------*/
    xmlrpc_value * retval;
    xmlrpc_value * result;
    const char * faultString;
    int faultCode;

    xmlrpc_parse_response2(envP, xmlData, xmlDataLen,
                           &result, &faultCode, &faultString);
    
    if (envP->fault_occurred)
        retval = NULL;
    else {
        if (faultString) {
            xmlrpc_env_set_fault(envP, faultCode, faultString);
            xmlrpc_strfree(faultString);
            retval = NULL;
        } else
            retval = result;  /* transfer reference */
    }
    return retval;
}
예제 #4
0
static void
testParseBadResult(void) {
/*----------------------------------------------------------------------------
   Test parsing of data that is supposed to be a response, but is not
   valid.  It looks like a valid success response, but the result value
   is not valid XML-RPC.
-----------------------------------------------------------------------------*/
    unsigned int i;

    for (i = 0; bad_values[i] != NULL; ++i) {
        const char * const bad_resp = bad_values[i];
        xmlrpc_env env;
        xmlrpc_value * valueP;
        xml_element *elem;
        int faultCode;
        const char * faultString;
    
        xmlrpc_env_init(&env);

        /* First, check to make sure that our test case is well-formed XML.
        ** (It's easy to make mistakes when writing the test cases!) */
        xml_parse(&env, bad_resp, strlen(bad_resp), &elem);
        TEST_NO_FAULT(&env);
        xml_element_free(elem);
    
        /* Now, make sure the higher-level routine barfs appropriately. */
        
        xmlrpc_parse_response2(&env, bad_resp, strlen(bad_resp),
                               &valueP, &faultCode, &faultString);

        TEST_FAULT(&env, XMLRPC_PARSE_ERROR);
        xmlrpc_env_clean(&env);

        xmlrpc_env_init(&env);

        /* And again with the old interface */

        valueP = xmlrpc_parse_response(&env, bad_resp, strlen(bad_resp));
        TEST_FAULT(&env, XMLRPC_PARSE_ERROR);
        TEST(valueP == NULL);
        xmlrpc_env_clean(&env);
    }
}
예제 #5
0
static void
testParseFaultResponse(void) {
/*----------------------------------------------------------------------------
   Test parsing of a valid response that indicates the RPC failed.
-----------------------------------------------------------------------------*/
    xmlrpc_env env;

    xmlrpc_env_init(&env);

    {
        xmlrpc_value * resultP;
        int faultCode;
        const char * faultString;
            
        xmlrpc_parse_response2(&env,
                               serialized_fault, strlen(serialized_fault),
                               &resultP, &faultCode, &faultString);

        TEST_NO_FAULT(&env);
        TEST(faultString != NULL);
        TEST(faultCode == 6);
        TEST(streq(faultString, "A fault occurred"));
        strfree(faultString);
    }
    /* Now with the old interface */
    {
        xmlrpc_value * valueP;
        xmlrpc_env fault;

        /* Parse a valid fault. */
        xmlrpc_env_init(&fault);
        valueP = xmlrpc_parse_response(&fault, serialized_fault,
                                       strlen(serialized_fault));

        TEST(fault.fault_occurred);
        TEST(fault.fault_code == 6);
        TEST(streq(fault.fault_string, "A fault occurred"));
        xmlrpc_env_clean(&fault);
    }

    xmlrpc_env_clean(&env);
}
예제 #6
0
static void
test_xml_size_limit(void) {

    xmlrpc_env env;
    const char * methodName;
    xmlrpc_value * paramsP;
    
    /* NOTE - This test suite only verifies the last-ditch size-checking
       code.  There should also be matching code in all server (and
       preferably all client) modules as well.
    */

    /* Set our XML size limit to something ridiculous. */
    xmlrpc_limit_set(XMLRPC_XML_SIZE_LIMIT_ID, 6);
    
    /* Attempt to parse a call. */
    xmlrpc_env_init(&env);
    xmlrpc_parse_call(&env, serialized_call, strlen(serialized_call),
                      &methodName, &paramsP);
    TEST_FAULT(&env, XMLRPC_LIMIT_EXCEEDED_ERROR);
    xmlrpc_env_clean(&env);

    {
        xmlrpc_value * resultP;
        int faultCode;
        const char * faultString;

        /* Attempt to parse a response. */
        xmlrpc_env_init(&env);
        xmlrpc_parse_response2(&env,
                               good_response_xml, strlen(good_response_xml),
                               &resultP, &faultCode, &faultString);
        TEST_FAULT(&env, XMLRPC_LIMIT_EXCEEDED_ERROR);
        xmlrpc_env_clean(&env);
    }
    /* Reset the default limit. */
    xmlrpc_limit_set(XMLRPC_XML_SIZE_LIMIT_ID, XMLRPC_XML_SIZE_LIMIT_DEFAULT);
}