int
wpCreatePostStruct(xmlrpc_env *env, char *username, char*password, wppost_t *post, xmlrpc_value **paramArray, int mode) {
	int retval = 0;
	xmlrpc_value *blogidP, *postidP, *usernameP, *passwordP, *titleP, *descriptionP, *dateP, *publishP, *categoryP, *contentP, *tokenP;
	char *token;
	char *categories = NULL, *catPtr;
	if ( mode == 0 ) {
		post->blogid = wpGetBlogId(username, password, post->url);
		if (post->blogid == NULL) {
			fprintf(stderr, "NULL Blog Id\n");
			retval = 1;
			goto out;	
		}
		blogidP = xmlrpc_string_new(env, post->blogid);
		postidP = NULL;
	} else {
		blogidP = NULL;
		postidP = xmlrpc_string_new(env, post->postid);
	}
	usernameP = xmlrpc_string_new(env, username);
	passwordP = xmlrpc_string_new(env, password);
	titleP = xmlrpc_string_new(env, post->subject);
	descriptionP = xmlrpc_string_new(env, post->body);
	if(!strcmp(post->status, "draft")) {
		publishP = xmlrpc_bool_new(env, FALSE);
	} else {
		publishP = xmlrpc_bool_new(env, TRUE);
	}
	dateP = xmlrpc_datetime_new_sec(env, time(NULL));
	asprintf(&categories, "%s", post->categories);
	catPtr = categories;
	categoryP = xmlrpc_array_new(env);
	token = strtok(categories, ",");
	tokenP = xmlrpc_string_new(env, token);
	xmlrpc_array_append_item(env, categoryP, tokenP);
	while( (token = strtok( (char *) NULL, ",") ) != NULL ) {
		tokenP = xmlrpc_string_new(env, token);
		xmlrpc_array_append_item(env, categoryP, tokenP);
	}
	free(catPtr);
	contentP = xmlrpc_struct_new(env);
	xmlrpc_struct_set_value(env, contentP, "title", titleP);
	xmlrpc_struct_set_value(env, contentP, "description", descriptionP);
	xmlrpc_struct_set_value(env, contentP, "dateCreated", dateP);
	xmlrpc_struct_set_value(env, contentP, "categories", categoryP);
	/* Populate the Parameter Array */
	*paramArray = xmlrpc_array_new(env);
	if (mode == 0)
		xmlrpc_array_append_item(env, *paramArray, blogidP);
	else
		xmlrpc_array_append_item(env, *paramArray, postidP);
	xmlrpc_array_append_item(env, *paramArray, usernameP);
	xmlrpc_array_append_item(env, *paramArray, passwordP);
	xmlrpc_array_append_item(env, *paramArray, contentP);
	xmlrpc_array_append_item(env, *paramArray, publishP);
out:
	return retval;
}
Esempio n. 2
0
/* Pack the information from any client method into a generic xmlrpc
   struct to send to the server */
xmlrpc_value *
callinfo_pack(xmlrpc_env *envP, struct call_info *cip)
{
  xmlrpc_value *s = xmlrpc_struct_new(envP);
  xmlrpc_value *methargs = xmlrpc_array_new(envP);
  xmlrpc_value *files = xmlrpc_array_new(envP);
  int i;

  xmlrpc_struct_set_value(envP, s, "clientIP", xmlrpc_string_new(envP, nonull(cip->clientIP)));
  xmlrpc_struct_set_value(envP, s, "serverURL", xmlrpc_string_new(envP, nonull(cip->serverURL)));
  xmlrpc_struct_set_value(envP, s, "session", xmlrpc_string_new(envP, nonull(cip->session)));
  xmlrpc_struct_set_value(envP, s, "method", xmlrpc_string_new(envP, nonull(cip->method)));
  xmlrpc_struct_set_value(envP, s, "user", xmlrpc_string_new(envP, nonull(cip->user)));
  xmlrpc_struct_set_value(envP, s, "password", xmlrpc_string_new(envP, nonull(cip->password)));
  xmlrpc_struct_set_value(envP, s, "project", xmlrpc_string_new(envP, nonull(cip->project)));
  xmlrpc_struct_set_value(envP, s, "version", xmlrpc_string_new(envP, nonull(cip->version)));

  if (cip->methodargs)
    {
      for (i = 0; cip->methodargs[i]; ++i)
	{
	  if (!strncmp(cip->methodargs[i], "file:", 5))
	    {
	      char *file_what, *file_name;
	      
	      file_what = strdup(&cip->methodargs[i][5]);
	      file_name = strchr(file_what, '=');
	      if (file_name)
		{
		  xmlrpc_value * fstruct;
		  *file_name++ = '\0';
		  fstruct = file_pack(envP, file_what, file_name);
		  xmlrpc_array_append_item(envP, files, fstruct);
		}
	      else
		{
		  fprintf(stderr, "oracc-client: bad -Mfile arg, expected -Mfile:WHAT=NAME\n");
		  exit(1);
		}
	    }
	  else
	    xmlrpc_array_append_item(envP, methargs, xmlrpc_string_new(envP, cip->methodargs[i]));
	}
    }

  xmlrpc_struct_set_value(envP, s, "method-args", methargs);
  xmlrpc_struct_set_value(envP, s, "method-data", files);

  return s;
}
Esempio n. 3
0
void
xr_setStringInResult (void *data, char *val)
{
    CallerP c = (Caller *) data;

    if (c->result)
	xmlrpc_DECREF (c->result);
    if (!xr_errstat)
	c->result = xmlrpc_string_new (c->env, (const char *)val);
}
Esempio n. 4
0
void
xmlrpc_set_struct_string( xmlrpc_env * const envP,
			xmlrpc_value *pstruct, 
			const char *key,
			const char *val )
{
	xmlrpc_value *str_val = xmlrpc_string_new( envP, val );
	assertValue( str_val );

	xmlrpc_struct_set_value( envP, pstruct, key, str_val );
	xmlrpc_DECREF( str_val );
}
static void
test_value_string_no_null(void) {

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

    /* Test strings (without '\0' bytes). */
    xmlrpc_env_init(&env);

    v = xmlrpc_string_new(&env, test_string_1);
    TEST_NO_FAULT(&env);
    TEST(XMLRPC_TYPE_STRING == xmlrpc_value_type(v));
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(strcmp(str, test_string_1) == 0);
    xmlrpc_DECREF(v);
    strfree(str);

    v = xmlrpc_build_value(&env, "s", test_string_1);

    TEST_NO_FAULT(&env);
    TEST(v != NULL);
    TEST(XMLRPC_TYPE_STRING == xmlrpc_value_type(v));

    xmlrpc_decompose_value(&env, v, "s", &str);
    TEST_NO_FAULT(&env);
    TEST(strcmp(str, test_string_1) == 0);
    strfree(str);

    xmlrpc_decompose_value(&env, v, "s#", &str, &len);
    TEST_NO_FAULT(&env);
    TEST(memcmp(str, test_string_1, strlen(test_string_1)) == 0);
    TEST(strlen(str) == strlen(test_string_1));
    strfree(str);

    xmlrpc_DECREF(v);

    xmlrpc_env_clean(&env);
}
static void
createMethodListArray(xmlrpc_env *      const envP,
                      xmlrpc_registry * const registryP,
                      xmlrpc_value **   const methodListPP) {
/*----------------------------------------------------------------------------
   Create as an XML-RPC array value a list of names of methods registered
   in registry 'registryP'.

   This is the type of value that the system.listMethods method is supposed
   to return.
-----------------------------------------------------------------------------*/
    xmlrpc_value * methodListP;

    methodListP = xmlrpc_array_new(envP);

    if (!envP->fault_occurred) {
        xmlrpc_methodNode * methodNodeP;
        for (methodNodeP = registryP->methodListP->firstMethodP;
             methodNodeP && !envP->fault_occurred;
             methodNodeP = methodNodeP->nextP) {
            
            xmlrpc_value * methodNameVP;
            
            methodNameVP = xmlrpc_string_new(envP, methodNodeP->methodName);
            
            if (!envP->fault_occurred) {
                xmlrpc_array_append_item(envP, methodListP, methodNameVP);
                
                xmlrpc_DECREF(methodNameVP);
            }
        }
        if (envP->fault_occurred)
            xmlrpc_DECREF(methodListP);
    }
    *methodListPP = methodListP;
}
static xmlrpc_value *
xr_defaultMethod (xmlrpc_env *envP, char *host, char *methodName,
               xmlrpc_value *paramArrayP, void *serverInfo)
{
    int      status;
    ServerP  svr = (Server *) serverInfo; 
    MethodP  m   = (Method *) NULL;
    extern int  xr_errstat;


   	
    if (DEBUG)
        fprintf (stderr, "DEFAULT:  method='%s' data= 0x%lx\n",
	    methodName, (unsigned long) serverInfo);
        

    /* Now look for the method in the interface registry.
    */
    for (m=svr->method_head; m; m = m->next) {

	if (strcmp (m->name, methodName) == 0) {

	    Caller *c = (Caller *) NULL;
	    xmlrpc_value *result = (xmlrpc_value *) NULL;


	    (void) pthread_mutex_lock (&svr_mutex);
	    c = &cs[(cindex = (cindex + 1) % SZ_CALL_RING)];
	    (void) pthread_mutex_unlock (&svr_mutex);

#ifdef FREE_RES
	    /*  Free old result values.
	     */
	    if (res_anum >= 0) {
		xr_freeArray (res_anum);
		res_anum = -1;
	    }
	    if (res_snum >= 0) {
		xr_freeStruct (res_snum);
		res_snum = -1;
	    }
#endif

	    memset (c, 0, sizeof(Caller));
	    c->env   = envP; 		/* setup the calling parameters */
	    c->host  = host;
	    c->name  = methodName;
	    c->param = paramArrayP;
	    c->info  = serverInfo;


	    /* Call the function.
	    */
	
	    xr_setStat (2);
	    if ( (status = (*(PFI)(*m->methodFunc))((void *)c)) ) {
		fprintf (stderr, "Matched failed '%s'...\n", m->name);
		xr_errstat = ERR;
	    } else {
	        xr_errstat = OK;
		xmlrpc_DECREF(paramArrayP);
	        result = (c->result ? c->result : (xmlrpc_value *) NULL);
	    }

	    xmlrpc_INCREF(result);
    	    return ( result ); 			/* return our result	*/
	}
    }


    if (!m) {
	char  msg[256];

	memset (msg, 0, 256);
	sprintf (msg, "No such method '%s'", methodName);
	xmlrpc_value *result = xmlrpc_string_new (envP, msg);

        return ( result );

    } else
        return ((xmlrpc_value *) NULL);		/* should never happen	*/
}
Esempio n. 8
0
static void 
test_value_string_wide(void) {

#if HAVE_UNICODE_WCHAR
    xmlrpc_env env;
    xmlrpc_value * valueP;
    const wchar_t * wcs;
    size_t len;

    xmlrpc_env_init(&env);

    /* Build a string from wchar_t data. */
    valueP = xmlrpc_string_w_new_lp(&env, 3, wcs_data);
    TEST_NO_FAULT(&env);
    TEST(valueP != NULL);

    /* Extract it as a wchar_t string. */
    xmlrpc_read_string_w_lp(&env, valueP, &len, &wcs);
    TEST_NO_FAULT(&env);
    TEST(wcs != NULL);
    TEST(len == 3);
    TEST(wcs[len] == '\0');
    TEST(wcsneq(wcs, wcs_data, len));
    free((void*)wcs);

    xmlrpc_read_string_w(&env, valueP, &wcs);
    TEST_NO_FAULT(&env);
    TEST(wcs != NULL);
    TEST(wcs[3] == '\0');
    TEST(wcsneq(wcs, wcs_data, 3));
    free((void*)wcs);

    xmlrpc_decompose_value(&env, valueP, "w#", &wcs, &len);
    TEST_NO_FAULT(&env);
    TEST(wcs != NULL);
    TEST(len == 3);
    TEST(wcs[len] == '\0');
    TEST(wcsneq(wcs, wcs_data, len));
    free((void*)wcs);

    {
        /* Extract it as a UTF-8 string. */
        const char * str;
        size_t len;

        xmlrpc_read_string_lp(&env, valueP, &len, &str);
        TEST_NO_FAULT(&env);
        TEST(str != NULL);
        TEST(len == 4);
        TEST(str[len] == '\0');
        TEST(xmlrpc_strneq(str, utf8_data, len));
        free((void*)str);
    }

    xmlrpc_DECREF(valueP);

    /* Build from null-terminated wchar_t string */
    valueP = xmlrpc_string_w_new(&env, wcs_data);
    TEST_NO_FAULT(&env);
    TEST(valueP != NULL);

    /* Verify it */
    xmlrpc_read_string_w_lp(&env, valueP, &len, &wcs);
    TEST_NO_FAULT(&env);
    TEST(wcs != NULL);
    TEST(len == 3);
    TEST(wcs[len] == '\0');
    TEST(wcsneq(wcs, wcs_data, len));
    free((void*)wcs);

    xmlrpc_DECREF(valueP);

    test_value_string_wide_build();

    /* Build a string from UTF-8 data. */
    valueP = xmlrpc_string_new(&env, utf8_data);
    TEST_NO_FAULT(&env);
    TEST(valueP != NULL);

    /* Extract it as a wchar_t string. */
    xmlrpc_read_string_w_lp(&env, valueP, &len, &wcs);
    TEST_NO_FAULT(&env);
    TEST(wcs != NULL);
    TEST(len == 3);
    TEST(wcs[len] == 0x0000);
    TEST(wcsneq(wcs, wcs_data, len));
    free((void*)wcs);
    xmlrpc_DECREF(valueP);

    /* Test with embedded NUL.  We use a length of 4 so that the terminating
       NUL actually becomes part of the string.
    */
    valueP = xmlrpc_string_w_new_lp(&env, 4, wcs_data);
    TEST_NO_FAULT(&env);
    TEST(valueP != NULL);

    /* Extract it as a wchar_t string. */
    xmlrpc_read_string_w_lp(&env, valueP, &len, &wcs);
    TEST_NO_FAULT(&env);
    TEST(wcs != NULL);
    TEST(len == 4);
    TEST(wcs[len] == '\0');
    TEST(wcsneq(wcs, wcs_data, len));
    free((void*)wcs);

    xmlrpc_read_string_w(&env, valueP, &wcs);
    TEST_FAULT(&env, XMLRPC_TYPE_ERROR);

    xmlrpc_DECREF(valueP);

    test_value_string_wide_line();

    xmlrpc_env_clean(&env);
#endif /* HAVE_UNICODE_WCHAR */
}
Esempio n. 9
0
static void
test_value_string_no_null(void) {

    /* Test strings (without '\0' bytes). */

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

    xmlrpc_env_init(&env);

    TEST(streq(xmlrpc_type_name(XMLRPC_TYPE_STRING), "STRING"));

    {
        const char * const simpleAsciiString = "foo";
        v = xmlrpc_string_new(&env, simpleAsciiString);
        TEST_NO_FAULT(&env);
        TEST(xmlrpc_value_type(v) == XMLRPC_TYPE_STRING);
        xmlrpc_read_string(&env, v, &str);
        TEST_NO_FAULT(&env);
        TEST(streq(str, simpleAsciiString));
        xmlrpc_DECREF(v);
        strfree(str);
    }        
    {
        const char * const utf8String = "KOŚĆ";
        v = xmlrpc_string_new(&env, utf8String);
        TEST_NO_FAULT(&env);
        TEST(xmlrpc_value_type(v) == XMLRPC_TYPE_STRING);
        xmlrpc_read_string(&env, v, &str);
        TEST_NO_FAULT(&env);
        TEST(streq(str, utf8String));
        xmlrpc_DECREF(v);
        strfree(str);
    }
    v = xmlrpc_string_new_f(&env, "String %s, number %d", "xyz", 7);
    TEST_NO_FAULT(&env);
    TEST(xmlrpc_value_type(v) == XMLRPC_TYPE_STRING);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "String xyz, number 7"));
    xmlrpc_DECREF(v);
    strfree(str);

    v = test_string_new_va(&env, "String %s, number %d", "xyz", 7);
    TEST_NO_FAULT(&env);
    TEST(xmlrpc_value_type(v) == XMLRPC_TYPE_STRING);
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "String xyz, number 7"));
    xmlrpc_DECREF(v);
    strfree(str);

    v = xmlrpc_build_value(&env, "s", "foo");

    TEST_NO_FAULT(&env);
    TEST(v != NULL);
    TEST(XMLRPC_TYPE_STRING == xmlrpc_value_type(v));

    xmlrpc_decompose_value(&env, v, "s", &str);
    TEST_NO_FAULT(&env);
    TEST(streq(str, "foo"));
    strfree(str);

    xmlrpc_decompose_value(&env, v, "s#", &str, &len);
    TEST_NO_FAULT(&env);
    TEST(len == strlen("foo"));
    TEST(xmlrpc_streq(str, "foo"));
    TEST(strlen(str) == strlen("foo"));
    strfree(str);

    xmlrpc_DECREF(v);

    xmlrpc_env_clean(&env);
}
Esempio n. 10
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);
}
Esempio n. 11
0
static void get_torrent_list(torrent_array **result) {
    size_t size;
    xmlrpc_value *xml_array, *params;

    params = xmlrpc_array_new(&env);
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "main"));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.hash="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.name="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.is_active="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.state="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.bytes_done="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.size_bytes="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.up.rate="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.down.rate="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.down.total="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.ratio="));
    check_fault();

    execute_proxy_method(&xml_array, "d.multicall", params);
    check_fault(&env);
    assert(xmlrpc_value_type(xml_array) == XMLRPC_TYPE_ARRAY);

    XMLRPC_ASSERT_ARRAY_OK(xml_array);
    size = xmlrpc_array_size(&env, xml_array);
    check_fault(&env);

    if (size <= 0)
        goto finish;
        
    *result = torrent_array_new(size);
    for (size_t i = 0; i < size; ++i) {
        size_t tarray_size;
        xmlrpc_value *tarray = NULL;

        xmlrpc_array_read_item(&env, xml_array, i, &tarray);
        check_fault(&env);
        assert(xmlrpc_value_type(tarray) == XMLRPC_TYPE_ARRAY);

        XMLRPC_ASSERT_ARRAY_OK(tarray);
        tarray_size = xmlrpc_array_size(&env, tarray);

        for (size_t j = 0; j < tarray_size; ++j) {
            xmlrpc_value *item = NULL;

            xmlrpc_array_read_item(&env, tarray, j, &item);
            check_fault(&env);

            switch (j) {
                case 0:
                    get_string(item, &(*result)->torrents[i]->hash);
                    break;
                case 1:
                    get_string(item, &(*result)->torrents[i]->name);
                    break;
                case 2:
                    get_bool_from_int64(item, &(*result)->torrents[i]->active);
                    break;
                case 3:
                    get_bool_from_int64(item, &(*result)->torrents[i]->started);
                    break;
                case 4:
                    get_int64(item, &(*result)->torrents[i]->done_bytes);
                    break;
                case 5:
                    get_int64(item, &(*result)->torrents[i]->size_bytes);
                    break;
                case 6:
                    get_int64(item, &(*result)->torrents[i]->up_rate);
                    break;
                case 7:
                    get_int64(item, &(*result)->torrents[i]->down_rate);
                    break;
                case 8:
                    get_int64(item, &(*result)->torrents[i]->down_total);
                    break;
                case 9:
                    get_int64(item, &(*result)->torrents[i]->ratio);
                    break;
                default:
                    ;
            }
            xmlrpc_DECREF(item);
        }
        xmlrpc_DECREF(tarray);
    }

finish:
    xmlrpc_DECREF(xml_array);
}
Esempio n. 12
0
static int
unenroll_host(const char *server, const char *hostname, const char *ktname, int quiet)
{
    int rval = 0;
    int ret;
    char *ipaserver = NULL;
    char *host = NULL;
    struct utsname uinfo;
    char *principal = NULL;
    char *realm = NULL;

    krb5_context krbctx = NULL;
    krb5_keytab keytab = NULL;
    krb5_ccache ccache = NULL;
    krb5_principal princ = NULL;
    krb5_error_code krberr;
    krb5_creds creds;
    krb5_get_init_creds_opt gicopts;
    char tgs[LINE_MAX];

    xmlrpc_env env;
    xmlrpc_value * argArrayP = NULL;
    xmlrpc_value * paramArrayP = NULL;
    xmlrpc_value * paramP = NULL;
    xmlrpc_value * resultP = NULL;
    xmlrpc_server_info * serverInfoP = NULL;
    xmlrpc_value *princP = NULL;
    char * url = NULL;
    char * user_agent = NULL;

    if (server) {
        ipaserver = strdup(server);
    } else {
        char * conf_data = read_config_file(IPA_CONFIG);
        if ((ipaserver = getIPAserver(conf_data)) == NULL) {
            if (!quiet)
                fprintf(stderr, _("Unable to determine IPA server from %s\n"),
                        IPA_CONFIG);
            exit(1);
        }
        free(conf_data);
    }

    if (NULL == hostname) {
        uname(&uinfo);
        host = strdup(uinfo.nodename);
    } else {
        host = strdup(hostname);
    }

    if (NULL == strstr(host, ".")) {
        if (!quiet)
            fprintf(stderr, _("The hostname must be fully-qualified: %s\n"),
                    host);
        rval = 16;
        goto cleanup;
    }

    krberr = krb5_init_context(&krbctx);
    if (krberr) {
        if (!quiet)
            fprintf(stderr, _("Unable to join host: "
                              "Kerberos context initialization failed\n"));
        rval = 1;
        goto cleanup;
    }
    krberr = krb5_kt_resolve(krbctx, ktname, &keytab);
    if (krberr != 0) {
        if (!quiet)
            fprintf(stderr, _("Error resolving keytab: %s.\n"),
                error_message(krberr));
        rval = 7;
        goto cleanup;
    }

    krberr = krb5_get_default_realm(krbctx, &realm);
    if (krberr != 0) {
        if (!quiet)
            fprintf(stderr, _("Error getting default Kerberos realm: %s.\n"),
                error_message(krberr));
        rval = 21;
        goto cleanup;
    }

    ret = asprintf(&principal, "host/%s@%s", host,  realm);
    if (ret == -1)
    {
        if (!quiet)
            fprintf(stderr, _("Out of memory!\n"));
        rval = 3;
        goto cleanup;
    }

    krberr = krb5_parse_name(krbctx, principal, &princ);
    if (krberr != 0) {
        if (!quiet)
            fprintf(stderr, _("Error parsing \"%1$s\": %2$s.\n"),
                            principal, error_message(krberr));
        return krberr;
    }
    strcpy(tgs, KRB5_TGS_NAME);
    snprintf(tgs + strlen(tgs), sizeof(tgs) - strlen(tgs), "/%.*s",
             (krb5_princ_realm(krbctx, princ))->length,
             (krb5_princ_realm(krbctx, princ))->data);
    snprintf(tgs + strlen(tgs), sizeof(tgs) - strlen(tgs), "@%.*s",
             (krb5_princ_realm(krbctx, princ))->length,
             (krb5_princ_realm(krbctx, princ))->data);
    memset(&creds, 0, sizeof(creds));
    krb5_get_init_creds_opt_init(&gicopts);
    krb5_get_init_creds_opt_set_forwardable(&gicopts, 1);
    krberr = krb5_get_init_creds_keytab(krbctx, &creds, princ, keytab,
                                      0, tgs, &gicopts);
    if (krberr != 0) {
        if (!quiet)
            fprintf(stderr, _("Error obtaining initial credentials: %s.\n"),
                    error_message(krberr));
        return krberr;
    }

    krberr = krb5_cc_resolve(krbctx, "MEMORY:ipa-join", &ccache);
    if (krberr == 0) {
        krberr = krb5_cc_initialize(krbctx, ccache, creds.client);
    } else {
        if (!quiet)
            fprintf(stderr,
                    _("Unable to generate Kerberos Credential Cache\n"));
        rval = 19;
        goto cleanup;
    }
    krberr = krb5_cc_store_cred(krbctx, ccache, &creds);
    if (krberr != 0) {
        if (!quiet)
            fprintf(stderr,
                    _("Error storing creds in credential cache: %s.\n"),
                    error_message(krberr));
        return krberr;
    }
    krb5_cc_close(krbctx, ccache);
    ccache = NULL;
    putenv("KRB5CCNAME=MEMORY:ipa-join");

    /* Start up our XML-RPC client library. */
    xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION);

    xmlrpc_env_init(&env);

    xmlrpc_client_setup_global_const(&env);

#if 1
    ret = asprintf(&url, "https://%s:443/ipa/xml", ipaserver);
#else
    ret = asprintf(&url, "http://%s:8888/", ipaserver);
#endif
    if (ret == -1)
    {
        if (!quiet)
            fprintf(stderr, _("Out of memory!\n"));
        rval = 3;
        goto cleanup;
    }
    serverInfoP = xmlrpc_server_info_new(&env, url);

    argArrayP = xmlrpc_array_new(&env);
    paramArrayP = xmlrpc_array_new(&env);

    paramP = xmlrpc_string_new(&env, host);
    xmlrpc_array_append_item(&env, argArrayP, paramP);
    xmlrpc_array_append_item(&env, paramArrayP, argArrayP);
    xmlrpc_DECREF(paramP);

    if ((user_agent = set_user_agent(ipaserver)) == NULL) {
        rval = 3;
        goto cleanup;
    }
    callRPC(user_agent, &env, serverInfoP, "host_disable", paramArrayP, &resultP);
    if (handle_fault(&env)) {
        rval = 17;
        goto cleanup;
    }

    xmlrpc_struct_find_value(&env, resultP, "result", &princP);
    if (princP) {
        xmlrpc_bool result;

        xmlrpc_read_bool(&env, princP, &result);
        if (result == 1) {
            if (!quiet)
                fprintf(stderr, _("Unenrollment successful.\n"));
        } else {
            if (!quiet)
                fprintf(stderr, _("Unenrollment failed.\n"));
        }

        xmlrpc_DECREF(princP);
    } else {
        fprintf(stderr, _("result not found in XML-RPC response\n"));
        rval = 20;
        goto cleanup;
    }

cleanup:

    free(user_agent);
    if (keytab) krb5_kt_close(krbctx, keytab);
    free((char *)principal);
    free((char *)ipaserver);
    if (princ) krb5_free_principal(krbctx, princ);
    if (ccache) krb5_cc_close(krbctx, ccache);
    if (krbctx) krb5_free_context(krbctx);

    free(url);
    xmlrpc_env_clean(&env);
    xmlrpc_client_cleanup();

    return rval;
}
Esempio n. 13
0
void getDataBlock(xmlrpc_env *   envP,
                 xmlrpc_value *  DataStructP,
                 xmlrpc_value ** OutDataStructPP) {

  xmlrpc_value * ID_t, * PORT_t, * DATA_t, * IP_t;
  xmlrpc_struct_find_value(envP, DataStructP, "ID", &ID_t);
  xmlrpc_struct_find_value(envP, DataStructP, "IP", &IP_t);
  xmlrpc_struct_find_value(envP, DataStructP, "PORT", &PORT_t);
  xmlrpc_struct_find_value(envP, DataStructP, "DATA", &DATA_t);

  xmlrpc_int ID, PORT, DATA;
  char* IP;

  xmlrpc_read_int(envP, ID_t, &ID);
  xmlrpc_read_string(envP, IP_t, &IP);
  xmlrpc_read_int(envP, PORT_t, &PORT);
  xmlrpc_read_int(envP, DATA_t, &DATA);
	      
  xmlrpc_DECREF(ID_t);
  xmlrpc_DECREF(IP_t);
  xmlrpc_DECREF(PORT_t);
  xmlrpc_DECREF(DATA_t);
  
  printf("The value of ID is %d\n", ID);
  printf("The value of ID is %s\n", IP);
  printf("The value of PORT is %d\n", PORT);
  printf("The value of DATA is %d\n", DATA);

  xmlrpc_value * ID_out, * IP_out, * PORT_out, * DATA_out, *DATAP_out;
  xmlrpc_value * ID1_out, * IP1_out, * PORT1_out, * DATA1_out, *DATAP1_out;
  xmlrpc_value * ID2_out, * IP2_out, * PORT2_out, * DATA2_out, *DATAP2_out;
  xmlrpc_value * structArray;

  structArray = xmlrpc_array_new(envP);

  ID_out = xmlrpc_int_new(envP, 78654);
  IP_out = xmlrpc_string_new(envP, "127.0.0.1");
  PORT_out  = xmlrpc_int_new(envP, 8090);
  DATA_out  = xmlrpc_int_new(envP, 45425);

  ID1_out = xmlrpc_int_new(envP, 78764);
  IP1_out = xmlrpc_string_new(envP, "127.0.0.1");
  PORT1_out  = xmlrpc_int_new(envP, 8091);
  DATA1_out  = xmlrpc_int_new(envP, 452135);

  ID2_out = xmlrpc_int_new(envP, 78123);
  IP2_out = xmlrpc_string_new(envP, "127.0.0.1");
  PORT2_out  = xmlrpc_int_new(envP, 8092);
  DATA2_out  = xmlrpc_int_new(envP, 45563);

  DATAP_out = xmlrpc_struct_new(envP);
  DATAP1_out = xmlrpc_struct_new(envP);
  DATAP2_out = xmlrpc_struct_new(envP);
  
  xmlrpc_struct_set_value(envP, DATAP_out, "ID", ID_out);
  xmlrpc_struct_set_value(envP, DATAP_out, "IP", IP_out);
  xmlrpc_struct_set_value(envP, DATAP_out, "PORT",  PORT_out);
  xmlrpc_struct_set_value(envP, DATAP_out, "DATA",  DATA_out);

  xmlrpc_struct_set_value(envP, DATAP1_out, "ID", ID1_out);
  xmlrpc_struct_set_value(envP, DATAP1_out, "IP", IP1_out);
  xmlrpc_struct_set_value(envP, DATAP1_out, "PORT",  PORT1_out);
  xmlrpc_struct_set_value(envP, DATAP1_out, "DATA",  DATA1_out);
  
  xmlrpc_struct_set_value(envP, DATAP2_out, "ID", ID2_out);
  xmlrpc_struct_set_value(envP, DATAP2_out, "IP", IP2_out);
  xmlrpc_struct_set_value(envP, DATAP2_out, "PORT",  PORT2_out);
  xmlrpc_struct_set_value(envP, DATAP2_out, "DATA",  DATA2_out);

  xmlrpc_array_append_item(envP, structArray, DATAP_out);
  xmlrpc_array_append_item(envP, structArray, DATAP1_out);
  xmlrpc_array_append_item(envP, structArray, DATAP2_out);

  xmlrpc_DECREF(ID_out);
  xmlrpc_DECREF(IP_out);
  xmlrpc_DECREF(PORT_out);
  xmlrpc_DECREF(DATA_out);
  xmlrpc_DECREF(ID1_out);
  xmlrpc_DECREF(IP1_out);
  xmlrpc_DECREF(PORT1_out);
  xmlrpc_DECREF(DATA1_out);
  xmlrpc_DECREF(ID2_out);
  xmlrpc_DECREF(IP2_out);
  xmlrpc_DECREF(PORT2_out);
  xmlrpc_DECREF(DATA2_out);
	
  *OutDataStructPP = structArray;
}
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);
}
Esempio n. 15
0
static int
join_krb5(const char *ipaserver, char *hostname, char **hostdn, const char **princ, const char **subject, int force, int quiet) {
    xmlrpc_env env;
    xmlrpc_value * argArrayP = NULL;
    xmlrpc_value * paramArrayP = NULL;
    xmlrpc_value * paramP = NULL;
    xmlrpc_value * optionsP = NULL;
    xmlrpc_value * resultP = NULL;
    xmlrpc_value * structP = NULL;
    xmlrpc_server_info * serverInfoP = NULL;
    struct utsname uinfo;
    xmlrpc_value *princP = NULL;
    xmlrpc_value *krblastpwdchangeP = NULL;
    xmlrpc_value *subjectP = NULL;
    xmlrpc_value *hostdnP = NULL;
    const char *krblastpwdchange = NULL;
    char * url = NULL;
    char * user_agent = NULL;
    int rval = 0;
    int ret;

    *hostdn = NULL;
    *subject = NULL;
    *princ = NULL;

    /* Start up our XML-RPC client library. */
    xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION);

    uname(&uinfo);

    xmlrpc_env_init(&env);

    xmlrpc_client_setup_global_const(&env);

#if 1
    ret = asprintf(&url, "https://%s:443/ipa/xml", ipaserver);
#else
    ret = asprintf(&url, "http://%s:8888/", ipaserver);
#endif
    if (ret == -1)
    {
        if (!quiet)
            fprintf(stderr, _("Out of memory!\n"));
        rval = 3;
        goto cleanup;
    }

    serverInfoP = xmlrpc_server_info_new(&env, url);

    argArrayP = xmlrpc_array_new(&env);
    paramArrayP = xmlrpc_array_new(&env);

    if (hostname == NULL)
        paramP = xmlrpc_string_new(&env, uinfo.nodename);
    else
        paramP = xmlrpc_string_new(&env, hostname);
    xmlrpc_array_append_item(&env, argArrayP, paramP);
#ifdef REALM
    if (!quiet)
        printf("Joining %s to IPA realm %s\n", uinfo.nodename, iparealm);
#endif
    xmlrpc_array_append_item(&env, paramArrayP, argArrayP);
    xmlrpc_DECREF(paramP);

    optionsP = xmlrpc_build_value(&env, "{s:s,s:s}",
                                  "nsosversion", uinfo.release,
                                  "nshardwareplatform", uinfo.machine);
    xmlrpc_array_append_item(&env, paramArrayP, optionsP);
    xmlrpc_DECREF(optionsP);

    if ((user_agent = set_user_agent(ipaserver)) == NULL) {
        rval = 3;
        goto cleanup;
    }
    callRPC(user_agent, &env, serverInfoP, "join", paramArrayP, &resultP);
    if (handle_fault(&env)) {
        rval = 17;
        goto cleanup_xmlrpc;
    }

    /* Return value is the form of an array. The first value is the
     * DN, the second a struct of attribute values
     */
    xmlrpc_array_read_item(&env, resultP, 0, &hostdnP);
    xmlrpc_read_string(&env, hostdnP, (const char **)hostdn);
    xmlrpc_DECREF(hostdnP);
    xmlrpc_array_read_item(&env, resultP, 1, &structP);

    xmlrpc_struct_find_value(&env, structP, "krbprincipalname", &princP);
    if (princP) {
        xmlrpc_value * singleprincP = NULL;

        /* FIXME: all values are returned as lists currently. Once this is
         * fixed we can read the string directly.
         */
        xmlrpc_array_read_item(&env, princP, 0, &singleprincP);
        xmlrpc_read_string(&env, singleprincP, &*princ);
        xmlrpc_DECREF(princP);
        xmlrpc_DECREF(singleprincP);
    } else {
        if (!quiet)
            fprintf(stderr, _("principal not found in XML-RPC response\n"));
        rval = 12;
        goto cleanup;
    }
    xmlrpc_struct_find_value(&env, structP, "krblastpwdchange", &krblastpwdchangeP);
    if (krblastpwdchangeP && !force) {
        xmlrpc_value * singleprincP = NULL;

        /* FIXME: all values are returned as lists currently. Once this is
         * fixed we can read the string directly.
         */
        xmlrpc_array_read_item(&env, krblastpwdchangeP, 0, &singleprincP);
        xmlrpc_read_string(&env, singleprincP, &krblastpwdchange);
        xmlrpc_DECREF(krblastpwdchangeP);
        if (!quiet)
            fprintf(stderr, _("Host is already joined.\n"));
        rval = 13;
        goto cleanup;
    }

    xmlrpc_struct_find_value(&env, structP, "ipacertificatesubjectbase", &subjectP);
    if (subjectP) {
        xmlrpc_value * singleprincP = NULL;

        /* FIXME: all values are returned as lists currently. Once this is
         * fixed we can read the string directly.
         */
        xmlrpc_array_read_item(&env, subjectP, 0, &singleprincP);
        xmlrpc_read_string(&env, singleprincP, *&subject);
        xmlrpc_DECREF(subjectP);
    }

cleanup:
    if (argArrayP) xmlrpc_DECREF(argArrayP);
    if (paramArrayP) xmlrpc_DECREF(paramArrayP);
    if (resultP) xmlrpc_DECREF(resultP);

cleanup_xmlrpc:
    free(user_agent);
    free(url);
    free((char *)krblastpwdchange);
    xmlrpc_env_clean(&env);
    xmlrpc_client_cleanup();

    return rval;
}
Esempio n. 16
0
/*
 *	Write accounting information to this modules database.
 */
static int xmlrpc_accounting(void *instance, REQUEST * request)
{
	rlm_xmlrpc_t *inst = instance;
	rlm_xmlrpc_client_t *client;
	VALUE_PAIR *vps = request->packet->vps;

	xmlrpc_value *array_param;
	xmlrpc_value *array_string;
	xmlrpc_value *resultP;

	char *const methodName = inst->method;
	int error;

	VALUE_PAIR *status_type_pair;
	if ((status_type_pair = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE)) == NULL) {
		radlog(L_ERR, "rlm_xmlrpc: No Accounting-Status-Type record.");
		return RLM_MODULE_NOOP;
	}

	client = get_client(instance);

	/*
	 * Xmlrpc wants method params in an array, so we build an array
	 * with a pointer in index 0. This pointer contains a sub array
	 * filled whith strings each one for packet attributes.
	 */
	array_param = xmlrpc_array_new(&client->env);
	error = check_error(&client->env);
	if (error != RLM_MODULE_OK)
		return error;

	array_string = xmlrpc_array_new(&client->env);
	error = check_error(&client->env);
	if (error != RLM_MODULE_OK)
		return error;

	/*
	 * The array of strings is built whit vp_prints
	 */
	VALUE_PAIR *vp = vps;
	for (; vp; vp = vp->next) {
		char buf[1024];
		vp_prints(buf, sizeof(buf), vp);
		xmlrpc_array_append_item(&client->env, array_string,
					 xmlrpc_string_new(&client->env, buf));
		int error = check_error(&client->env);
		if (error != RLM_MODULE_OK)
			return error;
	}

	xmlrpc_array_append_item(&client->env, array_param, array_string);
	error = check_error(&client->env);
	if (error != RLM_MODULE_OK)
		return error;

	xmlrpc_client_call2(&client->env, client->clientP, client->serverInfoP,
			    methodName, array_param, &resultP);
	error = check_error(&client->env);
	if (error != RLM_MODULE_OK)
		return error;

	/*
	 * We don't check for method return value. If an accounting packet is
	 * dispatched without errors, it should be processed by server 
	 * without any further notification.
	 */

	xmlrpc_DECREF(resultP);
	xmlrpc_DECREF(array_param);
	xmlrpc_DECREF(array_string);

	return RLM_MODULE_OK;
}
Esempio n. 17
0
xmlrpc_value *xmlrpccmd_core_get_version(xmlrpc_env * const envP, xmlrpc_value * const paramArrayP, void * const userData) {

	return xmlrpc_string_new(envP, VERSION);
}
Esempio n. 18
0
int bugzilla_submit_bug(BugzillaData *data,
						const char *product,
						const char *component,
						const char *summary,
						const char *version,
						const char *description,
						const char *op_sys,
						const char *platform,
						const char *priority,
						const char *severity,
						const char *cc)
{
	E_ASSERT(data != NULL);

	int bug_id = -1;
	xmlrpc_value *result;

	/* if given CC, add it so bugzilla assign that email as notification receiver */
	if(cc) {
		/* as for now we only support single email address */
		xmlrpc_value *cc_array, *cc_str;

		cc_array = xmlrpc_array_new(&data->xenv);
		cc_str = xmlrpc_string_new(&data->xenv, (const char *const)cc);
		xmlrpc_array_append_item(&data->xenv, cc_array, cc_str);
		xmlrpc_DECREF(cc_str);

		xmlrpc_client_call2f(&data->xenv, data->xcli, data->url.c_str(), "Bug.create", &result,
							 "({s:s,s:s,s:s,s:s,s:s,s:s,s:s,s:s,s:s,s:A})",
							 "product", product,
							 "component", component,
							 "summary", summary,
							 "version", version,
							 "description", description,
							 "op_sys", op_sys,
							 "platform", platform,
							 "priority", priority,
							 "severity", severity,
							 "cc", cc_array);
		xmlrpc_DECREF(cc_array);
	} else {
		xmlrpc_client_call2f(&data->xenv, data->xcli, data->url.c_str(), "Bug.create", &result,
							 "({s:s,s:s,s:s,s:s,s:s,s:s,s:s,s:s,s:s})",
							 "product", product,
							 "component", component,
							 "summary", summary,
							 "version", version,
							 "description", description,
							 "op_sys", op_sys,
							 "platform", platform,
							 "priority", priority,
							 "severity", severity);
	}

	if(data->xenv.fault_occurred) {
		E_WARNING(E_STRLOC ": Unable to perform submit function (%s)\n", data->xenv.fault_string);
		if(data->cb) (data->cb)(data->xenv.fault_string, data->cb_data);
		return bug_id;
	}

	xmlrpc_decompose_value(&data->xenv, result, "{s:i,*}", "id", &bug_id);
	xmlrpc_DECREF(result);

	return bug_id;
}
Esempio n. 19
0
node_t * xmlrpc_client_callmethod(const char * serverUrl, const char * methodName, unsigned int argVersion){

    xmlrpc_env env;

    xmlrpc_env_init(&env);
    xmlrpc_client_init2(&env, XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION, NULL, 0);
    dieIfFailed("Client initialization", &env);

    xmlrpc_value * ID, * PORT, * DATA, * DATAP, * IP;
    
    ID = xmlrpc_int_new(&env, 23121);
    IP = xmlrpc_string_new(&env, "127.0.0.1");
    PORT  = xmlrpc_int_new(&env, 8085);
    DATA  = xmlrpc_int_new(&env, 123);

    DATAP = xmlrpc_struct_new(&env);

    xmlrpc_struct_set_value(&env, DATAP, "ID", ID);
    xmlrpc_struct_set_value(&env, DATAP, "IP", IP);
    xmlrpc_struct_set_value(&env, DATAP, "PORT",  PORT);
    xmlrpc_struct_set_value(&env, DATAP, "DATA",  DATA);
        
    xmlrpc_DECREF(ID);
    xmlrpc_DECREF(IP);
    xmlrpc_DECREF(PORT);
    xmlrpc_DECREF(DATA);

    /* Make the call */
    xmlrpc_value * resultArray = xmlrpc_client_call(&env, serverUrl, methodName, "(iS)", (xmlrpc_int32) argVersion, DATAP);

    xmlrpc_value * OutID_t, *OutPORT_t, *OutDATA_t, *OutIP_t;
    xmlrpc_int OutID, OutPORT, OutDATA;
    char * OutIP;

    unsigned int const resultCt = xmlrpc_array_size(&env, resultArray);
    unsigned int i;
    
    node_t * resultnode = (node_t *) malloc(3*sizeof(node_t));

    for(i = 0; i < resultCt; ++i){
      xmlrpc_value * resultP;
      xmlrpc_array_read_item(&env, resultArray, i, &resultP);

      xmlrpc_struct_find_value(&env, resultP, "ID", &OutID_t);
      xmlrpc_struct_find_value(&env, resultP, "IP", &OutIP_t);
      xmlrpc_struct_find_value(&env, resultP, "PORT", &OutPORT_t);
      xmlrpc_struct_find_value(&env, resultP, "DATA", &OutDATA_t);
      
      xmlrpc_read_int(&env, OutID_t, &OutID);
      xmlrpc_read_string(&env, OutIP_t, &OutIP);
      xmlrpc_read_int(&env, OutPORT_t, &OutPORT);
      xmlrpc_read_int(&env, OutDATA_t, &OutDATA);
      
      resultnode[i].ID = OutID;
      strcpy(resultnode[i].IP, OutIP);
      resultnode[i].PORT = OutPORT;
      resultnode[i].DATA = OutDATA;
    }
    xmlrpc_env_clean(&env);
    xmlrpc_client_cleanup();


    return resultnode;
}