static SoupMessage *make_token_request_msg( const char *token_uri, const char *consumer_key, const char *consumer_secret) { struct oauth_request *oa = oa_req_new_with_params( consumer_key, consumer_secret, token_uri, "POST", SIG_HMAC_SHA1, NULL); if(!oa_sign_request(oa, OA_REQ_REQUEST_TOKEN)) { /* FIXME: handle! */ printf("fail!\n"); oa_req_free(oa); return NULL; } SoupMessage *msg = soup_message_new("POST", token_uri); #if 0 soup_message_headers_append(msg->request_headers, "Authorization", oa_auth_header(oa, OA_REQ_REQUEST_TOKEN)); #elif 1 char *body = oa_request_params_to_post_body(oa, OA_REQ_REQUEST_TOKEN); soup_message_set_request(msg, OA_POST_MIME_TYPE, SOUP_MEMORY_COPY, body, strlen(body)); #else GHashTable *query = oa_request_token_params(oa); soup_uri_set_query_from_form(soup_message_get_uri(msg), query); g_hash_table_destroy(query); #endif oa_req_free(oa); return msg; }
static gboolean send_files (NstPlugin *plugin, GtkWidget *contact_widget, GList *file_list) { if (!file_list) return TRUE; /* returning false, just hangs the send-to dialog */ gchar *save_items_req = build_save_items_request (file_list); SoupSession *soup_session = soup_session_sync_new (); SoupMessage *save_msg = soup_message_new ("POST", ZOTERO_CONNECTOR_URI"saveItems"); soup_message_set_request (save_msg, "application/json", SOUP_MEMORY_TAKE, save_items_req, strlen (save_items_req)); soup_message_headers_append (save_msg->request_headers, "X-Zotero-Connector-API-Version", ZOTERO_CONNECTOR_API_VERSION); guint status = soup_session_send_message(soup_session, save_msg); if (status != SAVE_ITEMS_STATUS_OK) g_warning ("nst-zotero: send failed: response to saveItems: %u\n", status); /* TODO: returning false just hands the send-to dialog, how to fail? */ g_object_unref (save_msg); g_object_unref (soup_session); return TRUE; }
static SoupMessage *make_access_token_request_msg( const char *uri, const char *req_token, const char *req_secret, const char *verifier, const char *consumer_key, const char *consumer_secret) { struct oauth_request *oa = oa_req_new_with_params(consumer_key, consumer_secret, uri, "POST", SIG_HMAC_SHA1, NULL); oa_set_token(oa, req_token, req_secret); oa_set_verifier(oa, verifier); if(!oa_sign_request(oa, OA_REQ_ACCESS_TOKEN)) { /* FIXME: do something */ printf("arashgrjhagkhfasfa\n"); oa_req_free(oa); return NULL; } SoupMessage *msg = soup_message_new("POST", uri); char *body = oa_request_params_to_post_body(oa, OA_REQ_ACCESS_TOKEN); soup_message_set_request(msg, OA_POST_MIME_TYPE, SOUP_MEMORY_COPY, body, strlen(body)); oa_req_free(oa); return msg; }
static void ws_love(sr_session_t *s) { struct sr_session_priv *priv = s->priv; SoupMessage *message; gchar *params; sr_track_t *t; g_mutex_lock(priv->love_queue_mutex); t = g_queue_peek_head(priv->love_queue); g_mutex_unlock(priv->love_queue_mutex); if (!t) return; ws_params(s, ¶ms, "method", "track.love", "api_key", priv->api_key, "sk", priv->session_key, "track", t->title, "artist", t->artist, NULL); message = soup_message_new("POST", priv->api_url); soup_message_set_request(message, "application/x-www-form-urlencoded", SOUP_MEMORY_TAKE, params, strlen(params)); soup_session_queue_message(priv->soup, message, ws_love_cb, s); }
static gboolean gs_plugin_odrs_json_post (SoupSession *session, const gchar *uri, const gchar *data, GError **error) { guint status_code; g_autoptr(SoupMessage) msg = NULL; /* create the GET data */ g_debug ("odrs sending: %s", data); msg = soup_message_new (SOUP_METHOD_POST, uri); soup_message_set_request (msg, "application/json; charset=utf-8", SOUP_MEMORY_COPY, data, strlen (data)); /* set sync request */ status_code = soup_session_send_message (session, msg); if (status_code != SOUP_STATUS_OK) { g_warning ("Failed to set rating on odrs: %s", soup_status_get_phrase (status_code)); } /* process returned JSON */ g_debug ("odrs returned: %s", msg->response_body->data); return gs_plugin_odrs_parse_success (msg->response_body->data, msg->response_body->length, error); }
static void do_test (SoupSession *session, SoupURI *base_uri, int n) { SoupURI *uri; SoupMessage *msg; TestRequest *req; debug_printf (1, "%2d. %s %s\n", n + 1, tests[n].requests[0].method, tests[n].requests[0].path); uri = soup_uri_new_with_base (base_uri, tests[n].requests[0].path); msg = soup_message_new_from_uri (tests[n].requests[0].method, uri); soup_uri_free (uri); if (msg->method == SOUP_METHOD_POST) { soup_message_set_request (msg, "text/plain", SOUP_MEMORY_STATIC, "post body", strlen ("post body")); } req = &tests[n].requests[0]; g_signal_connect (msg, "got_headers", G_CALLBACK (got_headers), &req); g_signal_connect (msg, "restarted", G_CALLBACK (restarted), &req); soup_session_send_message (session, msg); g_object_unref (msg); debug_printf (2, "\n"); }
void XCAP::CoreImpl::write (gmref_ptr<Path> path, const std::string content_type, const std::string content, sigc::slot1<void,std::string> callback) { SoupSession* session = NULL; SoupMessage* message = NULL; cb_other_data* data = NULL; clear_old_sessions (); /* all of this is freed in the result callback */ session = soup_session_async_new_with_options ("user-agent", "ekiga", NULL); message = soup_message_new ("PUT", path->to_uri ().c_str ()); soup_message_set_request (message, content_type.c_str (), SOUP_MEMORY_COPY, content.c_str (), content.length ()); data = new cb_other_data; data->core = this; data->path = path; data->callback = callback; g_signal_connect (session, "authenticate", G_CALLBACK (authenticate_other_callback), data); soup_session_queue_message (session, message, result_other_callback, data); pending_sessions.push_back (session); }
static SoupMessage * ews_create_msg_for_url (const gchar *url, xmlOutputBuffer *buf) { SoupMessage *msg; gconstpointer buf_content; gsize buf_size; msg = soup_message_new (buf != NULL ? "POST" : "GET", url); soup_message_headers_append ( msg->request_headers, "User-Agent", "libews/0.1"); if (buf != NULL) { buf_content = compat_libxml_output_buffer_get_content (buf, &buf_size); soup_message_set_request ( msg, "text/xml; charset=utf-8", SOUP_MEMORY_COPY, buf_content, buf_size); g_signal_connect ( msg, "restarted", G_CALLBACK (ews_post_restarted_cb), buf); } soup_buffer_free ( soup_message_body_flatten ( SOUP_MESSAGE (msg)->request_body)); g_debug ("The request headers"); g_debug ("==================="); g_debug ("%s", SOUP_MESSAGE (msg)->request_body->data); return msg; }
static SoupMessage * soup_form_request_for_data (const char *method, const char *uri_string, char *form_data) { SoupMessage *msg; SoupURI *uri; uri = soup_uri_new (uri_string); if (!uri) return NULL; if (!strcmp (method, "GET")) { g_free (uri->query); uri->query = form_data; msg = soup_message_new_from_uri (method, uri); } else if (!strcmp (method, "POST") || !strcmp (method, "PUT")) { msg = soup_message_new_from_uri (method, uri); soup_message_set_request ( msg, SOUP_FORM_MIME_TYPE_URLENCODED, SOUP_MEMORY_TAKE, form_data, strlen (form_data)); } else { g_warning ("invalid method passed to soup_form_request_new"); g_free (form_data); /* Don't crash */ msg = soup_message_new_from_uri (method, uri); } soup_uri_free (uri); return msg; }
/** * gdata_access_handler_update_rule: * @self: a #GDataAccessHandler * @service: a #GDataService * @rule: the #GDataAccessRule to update * @cancellable: optional #GCancellable object, or %NULL * @error: a #GError, or %NULL * * Updates @rule in the access control list of the #GDataAccessHandler. * * The service will return an updated version of the rule, which is the return value of this function on success. * * If @cancellable is not %NULL, then the operation can be cancelled by triggering the @cancellable object from another thread. * If the operation was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. * * If there is an error updating the rule, a %GDATA_SERVICE_ERROR_WITH_UPDATE error will be returned. * * Return value: an updated #GDataAccessRule, or %NULL * * Since: 0.3.0 **/ GDataAccessRule * gdata_access_handler_update_rule (GDataAccessHandler *self, GDataService *service, GDataAccessRule *rule, GCancellable *cancellable, GError **error) { GDataServiceClass *klass; GDataAccessRule *updated_rule; SoupMessage *message; gchar *upload_data; guint status; g_return_val_if_fail (GDATA_IS_ENTRY (self), NULL); g_return_val_if_fail (GDATA_IS_SERVICE (service), NULL); g_return_val_if_fail (GDATA_IS_ACCESS_RULE (rule), NULL); message = get_soup_message (self, rule, SOUP_METHOD_PUT); /* Make sure subclasses set their headers */ klass = GDATA_SERVICE_GET_CLASS (service); if (klass->append_query_headers != NULL) klass->append_query_headers (service, message); /* Looks like ACLs don't support ETags */ /* Append the data */ upload_data = gdata_entry_get_xml (GDATA_ENTRY (rule)); soup_message_set_request (message, "application/atom+xml", SOUP_MEMORY_TAKE, upload_data, strlen (upload_data)); /* Send the message */ status = _gdata_service_send_message (service, message, error); if (status == SOUP_STATUS_NONE) { g_object_unref (message); return NULL; } /* Check for cancellation */ if (g_cancellable_set_error_if_cancelled (cancellable, error) == TRUE) { g_object_unref (message); return NULL; } if (status != 200) { /* Error */ g_assert (klass->parse_error_response != NULL); klass->parse_error_response (service, GDATA_SERVICE_ERROR_WITH_UPDATE, status, message->reason_phrase, message->response_body->data, message->response_body->length, error); g_object_unref (message); return NULL; } /* Build the updated entry */ g_assert (message->response_body->data != NULL); /* Parse the XML; create and return a new GDataEntry of the same type as @entry */ updated_rule = GDATA_ACCESS_RULE (_gdata_entry_new_from_xml (G_OBJECT_TYPE (rule), message->response_body->data, message->response_body->length, error)); g_object_unref (message); return updated_rule; }
void http_client_request(const char *url, const char *post_data, const struct http_client_handler *handler, void *ctx) { SoupMessage *msg; struct http_request *request; if (post_data) { msg = soup_message_new(SOUP_METHOD_POST, url); #ifdef HAVE_SOUP_24 soup_message_set_request (msg, "application/x-www-form-urlencoded", SOUP_MEMORY_COPY, post_data, strlen(post_data)); soup_message_headers_append(msg->request_headers, "User-Agent", "mpdscribble/" VERSION); soup_message_headers_append(msg->request_headers, "Pragma", "no-cache"); soup_message_headers_append(msg->request_headers, "Accept", "*/*"); #else soup_message_set_request (msg, "application/x-www-form-urlencoded", SOUP_BUFFER_SYSTEM_OWNED, g_strdup(post_data), strlen(post_data)); soup_message_add_header(msg->request_headers, "User-Agent", "mpdscribble/" VERSION); soup_message_add_header(msg->request_headers, "Pragma", "no-cache"); soup_message_add_header(msg->request_headers, "Accept", "*/*"); #endif } else { msg = soup_message_new(SOUP_METHOD_GET, url); } soup_message_set_flags(msg, SOUP_MESSAGE_NO_REDIRECT); request = g_new(struct http_request, 1); request->handler = handler; request->handler_ctx = ctx; soup_session_queue_message(http_client.session, msg, http_client_soup_callback, request); }
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; }
gint xmlrpc_get_integer(gchar *addr, gchar *method, const gchar *param_types, ...) { gint integer; GValueArray *params; SoupMessage *msg; gchar *body; msg = soup_message_new("POST", addr); params = g_value_array_new(1); if (param_types && *param_types) { va_list ap; va_start(ap, param_types); while (*param_types) { switch (*param_types) { case '%': break; case 'i': soup_value_array_append(params, G_TYPE_INT, va_arg(ap, int)); break; case 's': default: soup_value_array_append(params, G_TYPE_STRING, va_arg(ap, char *)); break; } param_types++; } va_end(ap); } body = soup_xmlrpc_build_method_call(method, params->values, params->n_values); g_value_array_free(params); soup_message_set_request(msg, "text/xml", SOUP_MEMORY_TAKE, body, strlen(body)); while (lock) g_main_iteration(FALSE); lock = TRUE; soup_session_queue_message(session, msg, xmlrpc_response_get_integer, &integer); g_main_run(loop); return integer; }
bool ResourceHandle::startHttp(String urlString) { if (!session) { session = soup_session_async_new(); soup_session_add_feature(session, SOUP_SESSION_FEATURE(getCookieJar())); const char* soup_debug = g_getenv("WEBKIT_SOUP_LOGGING"); if (soup_debug) { int soup_debug_level = atoi(soup_debug); SoupLogger* logger = soup_logger_new(static_cast<SoupLoggerLogLevel>(soup_debug_level), -1); soup_logger_attach(logger, session); g_object_unref(logger); } } SoupMessage* msg; msg = soup_message_new(request().httpMethod().utf8().data(), urlString.utf8().data()); g_signal_connect(msg, "restarted", G_CALLBACK(restartedCallback), this); g_signal_connect(msg, "got-headers", G_CALLBACK(gotHeadersCallback), this); g_signal_connect(msg, "got-chunk", G_CALLBACK(gotChunkCallback), this); HTTPHeaderMap customHeaders = d->m_request.httpHeaderFields(); if (!customHeaders.isEmpty()) { HTTPHeaderMap::const_iterator end = customHeaders.end(); for (HTTPHeaderMap::const_iterator it = customHeaders.begin(); it != end; ++it) soup_message_headers_append(msg->request_headers, it->first.utf8().data(), it->second.utf8().data()); } FormData* httpBody = d->m_request.httpBody(); if (httpBody && !httpBody->isEmpty()) { // Making a copy of the request body isn't the most efficient way to // serialize it, but by far the most simple. Dealing with individual // FormData elements and shared buffers should be more memory // efficient. // // This possibly isn't handling file uploads/attachments, for which // shared buffers or streaming should definitely be used. Vector<char> body; httpBody->flatten(body); soup_message_set_request(msg, d->m_request.httpContentType().utf8().data(), SOUP_MEMORY_COPY, body.data(), body.size()); } d->m_msg = static_cast<SoupMessage*>(g_object_ref(msg)); soup_session_queue_message(session, d->m_msg, finishedCallback, this); return true; }
static void now_playing(sr_session_t *s, sr_track_t *t) { struct sr_session_priv *priv = s->priv; SoupMessage *message; GString *data; char *artist, *title; char *album = NULL, *mbid = NULL; /* haven't got the session yet? */ if (!priv->session_id) return; data = g_string_new(NULL); g_string_append_printf(data, "s=%s", priv->session_id); artist = soup_uri_encode(t->artist, EXTRA_URI_ENCODE_CHARS); title = soup_uri_encode(t->title, EXTRA_URI_ENCODE_CHARS); if (t->album) album = soup_uri_encode(t->album, EXTRA_URI_ENCODE_CHARS); if (t->mbid) mbid = soup_uri_encode(t->mbid, EXTRA_URI_ENCODE_CHARS); /* required fields */ g_string_append_printf(data, "&a=%s&t=%s", artist, title); /* optional fields */ ADD_FIELD("b", "s", album); ADD_FIELD("l", "i", t->length); ADD_FIELD("n", "i", t->position); ADD_FIELD("m", "s", mbid); g_free(artist); g_free(title); g_free(album); g_free(mbid); message = soup_message_new("POST", priv->now_playing_url); soup_message_set_request(message, "application/x-www-form-urlencoded", SOUP_MEMORY_TAKE, data->str, data->len); soup_session_queue_message(priv->soup, message, now_playing_cb, s); g_string_free(data, false); /* soup gets ownership */ }
/** * e_soap_message_persist: * @msg: the #ESoapMessage. * * Writes the serialized XML tree to the #SoupMessage's buffer. * * Since: 2.92 */ void e_soap_message_persist (ESoapMessage *msg) { ESoapMessagePrivate *priv; xmlChar *body; gint len; g_return_if_fail (E_IS_SOAP_MESSAGE (msg)); priv = E_SOAP_MESSAGE_GET_PRIVATE (msg); xmlDocDumpMemory (priv->doc, &body, &len); /* serialize to SoupMessage class */ soup_message_set_request (SOUP_MESSAGE (msg), "text/xml; charset=utf-8", SOUP_MEMORY_TAKE, (gchar *) body, len); }
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; }
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; }
static void set_request(JSContextRef ctx, SoupMessage *msg, JSValueRef val, JSValueRef *exc) { char *content_type = NULL, *body = NULL; JSObjectRef data = JSValueToObject(ctx, val, exc); if (data == NULL) return; content_type = js_get_string_property(ctx, data, "contentType"); if (content_type != NULL) { body = js_get_string_property(ctx, data, "data"); if (body != NULL) { soup_message_set_request(msg, content_type, SOUP_MEMORY_COPY, body, strlen(body)); } } g_free(content_type); g_free(body); }
static void ews_post_restarted_cb (SoupMessage *msg, gpointer data) { xmlOutputBuffer *buf = data; gconstpointer buf_content; gsize buf_size; /* In violation of RFC2616, libsoup will change a * POST request to a GET on receiving a 302 redirect. */ g_debug ("Working around libsoup bug with redirect"); g_object_set (msg, SOUP_MESSAGE_METHOD, "POST", NULL); buf_content = compat_libxml_output_buffer_get_content (buf, &buf_size); soup_message_set_request ( msg, "text/xml; charset=utf-8", SOUP_MEMORY_COPY, buf_content, buf_size); }
void HTTPEngineSender::put(const URI& uri, const Resource::Properties& properties, Resource::Graph ctx) { const string path = (uri.substr(0, 6) == "path:/") ? uri.substr(6) : uri.str(); const string full_uri = _engine_url.str() + "/" + path; Sord::Model model(_world); for (Resource::Properties::const_iterator i = properties.begin(); i != properties.end(); ++i) model.add_statement(Sord::URI(_world, path), AtomRDF::atom_to_node(model, i->first), AtomRDF::atom_to_node(model, i->second)); const string str = model.write_to_string(""); SoupMessage* msg = soup_message_new(SOUP_METHOD_PUT, full_uri.c_str()); assert(msg); soup_message_set_request(msg, "application/x-turtle", SOUP_MEMORY_COPY, str.c_str(), str.length()); soup_session_send_message(_session, msg); }
void picasa_web_service_create_album (PicasaWebService *self, PicasaWebAlbum *album, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { OAuthAccount *account; DomDocument *doc; DomElement *entry; char *buffer; gsize len; char *url; SoupMessage *msg; account = web_service_get_current_account (WEB_SERVICE (self)); g_return_if_fail (account != NULL); gth_task_progress (GTH_TASK (self), _("Creating the new album"), NULL, TRUE, 0.0); doc = dom_document_new (); entry = dom_domizable_create_element (DOM_DOMIZABLE (album), doc); dom_element_append_child (DOM_ELEMENT (doc), entry); buffer = dom_document_dump (doc, &len); url = g_strconcat ("https://picasaweb.google.com/data/feed/api/user/", account->id, NULL); msg = soup_message_new ("POST", url); soup_message_set_request (msg, ATOM_ENTRY_MIME_TYPE, SOUP_MEMORY_TAKE, buffer, len); _picasa_web_service_add_headers (self, msg); _web_service_send_message (WEB_SERVICE (self), msg, cancellable, callback, user_data, picasa_web_service_create_album, create_album_ready_cb, self); g_free (url); g_object_unref (doc); }
static SoupMessage * send_propfind (EBookBackendWebdav *webdav, GCancellable *cancellable) { SoupMessage *message; EBookBackendWebdavPrivate *priv = webdav->priv; const gchar *request = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" "<propfind xmlns=\"DAV:\"><prop><getetag/></prop></propfind>"; message = soup_message_new (SOUP_METHOD_PROPFIND, priv->uri); soup_message_headers_append (message->request_headers, "User-Agent", USERAGENT); soup_message_headers_append (message->request_headers, "Connection", "close"); soup_message_headers_append (message->request_headers, "Depth", "1"); soup_message_set_request ( message, "text/xml", SOUP_MEMORY_TEMPORARY, (gchar *) request, strlen (request)); send_and_handle_ssl (webdav, message, cancellable); return message; }
static void ews_client_post_restarted_cb (SoupMessage *msg, gpointer data) { xmlOutputBuffer *buf = data; /* In violation of RFC2616, libsoup will change a POST request to * a GET on receiving a 302 redirect. */ g_debug ("Working around libsoup bug with redirect"); g_object_set (msg, SOUP_MESSAGE_METHOD, "POST", NULL); soup_message_set_request(msg, "text/xml; charset=utf-8", SOUP_MEMORY_COPY, #ifdef LIBXML2_NEW_BUFFER (gchar *) xmlOutputBufferGetContent(buf), xmlOutputBufferGetSize(buf)); #else (gchar *) buf->buffer->content, buf->buffer->use); #endif }
static SoupMessage * ews_client_create_msg_for_url (const gchar *url, xmlOutputBuffer *buf) { SoupMessage *msg; msg = soup_message_new (buf != NULL ? "POST" : "GET", url); soup_message_headers_append (msg->request_headers, "User-Agent", "libews/0.1"); if (buf != NULL) { soup_message_set_request (msg, "text/xml; charset=utf-8", SOUP_MEMORY_COPY, #ifdef LIBXML2_NEW_BUFFER (gchar *) xmlOutputBufferGetContent(buf), xmlOutputBufferGetSize(buf)); #else (gchar *) buf->buffer->content, buf->buffer->use); #endif g_signal_connect (msg, "restarted", G_CALLBACK (ews_client_post_restarted_cb), buf); }
int GWQSessionDoPoll(GWQSession* wqs) { gchar *tmpCStr, *escaped; if (wqs->st != GWQS_ST_IDLE) { GWQ_ERR_OUT(ERR_OUT, "\n"); } tmpCStr = g_strdup_printf("http://d.web2.qq.com/channel/poll2?clientid=%s&psessionid=%s&t=%ld", wqs->clientId->str, wqs->psessionid->str, GetNowMillisecond() ); wqs->pollMsg = soup_message_new("POST", tmpCStr); g_free(tmpCStr); tmpCStr = g_strdup_printf("{\"clientid\":\"%s\"," "\"psessionid\":\"%s\"," "\"key\":0," "\"ids\":[]}" "&clientid=%s" "&psessionid=%s", wqs->clientId->str, wqs->psessionid->str, wqs->clientId->str, wqs->psessionid->str); escaped = g_uri_escape_string(tmpCStr, NULL, FALSE); g_free(tmpCStr); tmpCStr = g_strdup_printf("r=%s", escaped); g_free(escaped); soup_message_set_request (wqs->pollMsg, "application/x-www-form-urlencoded", SOUP_MEMORY_COPY, tmpCStr, strlen(tmpCStr)); soup_message_headers_append (wqs->pollMsg->request_headers, "Referer", "http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=4"); /* this is must */ g_free(tmpCStr); soup_session_queue_message(wqs->sps, wqs->pollMsg, _process_poll_resp, wqs); return 0; ERR_OUT: return -1; }
static gboolean _soup_xmlrpc_call_with_parameters(gchar * method, SyncNetAction * sna, SoupSessionCallback callback, ...) { SoupMessage *msg; GValueArray *parameters; gchar *argument, *body; va_list ap; sna->error = NULL; msg = soup_message_new("POST", XMLRPC_SERVER_URI); DEBUG("calling xmlrpc method %s", method); if (!msg) return FALSE; parameters = g_value_array_new(1); va_start(ap, callback); while ((argument = va_arg(ap, gchar *))) { soup_value_array_append(parameters, G_TYPE_STRING, argument); DEBUG("with parameter: %s", argument); } va_end(ap); body = soup_xmlrpc_build_method_call(method, parameters->values, parameters->n_values); g_value_array_free(parameters); soup_message_set_request(msg, "text/xml", SOUP_MEMORY_TAKE, body, strlen (body)); soup_session_queue_message(session, msg, callback, sna); g_main_run(loop); return TRUE; }
/** * gs_plugin_app_set_rating_pkg: */ static gboolean gs_plugin_app_set_rating_pkg (GsPlugin *plugin, const gchar *pkgname, gint rating, GError **error) { guint status_code; _cleanup_free_ gchar *data = NULL; _cleanup_free_ gchar *error_msg = NULL; _cleanup_free_ gchar *uri = NULL; _cleanup_object_unref_ SoupMessage *msg = NULL; /* create the PUT data */ uri = g_strdup_printf ("%s/api/v1/rating/%s/", GS_PLUGIN_FEDORA_TAGGER_SERVER, pkgname); data = g_strdup_printf ("pkgname=%s&rating=%i", pkgname, rating); msg = soup_message_new (SOUP_METHOD_PUT, uri); soup_message_set_request (msg, SOUP_FORM_MIME_TYPE_URLENCODED, SOUP_MEMORY_COPY, data, strlen (data)); /* set sync request */ status_code = soup_session_send_message (plugin->priv->session, msg); if (status_code != SOUP_STATUS_OK) { g_debug ("Failed to set rating on fedora-tagger: %s", soup_status_get_phrase (status_code)); if (msg->response_body->data != NULL) { error_msg = gs_plugin_parse_json (msg->response_body->data, msg->response_body->length, "error"); g_debug ("the error given was: %s", error_msg); } } else { g_debug ("Got response: %s", msg->response_body->data); } return TRUE; }
static gboolean gs_plugin_app_set_usage_pkg (GsPlugin *plugin, const gchar *pkgname, gboolean is_install, GError **error) { guint status_code; g_autofree gchar *data = NULL; g_autofree gchar *uri = NULL; g_autoptr(SoupMessage) msg = NULL; /* create the PUT data */ uri = g_strdup_printf ("%s/api/v1/usage/%s/", GS_PLUGIN_FEDORA_TAGGER_SERVER, pkgname); data = g_strdup_printf ("pkgname=%s&usage=%s", pkgname, is_install ? "true" : "false"); msg = soup_message_new (SOUP_METHOD_PUT, uri); soup_message_set_request (msg, SOUP_FORM_MIME_TYPE_URLENCODED, SOUP_MEMORY_COPY, data, strlen (data)); /* set sync request */ status_code = soup_session_send_message (gs_plugin_get_soup_session (plugin), msg); if (status_code != SOUP_STATUS_OK) { g_debug ("Failed to set usage on fedora-tagger: %s", soup_status_get_phrase (status_code)); if (msg->response_body->data != NULL) { g_debug ("the error given was: %s", msg->response_body->data); } } else { g_debug ("Got response: %s", msg->response_body->data); } return TRUE; }
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; }