Ejemplo n.º 1
0
static void
multipart_handling_cb (GObject *source, GAsyncResult *res, gpointer data)
{
    GMainLoop *loop = (GMainLoop*)data;
    SoupRequest *request = SOUP_REQUEST (source);
    GError *error = NULL;
    GInputStream *in;
    SoupMessage *message;

    in = soup_request_send_finish (request, res, &error);
    message = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
    multipart = soup_multipart_input_stream_new (message, in);
    g_object_unref (message);
    g_object_unref (in);

    if (error) {
        debug_printf (1, "  failed send: %s\n", error->message);
        errors++;

        g_main_loop_quit (loop);
        return;
    }

    if (g_object_get_data (source, "multipart-small-reads"))
        g_object_set_data (G_OBJECT (multipart), "multipart-small-reads", GINT_TO_POINTER(1));

    soup_multipart_input_stream_next_part_async (multipart, G_PRIORITY_DEFAULT, NULL,
            multipart_next_part_cb, data);
}
Ejemplo n.º 2
0
static void
gdav_request_send (SoupRequestHTTP *request,
                   GCancellable *cancellable,
                   GAsyncReadyCallback callback,
                   gpointer user_data)
{
	GTask *task;
	SoupMessage *message;

	/* This is an internal wrapper for soup_request_send_async().
	 * The input stream contents are written to the SoupMessage
	 * response body to ensure a SoupLogger sees it. */

	task = g_task_new (request, cancellable, callback, user_data);

	message = soup_request_http_get_message (request);
	g_task_set_task_data (task, message, g_object_unref);

	soup_request_send_async (
		SOUP_REQUEST (request),
		cancellable,
		gdav_request_send_cb,
		g_object_ref (task));

	g_object_unref (task);
}
Ejemplo n.º 3
0
static GByteArray *
do_single_coding_req_test (SoupRequest *req,
			   const char *expected_encoding,
			   const char *expected_content_type,
			   MessageContentStatus status)
{
	GInputStream *stream;
	SoupMessage *msg;
	GByteArray *data;
	guchar buf[1024];
	gssize nread;
	GError *error = NULL;

	data = g_byte_array_new ();

	msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));

	stream = soup_test_request_send (req, NULL, &error);
	if (error) {
		debug_printf (1, "    Error sending request: %s\n",
			      error->message);
		g_error_free (error);
		errors++;
		return data;
	}

	do {
		nread = -2;
		g_input_stream_read_async (stream, buf, sizeof (buf),
					   G_PRIORITY_DEFAULT,
					   NULL, read_finished, &nread);
		while (nread == -2)
			g_main_context_iteration (NULL, TRUE);

		if (nread > 0)
			g_byte_array_append (data, buf, nread);
	} while (nread > 0);

	soup_test_request_close_stream (req, stream, NULL, &error);
	if (error) {
		debug_printf (1, "    error closing stream: %s\n",
			      error->message);
		g_error_free (error);
		errors++;
	}
	g_object_unref (stream);

	check_response (msg, expected_encoding, expected_content_type, status);
	g_object_unref (msg);

	return data;
}
Ejemplo n.º 4
0
void
gdav_propfind (SoupSession *session,
               SoupURI *uri,
               GDavPropFindType type,
               GDavPropertySet *prop,
               GDavDepth depth,
               GCancellable *cancellable,
               GAsyncReadyCallback callback,
               gpointer user_data)
{
	GTask *task;
	SoupRequestHTTP *request;
	AsyncContext *async_context;
	GError *local_error = NULL;

	g_return_if_fail (SOUP_IS_SESSION (session));
	g_return_if_fail (uri != NULL);

	async_context = g_slice_new0 (AsyncContext);

	task = g_task_new (session, cancellable, callback, user_data);
	g_task_set_source_tag (task, gdav_propfind);

	g_task_set_task_data (
		task, async_context, (GDestroyNotify) async_context_free);

	request = gdav_request_propfind_uri (
		session, uri, type, prop, depth, &local_error);

	/* Sanity check */
	g_warn_if_fail (
		((request != NULL) && (local_error == NULL)) ||
		((request == NULL) && (local_error != NULL)));

	if (request != NULL) {
		async_context->message =
			soup_request_http_get_message (request);

		gdav_request_send (
			request, cancellable,
			gdav_propfind_request_cb,
			g_object_ref (task));

		g_object_unref (request);
	} else {
		g_task_return_error (task, local_error);
	}

	g_object_unref (task);
}
Ejemplo n.º 5
0
static void
do_coding_empty_test (void)
{
	SoupSession *session;
	SoupMessage *msg;
	SoupURI *uri;
	SoupRequester *requester;
	SoupRequest *req;
	GByteArray *body;

	debug_printf (1, "\nEmpty allegedly-encoded body test\n");

	session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
					 SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_DECODER,
					 SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
					 SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_REQUESTER,
					 NULL);
	requester = (SoupRequester *)soup_session_get_feature (session, SOUP_TYPE_REQUESTER);
	uri = soup_uri_new_with_base (base_uri, "/mbox");

	debug_printf (1, "  SoupMessage\n");
	msg = soup_message_new_from_uri ("GET", uri);
	soup_message_headers_append (msg->request_headers,
				     "X-Test-Options", "empty");
	soup_session_send_message (session, msg);
	check_response (msg, "gzip", "text/plain", EXPECT_NOT_DECODED);
	g_object_unref (msg);

	debug_printf (1, "  SoupRequest\n");
	req = soup_requester_request_uri (requester, uri, NULL);
	msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));
	soup_message_headers_append (msg->request_headers,
				     "X-Test-Options", "empty");
	g_object_unref (msg);
	body = do_single_coding_req_test (req, "gzip", "text/plain", EXPECT_NOT_DECODED);
	g_byte_array_free (body, TRUE);
	g_object_unref (req);

	soup_uri_free (uri);
	soup_test_session_abort_unref (session);
}
Ejemplo n.º 6
0
/*
 * our multipart handler callback
 * If we make an invalid request (like trying to cancel when no recipe is running)
 * then status_code will not be 200 and we will exit out after propagating the error
 * to our own GError
 */
static void
request_sent_cb (GObject *source, GAsyncResult *async_result, gpointer user_data)
{

    //g_print ("request_sent_cb\n");
    MultiPartData *multipart_data = (MultiPartData *) user_data;

    SoupRequest *request = SOUP_REQUEST (source);
    GInputStream *in = soup_request_send_finish (request,
                                                 async_result,
                                                 &multipart_data->error);
    if (multipart_data->error) {
        g_object_unref(request);
        multipart_destroy (multipart_data);
        return;
    }

    SoupMessage *message = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
    g_object_unref(request);

    if (message->status_code != SOUP_STATUS_OK) {
        g_set_error_literal(&multipart_data->error,
                            RESTRAINT_ERROR,
                            message->status_code,
                            message->reason_phrase);
        multipart_destroy (multipart_data);
        return;
    }

    multipart_data->multipart = soup_multipart_input_stream_new (message,
                                                                 in);
    g_object_unref (message);
    g_object_unref (in);

    soup_multipart_input_stream_next_part_async (multipart_data->multipart,
                                                 G_PRIORITY_DEFAULT,
                                                 multipart_data->cancellable,
                                                 next_part_cb,
                                                 user_data);
}
Ejemplo n.º 7
0
static void
get_url_now (GrlNetWc *self,
             const char *url,
             GHashTable *headers,
             GAsyncResult *result,
             GCancellable *cancellable)
{
  GrlNetWcPrivate *priv = self->priv;
  struct request_res *rr = g_slice_new0 (struct request_res);

  g_simple_async_result_set_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result),
                                             rr,
                                             NULL);

#ifdef LIBSOUP_REQUESTER_DEPRECATED
  SoupURI *uri = soup_uri_new (url);
  rr->request = soup_session_request_uri (priv->session, uri, NULL);
  soup_uri_free (uri);
#else
  rr->request = soup_requester_request (priv->requester, url, NULL);
#endif

  if (headers != NULL) {
    SoupMessage *message;
    GHashTableIter iter;
    const char *key, *value;

    message = soup_request_http_get_message (SOUP_REQUEST_HTTP (rr->request));

    if (message) {
      g_hash_table_iter_init (&iter, headers);
      while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *)&value)) {
        soup_message_headers_append (message->request_headers, key, value);
      }
      g_object_unref (message);
    }
  }

  soup_request_send_async (rr->request, cancellable, reply_cb, result);
}
Ejemplo n.º 8
0
static gboolean
do_one_attempt (gpointer user_data)
{
  GError *local_error = NULL;
  MinCloudAgentApp *self = user_data;
  gs_free char *uri_str = NULL;
  gs_unref_object SoupRequest *request = NULL;
  gs_unref_object GInputStream *instream = NULL;
  gs_unref_object GFileOutputStream *outstream = NULL;
  gs_unref_object GFile *authorized_keys_path = NULL;
  gs_unref_object SoupMessage *msg = NULL;
  SoupURI *uri = NULL;
  const int max_request_failures = 5;
  const char *state_description = NULL;

  /* Skip over already completed states */
 again:
  switch (self->state)
    {
    case MCA_STATE_USER_DATA:
      if (g_file_query_exists (self->userdata_done_stamp, NULL))
        {
          self->state++;
          goto again;
        }
      break;
    case MCA_STATE_OPENSSH_KEY:
      if (g_file_query_exists (self->authorized_keys_path, NULL))
        {
          self->state++;
          goto again;
        }
      break;
    case MCA_STATE_DONE:
      goto out;
    }

  uri = soup_uri_new (NULL);
  soup_uri_set_scheme (uri, "http");
  {
    gs_free char *addr_str = g_inet_address_to_string (self->addr);
    soup_uri_set_host (uri, addr_str);
  }
  soup_uri_set_port (uri, g_inet_socket_address_get_port (self->addr_port));
  switch (self->state)
    {
    case MCA_STATE_USER_DATA:
      soup_uri_set_path (uri, "/2009-04-04/user-data");
      state_description = "user-data";
      break;
    case MCA_STATE_OPENSSH_KEY:
      soup_uri_set_path (uri, "/2009-04-04/meta-data/public-keys/0/openssh-key");
      state_description = "openssh-key";
      break;
    case MCA_STATE_DONE:
      g_assert_not_reached ();
    }

  uri_str = soup_uri_to_string (uri, FALSE);
  g_print ("Requesting '%s'...\n", uri_str);

  request = soup_session_request_uri (self->session, uri, &local_error);
  soup_uri_free (uri);
  if (!request)
    goto out;

  instream = soup_request_send (request, NULL, &local_error);
  if (!instream)
    goto out;

  msg = soup_request_http_get_message ((SoupRequestHTTP*) request);
  if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
    {
      switch (msg->status_code)
        {
        case 404:
        case 410:
          {
            gs_log_structured_print_id_v (MCA_NOT_FOUND_ID, "No %s found", state_description);
            g_clear_error (&local_error);
            /* Note fallthrough to out, where we'll advance to the
               next state */
            goto out;
          }
        default:
          /* Don't actually set the error, we will just continue to
           * the next phase.
           */
          gs_log_structured_print_id_v (MCA_TIMEOUT_ID,
                                        "Error fetching %s: %u %s",
                                        uri_str,
                                        msg->status_code,
                                        soup_status_get_phrase (msg->status_code));
          goto out;
        }
    }

  switch (self->state)
    {
    case MCA_STATE_USER_DATA:
      if (!handle_userdata_script (self, instream, self->cancellable,
                                   &local_error))
        goto out;
      break;
    case MCA_STATE_OPENSSH_KEY:
      if (!handle_install_authorized_keys (self, instream, self->cancellable,
                                           &local_error))
        goto out;
      break;
    default:
      g_assert_not_reached ();
    }

  g_assert (self->state != MCA_STATE_DONE);
  self->state++;
  self->request_failure_count = 0;

 out:
  if (local_error)
    {
      self->request_failure_count++;
      if (self->request_failure_count >= max_request_failures)
        {
          g_error_free (local_error);
          gs_log_structured_print_id_v (MCA_TIMEOUT_ID,
                                        "Reached maximum failed attempts (%u) to fetch metadata",
                                        self->request_failure_count);
          self->do_one_attempt_id = 0;
          self->running = FALSE;
        }
      else
        {
          gs_log_structured_print_id_v (MCA_REQUEST_FAILED_ID,
                                        "Request failed (count: %u): %s", self->request_failure_count,
                                        local_error->message);
          g_error_free (local_error);
          self->do_one_attempt_id = g_timeout_add_seconds (self->request_failure_count,
                                                           do_one_attempt, self);
        }
    }
  else
    {
      /* If we advanced in state, schedule the next callback in an
       * idle so we're consistently scheduled out of an idle.
       */
      if (self->state != MCA_STATE_DONE)
        self->do_one_attempt_id = g_idle_add (do_one_attempt, self);
      else
        {
          self->do_one_attempt_id = 0;
          self->running = FALSE;
        }
    }

  return FALSE;
}
Ejemplo n.º 9
0
int main(int argc, char *argv[]) {

    AppData *app_data = g_slice_new0 (AppData);
    app_data->filename = g_strdup("resultoutputfile.log");
    app_data->outputfile = g_strdup(getenv("OUTPUTFILE"));
    app_data->disable_plugin = g_ptr_array_new_with_free_func (g_free);

    GError *error = NULL;

    gchar *server = NULL;
    SoupURI *result_uri = NULL;

    guint ret = 0;

    SoupMessage *server_msg;
    SoupRequest *request;

    gchar *result_msg = NULL;
    gchar *prefix = NULL;
    gchar *server_recipe_key = NULL;
    gchar *server_recipe = NULL;
    gchar *task_id = NULL;
    gchar *task_id_key = NULL;
    gboolean no_plugins = FALSE;

    gchar *form_data;
    GHashTable *data_table = g_hash_table_new (NULL, NULL);

    GOptionEntry entries[] = {
        {"server", 's', 0, G_OPTION_ARG_STRING, &server,
            "Server to connect to", "URL" },
        { "message", 't', 0, G_OPTION_ARG_STRING, &result_msg,
            "Short 100 characters or less message", "TEXT" },
        { "outputfile", 'o', 0, G_OPTION_ARG_CALLBACK, callback_outputfile,
            "Log to upload with result, $OUTPUTFILE is used by default", "FILE" },
        { "disable-plugin", 'p', 0, G_OPTION_ARG_CALLBACK, callback_disable_plugin,
            "don't run plugin on server side", "PLUGIN" },
        { "no-plugins", 0, 0, G_OPTION_ARG_NONE, &no_plugins,
            "don't run any plugins on server side", NULL },
        { NULL }
    };
    GOptionGroup *option_group = g_option_group_new ("main",
                                                    "Application Options",
                                                    "Various application related options",
                                                    app_data, NULL);

    GOptionContext *context = g_option_context_new("TASK_PATH RESULT SCORE");
    g_option_context_set_summary(context,
            "Report results to lab controller. if you don't specify the\n"
            "the server url you must have RECIPEID and TASKID defined.\n"
            "If HARNESS_PREFIX is defined then the value of that must be\n"
            "prefixed to RECIPEID and TASKID");
    g_option_group_add_entries(option_group, entries);
    g_option_context_set_main_group (context, option_group);

    gboolean parse_succeeded = g_option_context_parse(context, &argc, &argv, &error);

    if (!parse_succeeded) {
        goto cleanup;
    }

    prefix = getenv("HARNESS_PREFIX") ? getenv("HARNESS_PREFIX") : "";
    server_recipe_key = g_strdup_printf ("%sRECIPE_URL", prefix);
    server_recipe = getenv(server_recipe_key);
    task_id_key = g_strdup_printf ("%sTASKID", prefix);
    task_id = getenv(task_id_key);
    g_free(task_id_key);
    g_free(server_recipe_key);

    if (!server && server_recipe && task_id) {
        server = g_strdup_printf ("%s/tasks/%s/results/", server_recipe, task_id);
    }

    if (argc < 3 || !server) {
        cmd_usage(context);
        goto cleanup;
    }

    result_uri = soup_uri_new (server);
    if (result_uri == NULL) {
        g_set_error (&error, RESTRAINT_ERROR,
                     RESTRAINT_PARSE_ERROR_BAD_SYNTAX,
                     "Malformed server url: %s", server);
        goto cleanup;
    }
    session = soup_session_new_with_options("timeout", 3600, NULL);

    g_hash_table_insert (data_table, "path", argv[1]);
    g_hash_table_insert (data_table, "result", argv[2]);

    // if AVC_ERROR=+no_avc_check then disable the selinux check plugin
    // This is for legacy rhts tests.. please use --disable-plugin
    gchar *avc_error = getenv("AVC_ERROR");
    if (g_strcmp0 (avc_error, "+no_avc_check") == 0) {
        g_ptr_array_add (app_data->disable_plugin, g_strdup ("10_avc_check"));
    }

    if (app_data->disable_plugin->pdata) {
        g_hash_table_insert (data_table, "disable_plugin",
                             g_strjoinv (" ", (gchar **)app_data->disable_plugin->pdata));
    }
    if (no_plugins)
      g_hash_table_insert (data_table, "no_plugins", &no_plugins);
    if (argc > 3)
      g_hash_table_insert (data_table, "score", argv[3]);
    if (result_msg)
      g_hash_table_insert (data_table, "message", result_msg);

    request = (SoupRequest *)soup_session_request_http_uri (session, "POST", result_uri, &error);
    server_msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
    g_object_unref(request);
    form_data = soup_form_encode_hash (data_table);
    soup_message_set_request (server_msg, "application/x-www-form-urlencoded",
                              SOUP_MEMORY_TAKE, form_data, strlen (form_data));
    g_print ("** %s %s Score:%s\n", argv[1], argv[2], argv[3]);
    ret = soup_session_send_message (session, server_msg);
    if (SOUP_STATUS_IS_SUCCESSFUL (ret)) {
        gchar *location = g_strdup_printf ("%s/logs/",
                                           soup_message_headers_get_one (server_msg->response_headers, "Location"));
        soup_uri_free (result_uri);
        result_uri = soup_uri_new (location);
        g_free (location);
        if (app_data->outputfile != NULL &&
            g_file_test (app_data->outputfile, G_FILE_TEST_EXISTS))
        {
            g_print ("Uploading %s ", app_data->filename);
            if (upload_file (session, app_data->outputfile, app_data->filename, result_uri, &error)) {
                g_print ("done\n");
            } else {
                g_print ("failed\n");
            }
        }
    } else {
       g_warning ("Failed to submit result, status: %d Message: %s\n", ret, server_msg->reason_phrase);
    }
    g_object_unref(server_msg);
    soup_session_abort(session);
    g_object_unref(session);

cleanup:
    if (server != NULL) {
        g_free(server);
    }
    if (result_msg != NULL) {
        g_free(result_msg);
    }
    g_option_context_free(context);
    g_hash_table_destroy(data_table);
    if (result_uri != NULL) {
        soup_uri_free (result_uri);
    }
    restraint_free_appdata(app_data);
    if (error) {
        int retcode = error->code;
        g_printerr("%s [%s, %d]\n", error->message,
                g_quark_to_string(error->domain), error->code);
        g_clear_error(&error);
        return retcode;
    } else {
        return EXIT_SUCCESS;
    }
}
Ejemplo n.º 10
0
static void
read_async_cb (GObject *source,
               GAsyncResult *res,
               gpointer user_data)
{
  GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
  struct request_res *rr = g_simple_async_result_get_op_res_gpointer (result);;

  GError *error = NULL;
  gssize s = g_input_stream_read_finish (G_INPUT_STREAM (source), res, &error);

  gsize to_read;

  if (s > 0) {
    /* Continue reading */
    rr->offset += s;
    to_read = rr->length - rr->offset;

    if (!to_read) {
      /* Buffer is not enough; we need to assign more space */
      rr->length *= 2;
      rr->buffer = g_renew (gchar, rr->buffer, rr->length);
      to_read = rr->length - rr->offset;
    }

    g_input_stream_read_async (G_INPUT_STREAM (source),
                               rr->buffer + rr->offset,
                               to_read,
                               G_PRIORITY_DEFAULT,
                               NULL,
                               read_async_cb,
                               user_data);
    return;
  }

  /* Put the end of string */
  rr->buffer[rr->offset] = '\0';

  g_input_stream_close (G_INPUT_STREAM (source), NULL, NULL);

  if (error) {
    if (error->code == G_IO_ERROR_CANCELLED) {
      g_simple_async_result_set_error (result, GRL_NET_WC_ERROR,
                                       GRL_NET_WC_ERROR_CANCELLED,
                                       _("Operation was cancelled"));
    } else {
      g_simple_async_result_set_error (result, GRL_NET_WC_ERROR,
                                       GRL_NET_WC_ERROR_UNAVAILABLE,
                                       _("Data not available"));
    }

    g_error_free (error);

    g_simple_async_result_complete (result);
    g_object_unref (result);
    return;
  }

  {
    SoupMessage *msg =
      soup_request_http_get_message (SOUP_REQUEST_HTTP (rr->request));

    if (msg && msg->status_code != SOUP_STATUS_OK) {
        parse_error (msg->status_code,
                     msg->reason_phrase,
                     msg->response_body->data,
                     G_SIMPLE_ASYNC_RESULT (user_data));
        g_object_unref (msg);
    }
  }

  g_simple_async_result_complete (result);
  g_object_unref (result);
}
Ejemplo n.º 11
0
static void
do_coding_req_test (void)
{
	SoupSession *session;
	SoupRequester *requester;
	SoupRequest *req;
	SoupMessage *msg;
	SoupURI *uri;
	GByteArray *plain, *cmp;

	debug_printf (1, "\nSoupRequest tests\n");

	session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
					 SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
					 SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_REQUESTER,
					 NULL);
	requester = (SoupRequester *)soup_session_get_feature (session, SOUP_TYPE_REQUESTER);
	uri = soup_uri_new_with_base (base_uri, "/mbox");

	/* Plain text data, no claim */
	debug_printf (1, "  GET /mbox, plain\n");
	req = soup_requester_request_uri (requester, uri, NULL);
	plain = do_single_coding_req_test (req, NULL, "text/plain", EXPECT_NOT_DECODED);
	g_object_unref (req);

	/* Plain text data, claim gzip */
	debug_printf (1, "  GET /mbox, Accept-Encoding: gzip\n");
	soup_session_add_feature_by_type (session, SOUP_TYPE_CONTENT_DECODER);
	req = soup_requester_request_uri (requester, uri, NULL);
	cmp = do_single_coding_req_test (req, "gzip", "text/plain", EXPECT_DECODED);
	check_req_bodies (plain, cmp, "plain", "compressed");
	g_byte_array_free (cmp, TRUE);
	g_object_unref (req);

	/* Plain text data, claim gzip w/ junk */
	debug_printf (1, "  GET /mbox, Accept-Encoding: gzip, plus trailing junk\n");
	req = soup_requester_request_uri (requester, uri, NULL);
	msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));
	soup_message_headers_append (msg->request_headers,
				     "X-Test-Options", "trailing-junk");
	cmp = do_single_coding_req_test (req, "gzip", "text/plain", EXPECT_DECODED);
	check_req_bodies (plain, cmp, "plain", "compressed w/ junk");
	g_byte_array_free (cmp, TRUE);
	g_object_unref (msg);
	g_object_unref (req);

	/* Plain text data, claim gzip with server error */
	debug_printf (1, "  GET /mbox, Accept-Encoding: gzip, with server error\n");
	req = soup_requester_request_uri (requester, uri, NULL);
	msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));
	soup_message_headers_append (msg->request_headers,
				     "X-Test-Options", "force-encode");
	cmp = do_single_coding_req_test (req, "gzip", "text/plain", EXPECT_NOT_DECODED);

	/* Failed content-decoding should have left the body untouched
	 * from what the server sent... which happens to be the
	 * uncompressed data.
	 */
	check_req_bodies (plain, cmp, "plain", "mis-encoded");
	g_byte_array_free (cmp, TRUE);
	g_object_unref (msg);
	g_object_unref (req);

	/* Plain text data, claim deflate */
	debug_printf (1, "  GET /mbox, Accept-Encoding: deflate\n");
	req = soup_requester_request_uri (requester, uri, NULL);
	msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));
	soup_message_headers_append (msg->request_headers,
				     "X-Test-Options", "prefer-deflate-zlib");
	cmp = do_single_coding_req_test (req, "deflate", "text/plain", EXPECT_DECODED);
	check_req_bodies (plain, cmp, "plain", "compressed");
	g_byte_array_free (cmp, TRUE);
	g_object_unref (msg);
	g_object_unref (req);

	/* Plain text data, claim deflate w/ junk */
	debug_printf (1, "  GET /mbox, Accept-Encoding: deflate, plus trailing junk\n");
	req = soup_requester_request_uri (requester, uri, NULL);
	msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));
	soup_message_headers_append (msg->request_headers,
				     "X-Test-Options", "prefer-deflate-zlib, trailing-junk");
	cmp = do_single_coding_req_test (req, "deflate", "text/plain", EXPECT_DECODED);
	check_req_bodies (plain, cmp, "plain", "compressed w/ junk");
	g_byte_array_free (cmp, TRUE);
	g_object_unref (msg);
	g_object_unref (req);

	/* Plain text data, claim deflate with server error */
	debug_printf (1, "  GET /mbox, Accept-Encoding: deflate, with server error\n");
	req = soup_requester_request_uri (requester, uri, NULL);
	msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));
	soup_message_headers_append (msg->request_headers,
				     "X-Test-Options", "force-encode, prefer-deflate-zlib");
	cmp = do_single_coding_req_test (req, "deflate", "text/plain", EXPECT_NOT_DECODED);
	check_req_bodies (plain, cmp, "plain", "mis-encoded");
	g_byte_array_free (cmp, TRUE);
	g_object_unref (msg);
	g_object_unref (req);

	/* Plain text data, claim deflate (no zlib headers)*/
	debug_printf (1, "  GET /mbox, Accept-Encoding: deflate (raw data)\n");
	req = soup_requester_request_uri (requester, uri, NULL);
	msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));
	soup_message_headers_append (msg->request_headers,
				     "X-Test-Options", "prefer-deflate-raw");
	cmp = do_single_coding_req_test (req, "deflate", "text/plain", EXPECT_DECODED);
	check_req_bodies (plain, cmp, "plain", "compressed");
	g_byte_array_free (cmp, TRUE);
	g_object_unref (msg);
	g_object_unref (req);

	/* Plain text data, claim deflate with server error */
	debug_printf (1, "  GET /mbox, Accept-Encoding: deflate (raw data), with server error\n");
	req = soup_requester_request_uri (requester, uri, NULL);
	msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));
	soup_message_headers_append (msg->request_headers,
				     "X-Test-Options", "force-encode, prefer-deflate-raw");
	cmp = do_single_coding_req_test (req, "deflate", "text/plain", EXPECT_NOT_DECODED);
	check_req_bodies (plain, cmp, "plain", "mis-encoded");
	g_byte_array_free (cmp, TRUE);
	g_object_unref (msg);
	g_object_unref (req);

	g_byte_array_free (plain, TRUE);
	soup_uri_free (uri);

	soup_test_session_abort_unref (session);
}
Ejemplo n.º 12
0
static void
test_url_new_api (const char *url, int proxy, guint expected,
		  gboolean sync, gboolean close)
{
	SoupSession *session;
	SoupURI *proxy_uri;
	SoupMessage *msg;
	SoupRequester *requester;
	SoupRequest *request;
	GInputStream *stream;
	GError *error = NULL;

	if (!tls_available && g_str_has_prefix (url, "https:"))
		return;

	debug_printf (1, "  GET (requester API) %s via %s%s\n", url, proxy_names[proxy],
		      close ? " (with Connection: close)" : "");
	if (proxy == UNAUTH_PROXY && expected != SOUP_STATUS_FORBIDDEN)
		expected = SOUP_STATUS_PROXY_UNAUTHORIZED;

	/* We create a new session for each request to ensure that
	 * connections/auth aren't cached between tests.
	 */
	proxy_uri = soup_uri_new (proxies[proxy]);
	session = soup_test_session_new (sync ? SOUP_TYPE_SESSION_SYNC : SOUP_TYPE_SESSION_ASYNC,
					 SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_REQUESTER,
					 SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
					 SOUP_SESSION_PROXY_URI, proxy_uri,
					 NULL);
	soup_uri_free (proxy_uri);

	g_signal_connect (session, "authenticate",
			  G_CALLBACK (authenticate), NULL);
	if (close) {
		g_signal_connect (session, "request-started",
				  G_CALLBACK (set_close_on_connect), NULL);
	}

	requester = (SoupRequester *)soup_session_get_feature (session, SOUP_TYPE_REQUESTER);
	request = soup_requester_request (requester, url, NULL);
	msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));

	stream = soup_test_request_send (request, NULL, &error);
	if (!stream) {
		debug_printf (1, "  Unexpected error on Request: %s\n",
			      error->message);
		errors++;
		g_clear_error (&error);
	}

	if (stream) {
		soup_test_request_close_stream (request, stream, NULL, NULL);
		if (error) {
			debug_printf (1, "  Unexpected error on close: %s\n",
				      error->message);
			errors++;
			g_clear_error (&error);
		}
		g_object_unref (stream);
	}

	debug_printf (1, "  %d %s\n", msg->status_code, msg->reason_phrase);
	if (msg->status_code != expected) {
		debug_printf (1, "  EXPECTED %d!\n", expected);
		errors++;
	}

	g_object_unref (msg);
	g_object_unref (request);

	soup_test_session_abort_unref (session);
}
Ejemplo n.º 13
0
int main(int argc, char *argv[])
{
    char packet[] = {0x00, 0x00, 0x00};

    float temp, hum;

    int error_count = 0;

    int count = 1;

    GError *error = NULL;
    GOptionContext *context;

    context = g_option_context_new ("- collect temperature and humidity readings");
    g_option_context_add_main_entries (context, entries, NULL);
    if (!g_option_context_parse (context, &argc, &argv, &error))
    {
      g_print ("option parsing failed: %s\n", error->message);
      exit (1);
    }
    g_option_context_free(context);
    set_debug(debug);
    hid_device *handle;
    gboolean found = search_for_device();

    if(!found) {
        g_printerr("Sensor not found, aborting.\n");
        exit(-1);
    }
    
    // Open the device using the VID and PID
    handle = open_lascar();
    if(handle == NULL) {
      g_printerr("Error opening sensor.\n");
      exit(-1);
    }
    
    SoupSession *session = NULL;
    int channel;
    gchar *channel_name;
    gchar *room;
    GString *uri, *body;
    
    /* parse config file */
    GKeyFile *gkf = g_key_file_new();
    g_key_file_load_from_data_dirs(gkf,"templogger.conf",NULL,G_KEY_FILE_NONE,&error);
    if(error!=NULL) {
        g_printerr("Can't load configuration file, not uploading to server.\n");
        g_key_file_free(gkf);
    }
    else {
      gchar *url = g_key_file_get_string(gkf,"influx","url",NULL);
      channel = g_key_file_get_integer(gkf,"channel","channel_num",NULL);
      channel_name = g_key_file_get_string(gkf,"channel","channel_name",NULL);
      room = g_key_file_get_string(gkf,"channel","room",NULL);
      int port = g_key_file_get_integer(gkf,"influx","port",NULL);
      gchar *db = g_key_file_get_string(gkf,"influx","database",NULL);
      gchar *username = g_key_file_get_string(gkf,"influx","username",NULL);
      gchar *password = g_key_file_get_string(gkf,"influx","password",NULL);
      g_key_file_free(gkf);
    
      /* open session */
    
      session = soup_session_new();
      uri = g_string_new("http://");
      g_string_append_printf(uri,"%s:%d/write?db=%s&u=%s&p=%s",url,port,db,username,password);

      g_message(uri->str);
      body = g_string_new("");
	  g_print("Uploading as channel %d, name %s, room %s",channel, channel_name, room);
    }
    
    FILE *logfile = NULL;
    if(log_local) {
        logfile = fopen("log.txt","a");
    }
    
    const int upload_freq = floor(UPLOAD_TIME/SLEEP_TIME);
    
    while(1) {
        int ret = get_reading(handle, packet, &temp, &hum, TRUE);
        if(ret >= 0) {
            gint64 t = 1000*g_get_real_time();
            
            if(log_local) {
              fprintf(logfile,"%" G_GINT64_FORMAT "\t%.1f\t%.1f\n",t, temp, hum);
              fflush(logfile);
            }
            
            if(debug)
              g_print("%" G_GINT64_FORMAT "\t%.1f\t%.1f\n",t, temp, hum);
            
            if(session && (count % upload_freq == 0)) {
            SoupRequestHTTP *request = soup_session_request_http(session,"POST",uri->str,NULL);
            SoupMessage *message = soup_request_http_get_message(request);
            g_string_append_printf(body,"temp,channel=%d,channel_name=%s,room=%s",channel,channel_name,room);
            g_string_append_printf(body," value=%.1f %" G_GINT64_FORMAT,temp,t);
            g_string_append_printf(body,"\n");
            g_string_append_printf(body,"hum,channel=%d,channel_name=%s,room=%s",channel,channel_name,room);
            g_string_append_printf(body," value=%.1f %" G_GINT64_FORMAT,hum,t);
            g_string_append_printf(body,"\n");
            
            if(debug)
              g_message(body->str);
            
            if(!testing) {
                soup_message_set_request(message,"application/binary",SOUP_MEMORY_COPY,body->str,body->len);
                guint session_status = soup_session_send_message(session,message);
                if(session_status == 204) { /* message was received */
                    //g_print("received status %d\n",session_status);
                    g_string_erase(body,0,-1); /* clear the string */
                }
                else {
                  g_print("no connection to server");
                }
                /* otherwise, keep it and attempt to resend next time */
            }
            g_object_unref(message);
            }
            count ++;

            /* reset the error count on successful read */
            error_count = 0;
        } else if(error_count > MAX_ERRORS) {
            g_printerr("Too many errors to continue\n");
            exit(-1);
        } else {
            error_count++;
        }
        if(testing && count>60)
          break;
        g_usleep(SLEEP_TIME*1000000);
    }
    if(session) {
      g_string_free(uri,TRUE);
      g_string_free(body,TRUE);
      g_object_unref(session);
    }
    hid_close(handle);
    hid_exit();
    
    return 0;
}
Ejemplo n.º 14
0
static char *
do_request (SoupSession *session,
	    SoupURI     *base_uri,
	    const char  *method,
	    const char  *path,
	    ...)
{
	SoupRequestHTTP *req;
	SoupMessage *msg;
	GInputStream *stream;
	SoupURI *uri;
	va_list ap;
	const char *header, *value;
	char buf[256];
	gsize nread;
	GError *error = NULL;

	last_request_validated = last_request_hit_network = FALSE;

	uri = soup_uri_new_with_base (base_uri, path);
	req = soup_session_request_http_uri (session, method, uri, NULL);
	soup_uri_free (uri);
	msg = soup_request_http_get_message (req);

	va_start (ap, path);
	while ((header = va_arg (ap, const char *))) {
		value = va_arg (ap, const char *);
		soup_message_headers_append (msg->request_headers,
					     header, value);
	}
	g_object_unref (msg);

	stream = soup_test_request_send (SOUP_REQUEST (req), NULL, &error);
	if (!stream) {
		debug_printf (1, "    could not send request: %s\n",
			      error->message);
		g_error_free (error);
		g_object_unref (req);
		return NULL;
	}

	last_request_hit_network = is_network_stream (stream);

	g_input_stream_read_all (stream, buf, sizeof (buf), &nread,
				 NULL, &error);
	if (error) {
		debug_printf (1, "    could not read response: %s\n",
			      error->message);
		g_clear_error (&error);
	}
	soup_test_request_close_stream (SOUP_REQUEST (req), stream,
					NULL, &error);
	if (error) {
		debug_printf (1, "    could not close stream: %s\n",
			      error->message);
		g_clear_error (&error);
	}
	g_object_unref (stream);
	g_object_unref (req);

	/* Cache writes are G_PRIORITY_LOW, so they won't have happened yet... */
	soup_cache_flush ((SoupCache *)soup_session_get_feature (session, SOUP_TYPE_CACHE));

	return nread ? g_memdup (buf, nread) : g_strdup ("");
}
Ejemplo n.º 15
0
static void
do_request_to_session (SoupSession *session, const char *uri,
		       const char *comment, gboolean expect_timeout)
{
	SoupRequest *req;
	SoupMessage *msg;
	GInputStream *stream;
	GError *error = NULL;
	gboolean finished = FALSE;

	debug_printf (1, "    req %s\n", comment);
	req = soup_session_request (session, uri, NULL);
	msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));

	g_signal_connect (msg, "finished",
			  G_CALLBACK (message_finished), &finished);
	stream = soup_test_request_send (req, NULL, &error);

	if (expect_timeout && !error) {
		debug_printf (1, "      FAILED: request did not time out\n");
		errors++;
	} else if (expect_timeout && !g_error_matches (error, G_IO_ERROR,
						       G_IO_ERROR_TIMED_OUT)) {
		debug_printf (1, "      FAILED: wrong error: %s\n",
			      error->message);
		errors++;
	} else if (!expect_timeout && error) {
		debug_printf (1, "      FAILED: expected success but got error: %s\n",
			      error->message);
		errors++;
	}
	g_clear_error (&error);

	if (stream) {
		soup_test_request_close_stream (req, stream, NULL, &error);

		if (error) {
			debug_printf (1, "      ERROR closing string: %s",
				      error->message);
			errors++;
		}
		g_object_unref (stream);
	}

	if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code) &&
	    !soup_message_is_keepalive (msg)) {
		debug_printf (1, "      ERROR: message is not keepalive!\n");
		errors++;
	}

	if (!finished) {
		debug_printf (1, "      ERROR: 'finished' was not emitted\n");
		errors++;
	}

	g_signal_handlers_disconnect_by_func (msg,
					      G_CALLBACK (message_finished),
					      &finished);
	g_object_unref (msg);
	g_object_unref (req);
}
Ejemplo n.º 16
0
static void
test_multipart (int headers_expected, int sniffed_expected, MultipartMode multipart_mode)
{
    GError* error = NULL;
    SoupRequest* request = soup_session_request (session, base_uri_string, &error);

    SoupMessage *msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
    GMainLoop *loop = g_main_loop_new (NULL, TRUE);
    int headers_count = 0;
    int sniffed_count = 0;
    GHashTable *params;
    const char *content_type;
    gboolean message_is_multipart = FALSE;

    debug_printf (1, "test_multipart(%s)\n", multipart_mode_to_string (multipart_mode));

    /* This is used to track the number of parts. */
    passes = 0;

    /* Force the server to close the connection. */
    soup_message_headers_append (msg->request_headers,
                                 "Connection", "close");

    g_signal_connect (msg, "got_headers",
                      G_CALLBACK (got_headers), &headers_count);

    g_signal_connect (msg, "content-sniffed",
                      G_CALLBACK (content_sniffed), &sniffed_count);

    if (multipart_mode == ASYNC_MULTIPART)
        soup_request_send_async (request, NULL, multipart_handling_cb, loop);
    else if (multipart_mode == ASYNC_MULTIPART_SMALL_READS) {
        g_object_set_data (G_OBJECT (request), "multipart-small-reads", GINT_TO_POINTER(1));
        soup_request_send_async (request, NULL, multipart_handling_cb, loop);
    } else if (multipart_mode == SYNC_MULTIPART)
        soup_request_send_async (request, NULL, sync_multipart_handling_cb, loop);
    else
        soup_request_send_async (request, NULL, no_multipart_handling_cb, loop);

    g_main_loop_run (loop);

    content_type = soup_message_headers_get_content_type (msg->response_headers, &params);

    if (content_type &&
            g_str_has_prefix (content_type, "multipart/") &&
            g_hash_table_lookup (params, "boundary")) {
        message_is_multipart = TRUE;
    }
    g_clear_pointer (&params, g_hash_table_unref);

    if (!message_is_multipart) {
        debug_printf (1,
                      "	 Header does not indicate a multipart message!\n");
        errors++;
    }

    if (headers_count != headers_expected) {
        debug_printf (1,
                      "	 expected got_header %d times, got %d!\n",
                      headers_expected, headers_count);
        errors++;
    }

    if (sniffed_count != sniffed_expected) {
        debug_printf (1,
                      "	 expected content_sniffed %d times, got %d!\n",
                      sniffed_expected, sniffed_count);
        errors++;
    }

    g_object_unref (msg);
    g_object_unref (request);
    g_main_loop_unref (loop);
}
Ejemplo n.º 17
0
static void
sync_multipart_handling_cb (GObject *source, GAsyncResult *res, gpointer data)
{
    GMainLoop *loop = (GMainLoop*)data;
    SoupRequest *request = SOUP_REQUEST (source);
    GError *error = NULL;
    GInputStream *in;
    SoupMessage *message;
    char buffer[READ_BUFFER_SIZE];
    gsize bytes_read;

    in = soup_request_send_finish (request, res, &error);
    message = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
    multipart = soup_multipart_input_stream_new (message, in);
    g_object_unref (message);
    g_object_unref (in);

    if (error) {
        debug_printf (1, "  failed send: %s\n", error->message);
        errors++;

        g_main_loop_quit (loop);
        return;
    }

    while (TRUE) {
        in = soup_multipart_input_stream_next_part (multipart, NULL, &error);

        if (error) {
            debug_printf (1, "  failed sync next part: %s\n", error->message);
            errors++;
            g_clear_error (&error);
            break;
        }

        if (!in)
            break;

        check_headers (multipart, passes);

        g_input_stream_read_all (in, (void*)buffer, sizeof (buffer), &bytes_read, NULL, &error);

        if (error) {
            debug_printf (1, "  failed sync read: %s\n", error->message);
            errors++;
            g_clear_error (&error);
            g_object_unref (in);
            break;
        }

        check_read (bytes_read, passes);

        passes++;
        g_object_unref (in);
    }

    if (passes != 4) {
        debug_printf (1, "  expected 4 parts, got %u\n", passes);
        errors++;
    }

    g_main_loop_quit (loop);
    g_object_unref (multipart);
}
Ejemplo n.º 18
0
static void
do_timeout_req_test_for_session (SoupSession *session)
{
	SoupRequester *requester;
	SoupRequest *req;
	SoupMessage *msg;
	GInputStream *stream;
	SoupSocket *sockets[4] = { NULL, NULL, NULL, NULL };
	SoupURI *timeout_uri;
	GError *error = NULL;
	int i;

	requester = soup_requester_new ();
	soup_session_add_feature (session, SOUP_SESSION_FEATURE (requester));
	g_object_unref (requester);

	g_signal_connect (session, "request-started",
			  G_CALLBACK (request_started_socket_collector),
			  &sockets);

	debug_printf (1, "    First request\n");
	timeout_uri = soup_uri_new_with_base (base_uri, "/timeout-persistent");
	req = soup_requester_request_uri (requester, timeout_uri, NULL);
	soup_uri_free (timeout_uri);

	stream = soup_test_request_send (req, NULL, &error);
	if (!stream) {
		debug_printf (1, "      Unexpected error on send: %s\n",
			      error->message);
		errors++;
		g_clear_error (&error);
	} else {
		soup_test_request_close_stream (req, stream, NULL, &error);
		if (error) {
			debug_printf (1, "  Unexpected error on close: %s\n",
				      error->message);
			errors++;
			g_clear_error (&error);
		}
		g_object_unref (stream);
	}

	if (sockets[1]) {
		debug_printf (1, "      Message was retried??\n");
		errors++;
		sockets[1] = sockets[2] = sockets[3] = NULL;
	}
	g_object_unref (req);

	debug_printf (1, "    Second request\n");
	req = soup_requester_request_uri (requester, base_uri, NULL);

	stream = soup_test_request_send (req, NULL, &error);
	if (!stream) {
		debug_printf (1, "      Unexpected error on send: %s\n",
			      error->message);
		errors++;
		g_clear_error (&error);
	} else {
		soup_test_request_close_stream (req, stream, NULL, &error);
		if (error) {
			debug_printf (1, "  Unexpected error on close: %s\n",
				      error->message);
			errors++;
			g_clear_error (&error);
		}
		g_object_unref (stream);
	}

	msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));
	if (msg->status_code != SOUP_STATUS_OK) {
		debug_printf (1, "      Unexpected response: %d %s\n",
			      msg->status_code, msg->reason_phrase);
		errors++;
	}
	if (sockets[1] != sockets[0]) {
		debug_printf (1, "      Message was not retried on existing connection\n");
		errors++;
	} else if (!sockets[2]) {
		debug_printf (1, "      Message was not retried after disconnect\n");
		errors++;
	} else if (sockets[2] == sockets[1]) {
		debug_printf (1, "      Message was retried on closed connection??\n");
		errors++;
	} else if (sockets[3]) {
		debug_printf (1, "      Message was retried again??\n");
		errors++;
	}
	g_object_unref (msg);
	g_object_unref (req);

	for (i = 0; sockets[i]; i++)
		g_object_unref (sockets[i]);
}
Ejemplo n.º 19
0
gboolean upload_results(AppData *app_data) {
    GError *error = NULL;
    SoupURI *result_uri = NULL;

    guint ret = 0;

    SoupSession *session;
    SoupMessage *server_msg;
    SoupRequest *request;

    gchar *form_data;
    GHashTable *data_table = g_hash_table_new (NULL, NULL);

    result_uri = soup_uri_new (app_data->server);
    if (result_uri == NULL) {
        g_set_error (&error, RESTRAINT_ERROR,
                     RESTRAINT_PARSE_ERROR_BAD_SYNTAX,
                     "Malformed server url: %s", app_data->server);
        goto cleanup;
    }
    session = soup_session_new_with_options("timeout", 3600, NULL);

    g_hash_table_insert (data_table, "path", app_data->test_name);
    g_hash_table_insert (data_table, "result", app_data->test_result);

    // if AVC_ERROR=+no_avc_check then disable the selinux check plugin
    // This is for legacy rhts tests.. please use --disable-plugin
    gchar *avc_error = getenv("AVC_ERROR");
    if (g_strcmp0 (avc_error, "+no_avc_check") == 0) {
        g_ptr_array_add (app_data->disable_plugin, g_strdup ("10_avc_check"));
    }

    if (app_data->disable_plugin->pdata) {
        g_ptr_array_add (app_data->disable_plugin, NULL);
        g_hash_table_insert (data_table, "disable_plugin",
                             g_strjoinv (" ", (gchar **)app_data->disable_plugin->pdata));
    }
    if (app_data->no_plugins)
      g_hash_table_insert (data_table, "no_plugins", &app_data->no_plugins);
    if (app_data->score)
      g_hash_table_insert (data_table, "score", app_data->score);
    if (app_data->result_msg)
      g_hash_table_insert (data_table, "message", app_data->result_msg);

    request = (SoupRequest *)soup_session_request_http_uri (session, "POST", result_uri, &error);
    server_msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
    g_object_unref(request);
    form_data = soup_form_encode_hash (data_table);
    soup_message_set_request (server_msg, "application/x-www-form-urlencoded",
                              SOUP_MEMORY_TAKE, form_data, strlen (form_data));
    g_print ("** %s %s Score:%s\n", app_data->test_name, app_data->test_result,
        app_data->score != NULL ? app_data->score : "N/A");

    ret = soup_session_send_message (session, server_msg);
    if (SOUP_STATUS_IS_SUCCESSFUL (ret)) {
        gchar *location = g_strdup_printf ("%s/logs/",
                                           soup_message_headers_get_one (server_msg->response_headers, "Location"));
        soup_uri_free (result_uri);
        result_uri = soup_uri_new (location);
        g_free (location);
        if (app_data->outputfile != NULL &&
            g_file_test (app_data->outputfile, G_FILE_TEST_EXISTS))
        {
            g_print ("Uploading %s ", app_data->filename);
            if (upload_file (session, app_data->outputfile, app_data->filename, result_uri, &error)) {
                g_print ("done\n");
            } else {
                g_print ("failed\n");
            }
        }
    } else {
       g_warning ("Failed to submit result, status: %d Message: %s\n", ret, server_msg->reason_phrase);
    }
    g_object_unref(server_msg);
    soup_session_abort(session);
    g_object_unref(session);

cleanup:
    g_hash_table_destroy(data_table);
    if (result_uri != NULL) {
        soup_uri_free (result_uri);
    }

    if (error) {
        g_printerr("%s [%s, %d]\n", error->message,
                g_quark_to_string(error->domain), error->code);
        g_clear_error(&error);
        return FALSE;
    } else {
        return TRUE;
    }
}