コード例 #1
0
ファイル: roadmap-engine.c プロジェクト: alvaropg/roadmap
static gboolean
do_xmlrpc (SoupSession *session, const char *method, GValue *retval, ...)
{
	SoupMessage *msg;
	va_list args;
	GValueArray *params;
	GError *err = NULL;
	char *body;
	int i;

	va_start (args, retval);
	params = soup_value_array_from_args (args);
	va_end (args);

	/*
	for (i = 0; i < params->n_values; i++) {
		g_print ("param: %s\n", g_value_get_string (g_value_array_get_nth (params, i)));
	}
	*/
	
	body = soup_xmlrpc_build_method_call (method, params->values,
										  params->n_values);
	g_value_array_free (params);
	if (!body)
		return FALSE;

	msg = soup_message_new ("POST", "http://dev.map.es/trac/acceda/login/xmlrpc");
	soup_message_set_request (msg, "text/xml", SOUP_MEMORY_TAKE, body, strlen (body));
	soup_session_send_message (session, msg);

	if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
		g_print ("ERROR: %d %s\n", msg->status_code,
			      msg->reason_phrase);
		g_object_unref (msg);
		return FALSE;
	}

	if (!soup_xmlrpc_parse_method_response (msg->response_body->data,
						msg->response_body->length,
						retval, &err)) {
		if (err) {
			g_print ("%s", body);
			g_print ("FAULT: %d %s\n", err->code, err->message);
			g_error_free (err);
		} else
			g_print ("ERROR: could not parse response\n");
		g_object_unref (msg);
		return FALSE;
	}
	g_object_unref (msg);

	return TRUE;
}
コード例 #2
0
static gchar* send_xmlrpc (const gchar *uri, const gchar *method, GValue *result, ...)
{
	// Create an XMLRPC request from the arguments
	va_list args;
	va_start (args, result);
	GValueArray *params = soup_value_array_from_args (args);
	va_end (args);
	char *body = soup_xmlrpc_build_method_call (method, params->values, params->n_values);
	g_value_array_free (params);

	if (!body)
		return g_strdup("Could not create XMLRPC method call");

	// Create and send the actual request message
	SoupMessage *msg = soup_message_new ("POST", uri);
	soup_message_set_request (msg, "text/xml", SOUP_MEMORY_TAKE, body, strlen(body));
	soup_session_send_message (session, msg);

	if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
	{
		gchar *retval = g_strdup_printf("Request failed: %s", msg->reason_phrase);
		g_object_unref (msg);
		return retval;
	}

	// Parse the XMLRPC response
	GError *err = NULL;
	if (!soup_xmlrpc_parse_method_response (msg->response_body->data, msg->response_body->length, result, &err))
	{
		gchar *retval = NULL;
		if (err)
		{
			retval = g_strdup_printf("Error: %s", err->message);
			g_error_free (err);
		}
		else
		{
			retval = g_strdup("Could not parse XMLRPC response");
		}
		g_object_unref (msg);
		return retval;
	}
	g_object_unref (msg);

	return NULL;
}
コード例 #3
0
ファイル: xmlrpc-test.c プロジェクト: BabaNina/libsoup
static gboolean
do_xmlrpc (const char *method, GValue *retval, ...)
{
	SoupMessage *msg;
	va_list args;
	GValueArray *params;
	GError *err = NULL;
	char *body;

	va_start (args, retval);
	params = soup_value_array_from_args (args);
	va_end (args);

	body = soup_xmlrpc_build_method_call (method, params->values,
					      params->n_values);
	g_value_array_free (params);
	if (!body)
		return FALSE;

	msg = soup_message_new ("POST", uri);
	soup_message_set_request (msg, "text/xml", SOUP_MEMORY_TAKE,
				  body, strlen (body));
	soup_session_send_message (session, msg);

	if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
		debug_printf (1, "ERROR: %d %s\n", msg->status_code,
			      msg->reason_phrase);
		g_object_unref (msg);
		return FALSE;
	}

	if (!soup_xmlrpc_parse_method_response (msg->response_body->data,
						msg->response_body->length,
						retval, &err)) {
		if (err) {
			debug_printf (1, "FAULT: %d %s\n", err->code, err->message);
			g_error_free (err);
		} else
			debug_printf (1, "ERROR: could not parse response\n");
		g_object_unref (msg);
		return FALSE;
	}
	g_object_unref (msg);

	return TRUE;
}
コード例 #4
0
ファイル: xmlrpc-test.c プロジェクト: BabaNina/libsoup
static gboolean
do_bad_xmlrpc (const char *body)
{
	SoupMessage *msg;
	GError *err = NULL;
	GValue retval;

	msg = soup_message_new ("POST", uri);
	soup_message_set_request (msg, "text/xml", SOUP_MEMORY_COPY,
				  body, strlen (body));
	soup_session_send_message (session, msg);

	if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
		debug_printf (1, "ERROR: %d %s\n", msg->status_code,
			      msg->reason_phrase);
		g_object_unref (msg);
		return FALSE;
	}

	if (!soup_xmlrpc_parse_method_response (msg->response_body->data,
						msg->response_body->length,
						&retval, &err)) {
		if (err) {
			debug_printf (1, "FAULT: %d %s (OK!)\n",
				      err->code, err->message);
			g_error_free (err);
			g_object_unref (msg);
			return TRUE;
		} else
			debug_printf (1, "ERROR: could not parse response\n");
	} else
		debug_printf (1, "Unexpectedly got successful response!\n");

	g_object_unref (msg);
	return FALSE;
}
コード例 #5
0
static gboolean
do_xmlrpc (SoupSession *session, const gchar *uri, const gchar *method,
           GError **error, GValue *retval, ...)
{
  SoupMessage *msg;
  va_list args;
  GArray *params = g_array_sized_new(FALSE, FALSE, sizeof(GValue), 1);
  GError *err = NULL;
  char *body;
  GType type;
  GValue val;

  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  va_start (args, retval);

  //copy soup_value_array_from_args() in here and change datatypes respectivly
  while ((type = va_arg (args, GType)) != G_TYPE_INVALID)
  {
    SOUP_VALUE_SETV (&val, type, args);
    g_array_append_val (params, val);
  }

  va_end (args);

  body = soup_xmlrpc_build_method_call (method, (GValue*)params->data,
                                   params->len);
  g_array_unref (params);

  if (!body)
    {
      err = g_error_new (SOUP_XMLRPC_FAULT,
                         SOUP_XMLRPC_FAULT_APPLICATION_ERROR,
                         _("An error occurred when creating the XMLRPC"
                           " request."));
      g_propagate_error (error, err);

      return FALSE;
    }

  msg = soup_message_new ("POST", uri);
  soup_message_set_request (msg, "text/xml", SOUP_MEMORY_TAKE,
                            body, strlen (body));
  soup_session_send_message (session, msg);

  if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
    {
      TRACE ("Error during the XMLRPC exchange: %d %s\n",
             msg->status_code, msg->reason_phrase);

      err = g_error_new (SOUP_XMLRPC_FAULT,
                         SOUP_XMLRPC_FAULT_TRANSPORT_ERROR,
                         _("An error occurred when transferring the data"
                           " to ZimageZ."));
      g_propagate_error (error, err);
      g_object_unref (msg);

      return FALSE;
    }

  if (!soup_xmlrpc_parse_method_response (msg->response_body->data,
                                          msg->response_body->length,
                                          retval, &err))
    {
      if (err)
        {
          TRACE ("Fault when parsing the response: %d %s\n",
                 err->code, err->message);

          g_propagate_error (error, err);
        }
      else
        {
          TRACE ("Unable to parse the response, and no error...");

          err = g_error_new (SOUP_XMLRPC_FAULT,
                             SOUP_XMLRPC_FAULT_APPLICATION_ERROR,
                             _("An error occurred when parsing the response"
                               " from ZimageZ."));
          g_propagate_error (error, err);
        }

      g_object_unref (msg);
      return FALSE;
    }

  g_object_unref (msg);

  return TRUE;
}