Exemplo n.º 1
0
static void
parseName(xmlrpc_env *    const envP,
          xml_element *   const nameElemP,
          xmlrpc_value ** const valuePP) {

    unsigned int const childCount = xml_element_children_size(nameElemP);

    if (childCount > 0)
        setParseFault(envP, "<name> element has %u children.  "
                      "Should have none.", childCount);
    else {
        const char * const cdata     = xml_element_cdata(nameElemP);
        size_t       const cdataSize = xml_element_cdata_size(nameElemP);

        *valuePP = xmlrpc_string_new_lp(envP, cdataSize, cdata);
    }
}
Exemplo n.º 2
0
static void
test_value_string_null(void) {

    xmlrpc_value * v;
    xmlrpc_env env;
    xmlrpc_env env2;
    const char * str;
    size_t len;

    /* Test a string with a '\0' byte. */

    xmlrpc_env_init(&env);

    v = xmlrpc_string_new_lp(&env, 7, "foo\0bar");
    TEST_NO_FAULT(&env);
    TEST(XMLRPC_TYPE_STRING == xmlrpc_value_type(v));
    xmlrpc_read_string_lp(&env, v, &len, &str);
    TEST_NO_FAULT(&env);
    TEST(len == 7);
    TEST(memeq(str, "foo\0bar", 7));
    xmlrpc_DECREF(v);
    strfree(str);

    v = xmlrpc_build_value(&env, "s#", "foo\0bar", (size_t) 7);
    TEST_NO_FAULT(&env);
    TEST(v != NULL);
    TEST(XMLRPC_TYPE_STRING == xmlrpc_value_type(v));

    xmlrpc_decompose_value(&env, v, "s#", &str, &len);
    TEST_NO_FAULT(&env);
    TEST(memeq(str, "foo\0bar", 7));
    TEST(len == 7);
    strfree(str);

    /* Test for type error when decoding a string with a zero byte to a
    ** regular C string. */
    xmlrpc_env_init(&env2);
    xmlrpc_decompose_value(&env2, v, "s", &str);
    TEST_FAULT(&env2, XMLRPC_TYPE_ERROR);
    xmlrpc_env_clean(&env2);
    xmlrpc_DECREF(v);

    xmlrpc_env_clean(&env);
}
Exemplo n.º 3
0
    cNewStringWrapper(string const cppvalue,
                      value_string::nlCode const nlCode) {
        env_wrap env;

        switch (nlCode) {
        case value_string::nlCode_all:
            this->valueP = xmlrpc_string_new_lp(&env.env_c,
                                                cppvalue.length(),
                                                cppvalue.c_str());
            break;
        case value_string::nlCode_lf:
            this->valueP = xmlrpc_string_new_lp_cr(&env.env_c,
                                                   cppvalue.length(),
                                                   cppvalue.c_str());
            break;
        default:
            throw (error("Newline encoding argument to value_string "
                         "constructor is not one of the defined "
                         "enumerations of value_string::nlCode"));
        }
        throwIfError(env);
    }
Exemplo n.º 4
0
static void
test_value_string_multiline(void) {

    xmlrpc_env env;
    xmlrpc_value * v;
    const char * str;
    size_t len;

    xmlrpc_env_init(&env);

    /* LF line ending */

    v = xmlrpc_string_new(&env, "foo\n");
    TEST_NO_FAULT(&env);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\n"));
    strfree(str);
    xmlrpc_read_string_crlf(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\r\n"));
    strfree(str);
    xmlrpc_DECREF(v);

    v = xmlrpc_string_new(&env, "foo\n\n");
    TEST_NO_FAULT(&env);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\n\n"));
    strfree(str);
    xmlrpc_read_string_crlf(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\r\n\r\n"));
    strfree(str);
    xmlrpc_DECREF(v);

    v = xmlrpc_string_new(&env, "foo\nbar");
    TEST_NO_FAULT(&env);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\nbar"));
    strfree(str);
    xmlrpc_read_string_crlf(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\r\nbar"));
    strfree(str);
    xmlrpc_DECREF(v);

    v = xmlrpc_string_new(&env, "foo\nbar\n");
    TEST_NO_FAULT(&env);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\nbar\n"));
    strfree(str);
    xmlrpc_read_string_crlf(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\r\nbar\r\n"));
    strfree(str);
    xmlrpc_DECREF(v);

    v = xmlrpc_string_new(&env, "foo\nbar\nbaz");
    TEST_NO_FAULT(&env);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\nbar\nbaz"));
    strfree(str);
    xmlrpc_read_string_crlf(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\r\nbar\r\nbaz"));
    strfree(str);
    xmlrpc_DECREF(v);

    /* CR line ending */

    v = xmlrpc_string_new(&env, "foo\r");
    TEST_NO_FAULT(&env);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\n"));
    xmlrpc_DECREF(v);
    strfree(str);

    v = xmlrpc_string_new(&env, "foo\r\r");
    TEST_NO_FAULT(&env);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\n\n"));
    xmlrpc_DECREF(v);
    strfree(str);

    v = xmlrpc_string_new(&env, "foo\rbar");
    TEST_NO_FAULT(&env);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\nbar"));
    xmlrpc_DECREF(v);
    strfree(str);

    v = xmlrpc_string_new(&env, "foo\rbar\r");
    TEST_NO_FAULT(&env);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\nbar\n"));
    xmlrpc_DECREF(v);
    strfree(str);

    v = xmlrpc_string_new(&env, "foo\rbar\rbaz");
    TEST_NO_FAULT(&env);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\nbar\nbaz"));
    xmlrpc_DECREF(v);
    strfree(str);

    /* CRLF line ending */

    v = xmlrpc_string_new(&env, "foo\r\n");
    TEST_NO_FAULT(&env);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\n"));
    xmlrpc_DECREF(v);
    strfree(str);

    v = xmlrpc_string_new(&env, "foo\r\n\r\n");
    TEST_NO_FAULT(&env);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\n\n"));
    xmlrpc_DECREF(v);
    strfree(str);

    v = xmlrpc_string_new(&env, "foo\r\nbar");
    TEST_NO_FAULT(&env);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\nbar"));
    xmlrpc_DECREF(v);
    strfree(str);

    v = xmlrpc_string_new(&env, "foo\r\nbar\r\n");
    TEST_NO_FAULT(&env);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\nbar\n"));
    xmlrpc_DECREF(v);
    strfree(str);

    v = xmlrpc_string_new(&env, "foo\r\nbar\r\nbaz");
    TEST_NO_FAULT(&env);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo\nbar\nbaz"));
    xmlrpc_DECREF(v);
    strfree(str);

    /* Embedded null */

    v = xmlrpc_string_new_lp(&env, 14, "foo\r\n\0bar\r\nbaz");
    TEST_NO_FAULT(&env);
    xmlrpc_read_string_lp(&env, v, &len, &str);
    TEST_NO_FAULT(&env);
    TEST(len == 12);
    TEST(memeq(str, "foo\n\0bar\nbaz", len));
    strfree(str);
    xmlrpc_read_string_lp_crlf(&env, v, &len, &str);
    TEST_NO_FAULT(&env);
    TEST(len == 14);
    TEST(memeq(str, "foo\r\n\0bar\r\nbaz", len));
    strfree(str);
    xmlrpc_DECREF(v);

    xmlrpc_env_clean(&env);
}
static void
test_serialize_string(void) {

    /* Test serialize of a string, including all the line ending
       complexity.
    */

    xmlrpc_env env;
    xmlrpc_value * v;
    xmlrpc_mem_block * xmlP;         /* Serialized result */
    
    xmlrpc_env_init(&env);

    TEST_NO_FAULT(&env);

    v = xmlrpc_string_new(&env, "hello world");
    TEST_NO_FAULT(&env);

    xmlP = XMLRPC_MEMBLOCK_NEW(char, &env, 0);
    xmlrpc_serialize_value(&env, xmlP, v);
    TEST_NO_FAULT(&env);
    TEST(memeq(XMLRPC_MEMBLOCK_CONTENTS(char, xmlP),
               "<value><string>hello world</string></value>",
               XMLRPC_MEMBLOCK_SIZE(char, xmlP)));
    XMLRPC_MEMBLOCK_FREE(char, xmlP);
    xmlrpc_DECREF(v);

    v = xmlrpc_string_new(&env, "");
    TEST_NO_FAULT(&env);
    xmlP = XMLRPC_MEMBLOCK_NEW(char, &env, 0);
    xmlrpc_serialize_value(&env, xmlP, v);
    TEST_NO_FAULT(&env);
    TEST(memeq(XMLRPC_MEMBLOCK_CONTENTS(char, xmlP),
               "<value><string></string></value>",
               XMLRPC_MEMBLOCK_SIZE(char, xmlP)));
    XMLRPC_MEMBLOCK_FREE(char, xmlP);
    xmlrpc_DECREF(v);

    v = xmlrpc_string_new_lp(&env, 7, "foo\0bar");
    TEST_NO_FAULT(&env);
    xmlP = XMLRPC_MEMBLOCK_NEW(char, &env, 0);
    xmlrpc_serialize_value(&env, xmlP, v);
    TEST_NO_FAULT(&env);
    TEST(memeq(XMLRPC_MEMBLOCK_CONTENTS(char, xmlP),
               "<value><string>foo\0bar</string></value>",
               XMLRPC_MEMBLOCK_SIZE(char, xmlP)));
    XMLRPC_MEMBLOCK_FREE(char, xmlP);
    xmlrpc_DECREF(v);

    v = xmlrpc_string_new_lp(&env, 7, "foo\nbar");
    TEST_NO_FAULT(&env);
    xmlP = XMLRPC_MEMBLOCK_NEW(char, &env, 0);
    xmlrpc_serialize_value(&env, xmlP, v);
    TEST_NO_FAULT(&env);
    TEST(memeq(XMLRPC_MEMBLOCK_CONTENTS(char, xmlP),
               "<value><string>foo\nbar</string></value>",
               XMLRPC_MEMBLOCK_SIZE(char, xmlP)));
    XMLRPC_MEMBLOCK_FREE(char, xmlP);
    xmlrpc_DECREF(v);

    v = xmlrpc_string_new_lp(&env, 8, "foo\r\nbar");
    TEST_NO_FAULT(&env);
    xmlP = XMLRPC_MEMBLOCK_NEW(char, &env, 0);
    xmlrpc_serialize_value(&env, xmlP, v);
    TEST_NO_FAULT(&env);
    TEST(memeq(XMLRPC_MEMBLOCK_CONTENTS(char, xmlP),
               "<value><string>foo\nbar</string></value>",
               XMLRPC_MEMBLOCK_SIZE(char, xmlP)));
    XMLRPC_MEMBLOCK_FREE(char, xmlP);
    xmlrpc_DECREF(v);

    v = xmlrpc_string_new_lp(&env, 7, "foo\rbar");
    TEST_NO_FAULT(&env);
    xmlP = XMLRPC_MEMBLOCK_NEW(char, &env, 0);
    xmlrpc_serialize_value(&env, xmlP, v);
    TEST_NO_FAULT(&env);
    TEST(memeq(XMLRPC_MEMBLOCK_CONTENTS(char, xmlP),
               "<value><string>foo\nbar</string></value>",
               XMLRPC_MEMBLOCK_SIZE(char, xmlP)));
    XMLRPC_MEMBLOCK_FREE(char, xmlP);
    xmlrpc_DECREF(v);

    v = xmlrpc_string_new_lp_cr(&env, 7, "foo\rbar");
    TEST_NO_FAULT(&env);
    xmlP = XMLRPC_MEMBLOCK_NEW(char, &env, 0);
    xmlrpc_serialize_value(&env, xmlP, v);
    TEST_NO_FAULT(&env);
    TEST(memeq(XMLRPC_MEMBLOCK_CONTENTS(char, xmlP),
               "<value><string>foo&#x0d;bar</string></value>",
               XMLRPC_MEMBLOCK_SIZE(char, xmlP)));
    XMLRPC_MEMBLOCK_FREE(char, xmlP);
    xmlrpc_DECREF(v);

    xmlrpc_env_clean(&env);
}