Example #1
0
gint64 torrent_get_eta(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_ETA);
}
Example #2
0
gint64 torrent_get_downloaded(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_DOWNLOADEDEVER);
}
Example #3
0
gint64 torrent_get_left_until_done(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_LEFTUNTILDONE);
}
Example #4
0
static void _process_poll_resp(SoupSession *ss, SoupMessage *msg,  gpointer user_data)
{
    GWQSession *wqs;
    const guint8* data;
    gsize size;
    SoupBuffer *sBuf;
    gchar *tmpCStr;
    JsonParser *jParser;
    JsonNode *jn;
    JsonObject *jo;
    gint32 tmpInt;
    SoupURI *su;
    JsonArray *resJa;
    
    wqs = (GWQSession*)user_data;
    
    GWQ_DBG("poll responsed, retcode=%d, reason:%s\n", msg->status_code, msg->reason_phrase);
    if (wqs->st != GWQS_ST_IDLE) {
        goto ERR_OUT;
    }
    
    if (msg->status_code != 200) {
        GWQ_ERR_OUT(ERR_OUT, "\n");
    }
    
    sBuf = soup_message_body_flatten(msg->response_body);
    if (!sBuf) {
        GWQ_ERR_OUT(ERR_OUT, "\n");
    }

    soup_buffer_get_data(sBuf, &data, &size);
    if (!data || size <=0 ) {
        GWQ_ERR_OUT(ERR_FREE_SBUF, "\n");
    }
    GWQ_DBG("bodySize=%d\nbody:%s\n", size, data);
    
    if (!(jParser = json_parser_new())) {
        GWQ_ERR_OUT(ERR_FREE_SBUF, "\n");
    }
    
    resJa = NULL;
    if (!json_parser_load_from_data(jParser, (const gchar*)data, size, NULL)) {
        GWQ_ERR("\n");
    } else if (!(jn = json_parser_get_root(jParser))
            || !(jo = json_node_get_object(jn))) {
        GWQ_ERR("\n");
    } else if ((tmpInt = json_object_get_int_member(jo, "retcode"))) {
        GWQ_ERR("poll retcode=%d\n", tmpInt);
    } else if (!(jn = json_object_get_member(jo, "result"))
            || !(resJa = json_node_get_array(jn))) {
        GWQ_ERR("poll no result found\n");
    } 
    if (resJa) {
        json_array_foreach_element(resJa, _PollResultArrayForeach, wqs);
    }
    
    g_object_unref(jParser);
    soup_buffer_free(sBuf);
    tmpCStr = g_strdup_printf("clientid=%s&psessionid=%s&t=%ld", 
        wqs->clientId->str, wqs->psessionid->str, GetNowMillisecond()
    );
    su = soup_message_get_uri(msg);
    soup_uri_set_query(su, tmpCStr);

    g_free(tmpCStr);
    GWQ_ERR("Fix me : why soup_session_requeue_message() fails here!!!!!!!!!!!!!!!!!!!!!\n");
    //soup_session_requeue_message(wqs->sps, msg);
    GWQSessionDoPoll(wqs);
    return;
ERR_FREE_J_PARSER:
    g_object_unref(jParser);
ERR_FREE_SBUF:
    soup_buffer_free(sBuf);
ERR_OUT:
    soup_session_cancel_message(ss, msg, SOUP_STATUS_CANCELLED);
}
Example #5
0
gint64 torrent_get_status(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_STATUS);
}
Example #6
0
gint64 torrent_get_done_date(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_DONE_DATE);
}
Example #7
0
gint64 torrent_get_seed_ratio_mode(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_SEED_RATIO_MODE);
}
Example #8
0
gint64 torrent_get_have_valid(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_HAVEVALID);
}
Example #9
0
gint64 torrent_get_bandwidth_priority(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_BANDWIDTH_PRIORITY);
}
Example #10
0
gint64 torrent_get_peer_limit(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_PEER_LIMIT);
}
Example #11
0
static void ggp_edisc_xfer_recv_ticket_update_got(PurpleHttpConnection *hc,
	PurpleHttpResponse *response, gpointer user_data)
{
	PurpleConnection *gc = purple_http_conn_get_purple_connection(hc);
	PurpleXfer *xfer;
	ggp_edisc_xfer *edisc_xfer;
	JsonParser *parser;
	JsonObject *result;
	int status = -1;
	ggp_edisc_session_data *sdata;

	const gchar *ticket_id, *file_name, *send_mode_str;
	uin_t sender, recipient;
	int file_size;

	if (!purple_http_response_is_successful(response)) {
		purple_debug_error("gg",
			"ggp_edisc_xfer_recv_ticket_update_got: "
			"cannot fetch update for ticket (code=%d)\n",
			purple_http_response_get_code(response));
		return;
	}

	sdata = ggp_edisc_get_sdata(gc);
	g_return_if_fail(sdata != NULL);

	parser = ggp_json_parse(purple_http_response_get_data(response, NULL));
	result = json_node_get_object(json_parser_get_root(parser));
	result = json_object_get_object_member(result, "result");
	if (json_object_has_member(result, "status"))
		status = json_object_get_int_member(result, "status");
	result = json_object_get_object_member(result, "send_ticket");

	if (status != 0) {
		purple_debug_warning("gg",
			"ggp_edisc_xfer_recv_ticket_update_got: failed to get "
			"update (status=%d)\n", status);
		g_object_unref(parser);
		return;
	}

	ticket_id = json_object_get_string_member(result, "id");
	sender = ggp_str_to_uin(json_object_get_string_member(result,
		"sender"));
	recipient = ggp_str_to_uin(json_object_get_string_member(result,
		"recipient"));
	file_size = g_ascii_strtoll(json_object_get_string_member(result,
		"file_size"), NULL, 10);
	file_name = json_object_get_string_member(result, "file_name");

	/* GG11: normal
	 * AQQ 2.4.2.10: direct_inbox
	 */
	send_mode_str = json_object_get_string_member(result, "send_mode");

	/* more fields:
	 * send_progress (float), ack_status, send_status
	 */

	if (purple_debug_is_verbose() && purple_debug_is_unsafe())
		purple_debug_info("gg", "Got ticket update: id=%s, sender=%u, "
			"recipient=%u, file name=\"%s\", file size=%d, "
			"send mode=%s)\n",
			ticket_id,
			sender, recipient,
			file_name, file_size,
			send_mode_str);

	xfer = g_hash_table_lookup(sdata->xfers_initialized, ticket_id);
	if (xfer != NULL) {
		purple_debug_misc("gg", "ggp_edisc_xfer_recv_ticket_update_got:"
			" ticket %s already updated\n",
			purple_debug_is_unsafe() ? ticket_id : "");
		g_object_unref(parser);
		return;
	}

	if (recipient != ggp_get_my_uin(gc)) {
		purple_debug_misc("gg", "ggp_edisc_xfer_recv_ticket_update_got:"
			" ticket %s is not for incoming transfer "
			"(its from %u to %u)\n",
			purple_debug_is_unsafe() ? ticket_id : "",
			sender, recipient);
		g_object_unref(parser);
		return;
	}

	xfer = ggp_edisc_xfer_recv_new(gc, ggp_uin_to_str(sender));
	purple_xfer_set_filename(xfer, file_name);
	purple_xfer_set_size(xfer, file_size);
	purple_xfer_request(xfer);
	edisc_xfer = purple_xfer_get_protocol_data(xfer);
	edisc_xfer->ticket_id = g_strdup(ticket_id);
	g_hash_table_insert(sdata->xfers_initialized,
		edisc_xfer->ticket_id, xfer);
	g_hash_table_insert(sdata->xfers_history,
		g_strdup(ticket_id), GINT_TO_POINTER(1));

	g_object_unref(parser);
}
/**
 * xdg_app_review_parse_ratings:
 */
static GArray *
xdg_app_review_parse_ratings (const gchar *data,
			      gsize data_len,
			      GError **error)
{
	GArray *ratings;
	JsonNode *json_root;
	JsonObject *json_item;
	guint i;
	g_autoptr(JsonParser) json_parser = NULL;
	const gchar *names[] = { "star0", "star1", "star2", "star3",
				 "star4", "star5", NULL };

	/* nothing */
	if (data == NULL) {
		g_set_error_literal (error,
				     GS_PLUGIN_ERROR,
				     GS_PLUGIN_ERROR_FAILED,
				     "server returned no data");
		return NULL;
	}

	/* parse the data and find the success */
	json_parser = json_parser_new ();
	if (!json_parser_load_from_data (json_parser, data, data_len, error))
		return NULL;
	json_root = json_parser_get_root (json_parser);
	if (json_root == NULL) {
		g_set_error_literal (error,
				     GS_PLUGIN_ERROR,
				     GS_PLUGIN_ERROR_FAILED,
				     "no error root");
		return NULL;
	}
	if (json_node_get_node_type (json_root) != JSON_NODE_OBJECT) {
		g_set_error_literal (error,
				     GS_PLUGIN_ERROR,
				     GS_PLUGIN_ERROR_FAILED,
				     "no error object");
		return NULL;
	}
	json_item = json_node_get_object (json_root);
	if (json_item == NULL) {
		g_set_error_literal (error,
				     GS_PLUGIN_ERROR,
				     GS_PLUGIN_ERROR_FAILED,
				     "no error object");
		return NULL;
	}

	/* get data array */
	ratings = g_array_sized_new (FALSE, TRUE, sizeof(guint32), 6);
	for (i = 0; names[i] != NULL; i++) {
		guint64 tmp;
		if (!json_object_has_member (json_item, names[i]))
			continue;
		tmp = json_object_get_int_member (json_item, names[i]);
		g_array_append_val (ratings, tmp);
	}
	return ratings;
}
Example #13
0
static gboolean
facebook_photo_deserialize_property (JsonSerializable *serializable,
                                     const gchar      *property_name,
                                     GValue           *value,
                                     GParamSpec       *pspec,
                                     JsonNode         *property_node)
{
	FacebookPhoto *self = FACEBOOK_PHOTO (serializable);

	if (pspec->value_type == GTH_TYPE_DATETIME) {
		GTimeVal timeval;

		if (g_time_val_from_iso8601 (json_node_get_string (property_node), &timeval)) {
			GthDateTime *datetime;

			datetime = gth_datetime_new ();
			gth_datetime_from_timeval (datetime, &timeval);
			g_object_set (self, property_name, datetime, NULL);

			gth_datetime_free (datetime);

			return TRUE;
		}

		return FALSE;
	}

	if (pspec->value_type == FACEBOOK_TYPE_IMAGE_LIST) {
		GList     *images = NULL;
		JsonArray *array;
		int        i;

		array = json_node_get_array (property_node);
		for (i = 0; i < json_array_get_length (array); i++) {
			JsonObject *image_obj;

			image_obj = json_array_get_object_element (array, i);
			if (image_obj != NULL) {
				FacebookImage *image;

				image = facebook_image_new ();
				_g_strset (&image->source, json_object_get_string_member (image_obj, "source"));
				image->width = json_object_get_int_member (image_obj, "width");
				image->height = json_object_get_int_member (image_obj, "height");

				images = g_list_prepend (images, image);
			}
		}

		images = g_list_reverse (images);
		g_object_set (self, property_name, images, NULL);

		facebook_image_list_free (images);

		return TRUE;
	}

	return json_serializable_default_deserialize_property (serializable,
							       property_name,
							       value,
							       pspec,
							       property_node);
}
Example #14
0
gint64 torrent_get_uploaded(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_UPLOADEDEVER);
}
Example #15
0
gint64 torrent_get_download_limit(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_DOWNLOAD_LIMIT);
}
Example #16
0
gint64 torrent_get_corrupted(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_CORRUPTEVER);
}
Example #17
0
gint64 torrent_get_total_size(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_TOTAL_SIZE);
}
Example #18
0
gint64 torrent_get_have_unchecked(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_HAVEUNCHECKED);
}
Example #19
0
gint64 torrent_get_size_when_done(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_SIZEWHENDONE);
}
Example #20
0
gint64 torrent_get_activity_date(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_ACTIVITY_DATE);
}
Example #21
0
gint64 torrent_get_rate_down(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_RATEDOWNLOAD);
}
Example #22
0
gint64 torrent_get_date_created(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_DATE_CREATED);
}
Example #23
0
gint64 torrent_get_rate_up(JsonObject * t)
{
    return json_object_get_int_member(t, FIELD_RATEUPLOAD);
}
Example #24
0
gint64 torrent_get_peers_connected(JsonObject * args)
{
    return json_object_get_int_member(args, FIELD_PEERS_CONNECTED);
}
Example #25
0
/** Refresh albums */
static void _piwigo_refresh_albums(dt_storage_piwigo_gui_data_t *ui, const gchar *select_album)
{
  gtk_widget_set_sensitive(GTK_WIDGET(ui->album_list), FALSE);
  gtk_widget_set_sensitive(GTK_WIDGET(ui->parent_album_list), FALSE);

  if(ui->api == NULL || ui->api->authenticated == FALSE)
  {
    _piwigo_authenticate(ui);
    if(ui->api == NULL || !ui->api->authenticated) return;
  }

  gchar *to_select;
  int index = 0;

  // get the new album name, it will be checked in the
  if(select_album == NULL)
  {
    to_select = g_strdup(dt_bauhaus_combobox_get_text(ui->album_list));
    if(to_select)
    {
      // cut the count of picture in album to get the name only
      gchar *p = to_select;
      while(*p)
      {
        if(*p == ' ' && *(p+1) == '(')
        {
          *p = '\0';
          break;
        }
        p++;
      }
    }
  }
  else
    to_select = g_strdup(select_album);

  // First clear the combobox except first 2 items (none / create new album)
  dt_bauhaus_combobox_clear(ui->album_list);
  dt_bauhaus_combobox_clear(ui->parent_album_list);
  g_list_free(ui->albums);
  ui->albums = NULL;

  GList *args = NULL;

  args = _piwigo_query_add_arguments(args, "method", "pwg.categories.getList");
  args = _piwigo_query_add_arguments(args, "cat_id", "0");
  args = _piwigo_query_add_arguments(args, "recursive", "true");

  _piwigo_api_post(ui->api, args, NULL, FALSE);

  g_list_free(args);

  if(ui->api->response && !ui->api->error_occured)
  {
    dt_bauhaus_combobox_add(ui->album_list, _("create new album"));
    dt_bauhaus_combobox_add(ui->parent_album_list, _("---"));

    JsonObject *result = json_node_get_object(json_object_get_member(ui->api->response, "result"));
    JsonArray *albums = json_object_get_array_member(result, "categories");

    if(json_array_get_length(albums)>0 && index==0) index = 1;
    if(index > json_array_get_length(albums) - 1) index = json_array_get_length(albums) - 1;

    for(int i = 0; i < json_array_get_length(albums); i++)
    {
      char data[MAX_ALBUM_NAME_SIZE] = { 0 };
      JsonObject *album = json_array_get_object_element(albums, i);

      _piwigo_album_t *new_album = g_malloc0(sizeof(struct _piwigo_album_t));

      g_strlcpy(new_album->name, json_object_get_string_member(album, "name"), sizeof(new_album->name));
      new_album->id = json_object_get_int_member(album, "id");
      new_album->size = json_object_get_int_member(album, "nb_images");
      const int isroot = json_object_get_null_member(album, "id_uppercat");
      int indent = 0;

      if(!isroot)
      {
        const char *hierarchy = json_object_get_string_member(album, "uppercats");
        char const *p = hierarchy;
        while(*p++) if(*p == ',') indent++;
      }

      snprintf(data, sizeof(data), "%*c%s (%"PRId64")", indent * 3, ' ', new_album->name, new_album->size);

      if(to_select && !strcmp(new_album->name, to_select)) index = i + 1;

      g_strlcpy(new_album->label, data, sizeof(new_album->label));

      ui->albums = g_list_append(ui->albums, new_album);

      dt_bauhaus_combobox_add_aligned(ui->album_list, data, DT_BAUHAUS_COMBOBOX_ALIGN_LEFT);
      dt_bauhaus_combobox_add_aligned(ui->parent_album_list, data, DT_BAUHAUS_COMBOBOX_ALIGN_LEFT);
    }
  }
  else
    dt_control_log(_("cannot refresh albums"));

  g_free(to_select);

  gtk_widget_set_sensitive(GTK_WIDGET(ui->album_list), TRUE);
  gtk_widget_set_sensitive(GTK_WIDGET(ui->parent_album_list), TRUE);
  dt_bauhaus_combobox_set(ui->album_list, index);
}