Beispiel #1
0
int dm_process_json_cmd(bl_t *bl, json_object *req, json_object **ans)
{
  json_object *cmd_obj=0;
  const char *cmd, *iface;
  uint32_t mask;
  int r=0;

  if (!req) {
    r = ERR_WRONG_SYNTAX;
    goto exit;
  }

  dm_json_print("", req);

  if (dm_json_check(req, gen_items)) {
    r = ERR_WRONG_MANDATORY_ITEM;
    goto exit;
  }

  cmd = json_get_string(req, "cmd");

  DBG("cmd: '%s'", cmd);

  json_cmd_table_item_t *cm = dm_find_json_cmd(cm_str_table, cmd);

  if (!cm) {
    r=ERR_UNKNOWN_COMMAND;
    goto exit;
  }

  /* check iface allowed for command */
  if (!dm_vars.prm.no_check_iface) {
    iface = json_get_string(req, "interface");
    mask = 0;
    if (strcmp(iface, "cli")==0)
      mask |= CMFL_IFACECLI;
    if (strcmp(iface, "fcgi")==0)
      mask |= CMFL_IFACEFCGI;

    if (!(cm->flags & mask)) {
      DBG("wrong iface '%s' for command '%s'", iface, cmd);
      r= ERR_ACCESS;
      goto exit;
    }
  }

  /* execute command */
  cm->do_cmd(bp, req, ans);

exit:

  if (!(*ans))
    (*ans)=dm_mk_jsonanswer(r);
  DBG("ans %s", json_object_to_json_string(*ans));

  if (cmd_obj)
    json_object_put(cmd_obj);

  return r;
}
void coind_getauxblock(YAAMP_COIND *coind)
{
	if(!coind->isaux) return;

	json_value *json = rpc_call(&coind->rpc, "getauxblock", "[]");
	if(!json)
	{
		coind_error(coind, "coind_getauxblock");
		return;
	}

	json_value *json_result = json_get_object(json, "result");
	if(!json_result)
	{
		coind_error(coind, "coind_getauxblock");
		return;
	}

//	coind->aux.height = coind->height+1;
	coind->aux.chainid = json_get_int(json_result, "chainid");

	const char *p = json_get_string(json_result, "target");
	if(p) strcpy(coind->aux.target, p);

	p = json_get_string(json_result, "hash");
	if(p) strcpy(coind->aux.hash, p);

//	if(strcmp(coind->symbol, "UNO") == 0)
//	{
//		string_be1(coind->aux.target);
//		string_be1(coind->aux.hash);
//	}

	json_value_free(json);
}
YAAMP_JOB_TEMPLATE *coind_create_template_memorypool(YAAMP_COIND *coind)
{
	json_value *json = rpc_call(&coind->rpc, "getmemorypool");
	if(!json || json->type == json_null)
	{
		coind_error(coind, "getmemorypool");
		return NULL;
	}

	json_value *json_result = json_get_object(json, "result");
	if(!json_result || json_result->type == json_null)
	{
		coind_error(coind, "getmemorypool");
		json_value_free(json);

		return NULL;
	}

	YAAMP_JOB_TEMPLATE *templ = new YAAMP_JOB_TEMPLATE;
	memset(templ, 0, sizeof(YAAMP_JOB_TEMPLATE));

	templ->created = time(NULL);
	templ->value = json_get_int(json_result, "coinbasevalue");
//	templ->height = json_get_int(json_result, "height");
	sprintf(templ->version, "%08x", (unsigned int)json_get_int(json_result, "version"));
	sprintf(templ->ntime, "%08x", (unsigned int)json_get_int(json_result, "time"));
	strcpy(templ->nbits, json_get_string(json_result, "bits"));
	strcpy(templ->prevhash_hex, json_get_string(json_result, "previousblockhash"));

	json_value_free(json);

	json = rpc_call(&coind->rpc, "getinfo", "[]");
	if(!json || json->type == json_null)
	{
		coind_error(coind, "coind_getinfo");
		return NULL;
	}

	json_result = json_get_object(json, "result");
	if(!json_result || json_result->type == json_null)
	{
		coind_error(coind, "coind_getinfo");
		json_value_free(json);

		return NULL;
	}

	templ->height = json_get_int(json_result, "blocks")+1;
	json_value_free(json);

	if(coind->isaux)
		coind_getauxblock(coind);

	coind->usememorypool = true;
	return templ;
}
Beispiel #4
0
bool coind_submitgetauxblock(YAAMP_COIND *coind, const char *hash, const char *block)
{
	int paramlen = strlen(block);

	char *params = (char *)malloc(paramlen+1024);
	if(!params) return false;

	sprintf(params, "[\"%s\",\"%s\"]", hash, block);
	json_value *json = rpc_call(&coind->rpc, "getauxblock", params);

	free(params);
	if(!json) return false;

	json_value *json_error = json_get_object(json, "error");
	if(json_error && json_error->type != json_null)
	{
		const char *p = json_get_string(json_error, "message");
		if(p) stratumlog("ERROR %s %s\n", coind->name, p);

	//	job_reset();
		json_value_free(json);

		return false;
	}

	json_value *json_result = json_get_object(json, "result");
	bool b = json_result && json_result->type == json_boolean && json_result->u.boolean;

	json_value_free(json);
	return b;
}
static void
ttrss_source_check_node_for_removal (nodePtr node, gpointer user_data)
{
	JsonArray	*array = (JsonArray *)user_data;
	GList		*iter, *elements;
	gboolean	found = FALSE;

	if (IS_FOLDER (node)) {
		// FIXME: check folders too

		node_foreach_child_data (node, ttrss_source_check_node_for_removal, user_data);
	} else {
		elements = iter = json_array_get_elements (array);
		while (iter) {
			JsonNode *json_node = (JsonNode *)iter->data;
			if (g_str_equal (node->subscription->source, json_get_string (json_node, "feed_url"))) {
				debug1 (DEBUG_UPDATE, "node: %s", node->subscription->source);
				found = TRUE;
				break;
			}
			iter = g_list_next (iter);
		}
		g_list_free (elements);

		if (!found)			
			feedlist_node_removed (node);
	}				
}
Beispiel #6
0
int json_toStr(char *buf,JSON_OBJECT json,T_PkgType *tp)
{
char *p,*p1;
int i;
T_PkgType *typ,Char_Type[2];

    if(!buf || !json) return 0;
        Char_Type[0].type=CH_CHAR;
        Char_Type[0].len=-1;
        Char_Type[1].len=0;
        Char_Type[0].offset=0;
        Char_Type[1].offset=-1;

    p=buf;
    typ=tp;
    for(i=0;typ->type >= 0;i++,typ++) {
	if(typ->bindtype & NOSELECT) continue;
	if(typ->type == CH_STRUCT) {
	JSON_OBJECT val=json_object_object_get(json,plain_name(typ->name));
		if(!val) continue;
		p+=json_toStr(p,val,(T_PkgType *)typ->format);
		continue;
	}
        p1=json_get_string(json,plain_name(typ->name));
        if(p1) p+=get_one_str(p,p1,Char_Type,'|'); // 组串时需要转义
        *p++ = '|';
        *p=0;
    }
    return p-buf;
}
Beispiel #7
0
static command_status_t fetch_domains(domain_set_t *ds, bool force, error_t **error)
{
    if (!ds->uptodate || force) {
        request_t *req;
        bool request_success;
        json_document_t *doc;

        req = request_new(REQUEST_FLAG_SIGN, HTTP_GET, NULL, error, API_BASE_URL "/domain");
        request_success = request_execute(req, RESPONSE_JSON, (void **) &doc, error);
        request_destroy(req);
        if (request_success) {
            Iterator it;
            json_value_t root;

            root = json_document_get_root(doc);
            hashtable_clear(ds->domains);
            json_array_to_iterator(&it, root);
            for (iterator_first(&it); iterator_is_valid(&it); iterator_next(&it)) {
                json_value_t v;

                v = (json_value_t) iterator_current(&it, NULL);
                hashtable_put(ds->domains, 0, json_get_string(v), domain_new(), NULL); // ds->domains has strdup as key_duper, don't need to strdup it ourself
            }
            iterator_close(&it);
            ds->uptodate = TRUE;
            json_document_destroy(doc);
        } else {
            return COMMAND_FAILURE;
        }
    }

    return COMMAND_SUCCESS;
}
Beispiel #8
0
static command_status_t dnssec_status(COMMAND_ARGS)
{
    request_t *req;
    bool request_success;
    json_document_t *doc;
    domain_record_argument_t *args;

    USED(mainopts);
    args = (domain_record_argument_t *) arg;
    assert(NULL != args->domain);
    req = request_new(REQUEST_FLAG_SIGN, HTTP_GET, NULL, error, API_BASE_URL "/domain/zone/%s/dnssec", args->domain);
    request_success = request_execute(req, RESPONSE_JSON, (void **) &doc, error);
    request_destroy(req);
    if (request_success) {
        json_value_t root, v;

        root = json_document_get_root(doc);
#if 0
        // for translations, do not remove
        _("enabled")
        _("disabled")
        _("enableInProgress")
        _("disableInProgress")
#endif
        json_object_get_property(root, "status", &v);
        puts(_(json_get_string(v)));
        json_document_destroy(doc);
    }

    return request_success ? COMMAND_SUCCESS : COMMAND_FAILURE;
}
Beispiel #9
0
bool coind_validate_address(YAAMP_COIND *coind)
{
    if(!coind->wallet[0]) return false;

    char params[YAAMP_SMALLBUFSIZE];
    sprintf(params, "[\"%s\"]", coind->wallet);

    json_value *json = rpc_call(&coind->rpc, "validateaddress", params);
    if(!json) return false;

    json_value *json_result = json_get_object(json, "result");
    if(!json_result)
    {
        json_value_free(json);
        return false;
    }

    bool isvalid = json_get_bool(json_result, "isvalid");
    if(!isvalid) stratumlog("%s wallet %s is not valid.\n", coind->name, coind->wallet);

    bool ismine = json_get_bool(json_result, "ismine");
    if(!ismine) stratumlog("%s wallet %s is not mine.\n", coind->name, coind->wallet);

    const char *p = json_get_string(json_result, "pubkey");
    if(p) strcpy(coind->pubkey, p);

    json_value_free(json);
    base58_decode(coind->wallet, coind->script_pubkey);

    return isvalid && ismine;
}
Beispiel #10
0
int main()
{
	int i = 0;
    int rc;
	while (i++ < 1)
	{
		json_t *jso = json_new();
		json_add_string(jso, "string1", "string1_val");
		json_add_string(jso, "string2", "string2_val");
		json_add_int(jso, "integer1", 12345);
		printf("%s\n", json_get_string(jso, "string1"));
		printf("%s\n%d\n", json_get_string(jso, "string2"),
			json_get_int(jso, "integer1"));

		json_padd_string(jso, "sub-object/sub-string", "sub-string-val");
		json_padd_string(jso, "object1/sub-object/sub-string", "sub-string-val");
		char *path = "object1/sub-object1/sub-sub-object1//sub-sub-string1";
		json_padd_string(jso, path, "sub-sub-string1-val ");
		printf("sub-sub-string1=[%s]\n", json_pget_string(jso, path));
		json_add_string(jso, "string3", "string3_val");
		json_padd_string(jso, "string4", "string4_val");
//		LOG("\n%s", json_to_string(jso));

        array_t *arr = json_new_array( jso, "array0" );
        rc = json_array_add_string( arr, 0, "array-item", "array-item0-val" );
        rc = json_array_add_int( arr, 0, "array-item-int", 1234 );
        rc = json_array_add_string( arr, 1, "array-item", "array-item1-val" );
        rc = json_array_add_int( arr, 1, "array-item-int", 2234 );
        rc = json_array_add_string( arr, 2, "array-item", "array-item2-val" );
        rc = json_array_add_int( arr, 2, "array-item-int", 3234 );
        /*
        LOG( "rc = [%d][%s][%s][%s][%d]", rc, json_array_get_string( arr, 0, "array-item"),
            json_array_get_string( arr, 1, "array-item" ),
            json_array_get_string( arr, 2, "array-item" ),
            json_array_get_int( arr, 2, "array-item-int") );
            */

        //printf( "====[%d]===[%s]-=-----\n", json_array_getlen(arr),json_array_get_string( arr, 0, "array-item" ) );
        json_t *tmp1 = json_array_get_item( arr, 1 );
        //printf( "-----------\n%s\n--------\n", json_to_string(tmp1) );
		//printf("\n%s\n", json_to_string(jso));
        LOG( "\n%s\n", json_to_string(jso) );
		json_free(&jso);
	}
	//system("pause");
}
int entrypoint ()
{
    int i;
    int32_t type, obj, objarr, objit, arrlen, strlen;
    char str[STR_MAXLEN];

    /* check is json is available, alerts on inactive (optional) */
    if (!json_is_active()) {
        return -1;
    }

    /* acquire array of internal contained objects */
    objarr = json_get_object("ContainedObjects", 16, 0);
    type = json_get_type(objarr);
    /* debug print uint (no '\n' or prepended message */
    debug_print_uint(type);

    if (type != JSON_TYPE_ARRAY) {
        return -1;
    }

    /* check array length for iteration over elements */
    arrlen = json_get_array_length(objarr);
    for (i = 0; i < arrlen; ++i) {
        /* acquire json object @ idx i */
        objit = json_get_array_idx(i, objarr);
        if (objit <= 0) continue;

        /* acquire FileType object of the array element @ idx i */
        obj = json_get_object("FileType", 8, objit);
        if (obj <= 0) continue;

        /* acquire and check type */
        type = json_get_type(obj);
        if (type == JSON_TYPE_STRING) {
            /* acquire string length, note +1 is for the NULL terminator */
            strlen = json_get_string_length(obj)+1;
            /* prevent buffer overflow */
            if (strlen > STR_MAXLEN)
                strlen = STR_MAXLEN;
            /* acquire string data, note strlen includes NULL terminator */
            if (json_get_string(str, strlen, obj)) {
                /* debug print str (with '\n' and prepended message */
                debug_print_str(str,strlen);

                /* check the contained object's type */
                if (strlen == 14 && !memcmp(str, "CL_TYPE_MSEXE", 14)) {
                //if (!strcmp(str, strlen, "CL_TYPE_MSEXE", strlen)) {
                    /* alert for submission */
                    foundVirus("EmbedPE");
                    return 0;
                }
            }
        }
    }

    return 0;
}
static void
ttrss_source_merge_categories (ttrssSourcePtr source, nodePtr parent, gint parentId, JsonNode *items)
{
	JsonArray	*array = json_node_get_array (items);
	GList		*iter, *elements;

	elements = iter = json_array_get_elements (array);
	while (iter) {
		JsonNode *node = (JsonNode *)iter->data;

		gint id = json_get_int (node, "bare_id");
		if (id > 0) {
			const gchar *type = json_get_string (node, "type");
			const gchar *name = json_get_string (node, "name");

			/* ignore everything without a name */	
			if (json_get_string (node, "name")) {

				/* Process child categories */
				if (type && g_str_equal (type, "category")) {
					nodePtr folder;

					debug2 (DEBUG_UPDATE, "TinyTinyRSS category id=%ld name=%s", id, name);
					folder = ttrss_source_find_or_create_folder (name, parent);
					g_hash_table_insert (source->categoryToNode, GINT_TO_POINTER (id), folder);
					g_hash_table_insert (source->nodeToCategory, folder, GINT_TO_POINTER (id));

					/* Process child categories ... */
					if (json_get_node (node, "items"))
						ttrss_source_merge_categories (source, folder, id, json_get_node (node, "items"));
				/* Process child feeds */
				} else {	
					debug3 (DEBUG_UPDATE, "TinyTinyRSS feed=%s folder=%d (%ld)", name, parentId, id);
					g_hash_table_insert (source->categories, GINT_TO_POINTER (id), GINT_TO_POINTER (parentId));
				}
			}

		}
		iter = g_list_next (iter);
	}
	g_list_free (elements);
}
Beispiel #13
0
int getJSONString(json_stream *json, char *aField, const char *aOType, char **var)
{
	if (strcmp(aOType, aField) == 0)
	{
		json_type type = json_next(json);
		assert(type == JSON_STRING);
		*var = mystrdup(json_get_string(json, 0));
		return 1;
	}
	return 0;
}
Beispiel #14
0
void ParserImpl::handleObject()
{
	json_type tok = json_peek(_pJSON);
	while (tok != JSON_OBJECT_END && checkError())
	{
		json_next(_pJSON);
		if (_pHandler) _pHandler->key(std::string(json_get_string(_pJSON, NULL)));
		handle();
		tok = json_peek(_pJSON);
	}

	if (tok == JSON_OBJECT_END) handle();
	else throw JSONException("JSON object end not found");
}
Beispiel #15
0
static command_status_t domain_check(COMMAND_ARGS)
{
    bool success;
    domain_set_t *ds;

    USED(arg);
    USED(mainopts);
    FETCH_ACCOUNT_DOMAINS(ds);
    // populate
    if ((success = (COMMAND_SUCCESS == fetch_domains(ds, FALSE, error)))) {
        time_t now;
        Iterator it;

        now = time(NULL);
        hashtable_to_iterator(&it, ds->domains);
        for (iterator_first(&it); success && iterator_is_valid(&it); iterator_next(&it)) {
            request_t *req;
            json_document_t *doc;
            const char *domain_name;

            iterator_current(&it, (void **) &domain_name);
            // request
            req = request_new(REQUEST_FLAG_SIGN, HTTP_GET, NULL, error, API_BASE_URL "/domain/%s/serviceInfos", domain_name);
            success = request_execute(req, RESPONSE_JSON, (void **) &doc, error);
            request_destroy(req);
            // response
            if (success) {
                time_t domain_expiration;
                json_value_t root, expiration;

                root = json_document_get_root(doc);
                if (json_object_get_property(root, "expiration", &expiration)) {
                    if (date_parse_to_timestamp(json_get_string(expiration), NULL, &domain_expiration)) {
                        int diff_days;

                        diff_days = date_diff_in_days(domain_expiration, now);
                        if (diff_days > 0 && diff_days < 3000) {
                            printf("%s expires in %d days\n", domain_name, diff_days);
                        }
                    }
                }
                json_document_destroy(doc);
            }
        }
        iterator_close(&it);
    }

    return success ? COMMAND_SUCCESS : COMMAND_FAILURE;
}
Beispiel #16
0
const gchar *
json_api_get_string (JsonNode *parent, const gchar *mapping)
{
	JsonNode	*node;
	const gchar	*field;

	if (!node || !mapping)
		return NULL;

	node = json_api_get_node (parent, mapping);
	field = strrchr (mapping, '/');
	if (!field)
		field = mapping;
	else
		field++;

	return json_get_string (node, field);
}
Beispiel #17
0
void test_object_node(void) {
	json_buffer_t* buf = JSON_BUFFER(" { \"b\":true,  \"_int\":  10,   \"str\":\"hi!\" } ");
	json_node_t* obj;

	boolean_t b = B_FALSE;
	int i = -1;
	const char* s = "bye!";

	assert(json_parse(buf, &obj) == JSON_OK);
	assert(json_size(obj) == 3);

	assert(json_get_boolean(obj, "b", &b) == JSON_OK);
	assert(b == B_TRUE);

	assert(json_get_integer_i(obj, "_int", &i) == JSON_OK);
	assert(i == 10);

	assert(json_get_string(obj, "str", &s) == JSON_OK);
	assert(strcmp(s, "hi!") == 0);

	json_node_destroy(obj);
}
Beispiel #18
0
static void
reedah_item_callback (JsonNode *node, itemPtr item)
{
	JsonNode	*canonical, *categories;
	GList		*elements, *iter;

	/* Determine link: path is "canonical[0]/@href" */
	canonical = json_get_node (node, "canonical");
	if (canonical && JSON_NODE_TYPE (canonical) == JSON_NODE_ARRAY) {
		iter = elements = json_array_get_elements (json_node_get_array (canonical));
		while (iter) {
			const gchar *href = json_get_string ((JsonNode *)iter->data, "href");
			if (href) {
				item_set_source (item, href);
				break;
			}
			iter = g_list_next (iter);
		}

		g_list_free (elements);
	}

	/* Determine read state: check for category with ".*state/com.google/read" */
	categories = json_get_node (node, "categories");
	if (categories && JSON_NODE_TYPE (categories) == JSON_NODE_ARRAY) {
		iter = elements = json_array_get_elements (json_node_get_array (canonical));
		while (iter) {
			const gchar *category = json_node_get_string ((JsonNode *)iter->data);
			if (category) {
				item->readStatus = (strstr (category, "state\\/com.google\\/read") != NULL);
				break;
			}
			iter = g_list_next (iter);
		}

		g_list_free (elements);	
	}
}
Beispiel #19
0
static int read_handler(void *arg, void *k, void *v)
{
	hlinda *h = (hlinda*)arg;
	uuid *u = (uuid*)v;

	if (!store_get(h->l->st, u, (void**)&h->dst, &h->len))
		return 0;

	int match = 1;
	json *j1 = json_get_object(h->jquery);
	json *jdst = json_open(h->dst);
	json *j2 = json_get_object(jdst);
	size_t i, cnt = json_count(j1);

	for (i = 0; i < cnt; i++)
	{
		json *j1it = json_index(j1, i);
		const char *name = json_get_string(j1it);

		if (name[0] == '$')
			continue;

		json *j2it = json_find(j2, name);

		if (!j2it)
		{
			match = 0;
			continue;
		}

		if (json_is_integer(j1it))
		{
			if (!json_is_integer(j2it))
			{
				match = 0;
				break;
			}

			if (json_get_integer(j1it) != json_get_integer(j2it))
			{
				match = 0;
				break;
			}
		}
		else if (json_is_real(j1it))
		{
			if (!json_is_real(j2it))
			{
				match = 0;
				break;
			}

			if (json_get_real(j1it) != json_get_real(j2it))
			{
				match = 0;
				break;
			}
		}
		else if (json_is_string(j1it))
		{
			if (!json_is_string(j2it))
			{
				match = 0;
				break;
			}

			if (strcmp(json_get_string(j1it), json_get_string(j2it)))
			{
				match = 0;
				break;
			}
		}
		else if (json_is_true(j1it))
		{
			if (!json_is_true(j2it))
			{
				match = 0;
				break;
			}
		}
		else if (json_is_false(j1it))
		{
			if (!json_is_false(j2it))
			{
				match = 0;
				break;
			}
		}
		else if (json_is_null(j1it))
		{
			if (!json_is_null(j2it))
			{
				match = 0;
				break;
			}
		}
	}

	json_close(jdst);

	if (!match)
		return 1;

	h->oid.u1 = u->u1;
	h->oid.u2 = u->u2;
	return 0;
}
Beispiel #20
0
Scene *loadScene(char *aFilename)
{
	Scene *t = new Scene;
	json_stream json;
	FILE * f = fopen(aFilename, "rb");

	json_open_stream(&json, f);
	json_type type = json_next(&json);
	assert(type == JSON_OBJECT);
	while (json_peek(&json) != JSON_OBJECT_END && json_peek(&json) != JSON_ERROR)
	{
		type = json_next(&json);
		assert(type == JSON_STRING);
		const char *otype = json_get_string(&json, 0);
		if (strcmp(otype, "material") == 0)
		{
			const char *name = "[untitled]";
			glm::vec3 diffuse(1);
			glm::vec3 specular(0);
			glm::vec3 ambient(0);
			float opacity = 1;
			float reflection = 0;


			type = json_next(&json);
			assert(type == JSON_OBJECT);
			while (json_peek(&json) != JSON_OBJECT_END)
			{
				type = json_next(&json);
				assert(type == JSON_STRING);
				otype = json_get_string(&json, 0);

				if (!getJSONString(&json, "name", otype, (char**)&name))
					if (!getJSONVec3(&json, "diffuse", otype, diffuse))
						if (!getJSONVec3(&json, "ambient", otype, ambient))
							if (!getJSONVec3(&json, "specular", otype, specular))
								if (!getJSONNumber(&json, "opacity", otype, opacity))
									if (!getJSONNumber(&json, "reflection", otype, reflection))
										assert(0 && "error parsing material");
			}
			type = json_next(&json);
			assert(type == JSON_OBJECT_END);
			Material *m = new Material();
			m->mName = (char*)name;
			m->mDiffuse = diffuse;
			m->mAmbient = ambient;
			m->mSpecular = specular;
			m->mOpacity = opacity;
			m->mReflection = reflection;
			m->mNext = t->mMaterial;
			t->mMaterial = m;
		}
		else
			if (strcmp(otype, "box") == 0)
			{
				const char *name = "[untitled]";
				const char *material = "default";
				glm::vec3 center;
				glm::vec3 size;
				float dynamic = 0;

				type = json_next(&json);
				assert(type == JSON_OBJECT);
				while (json_peek(&json) != JSON_OBJECT_END)
				{
					type = json_next(&json);
					assert(type == JSON_STRING);
					otype = json_get_string(&json, 0);
					if (!getJSONString(&json, "name", otype, (char**)&name))
						if (!getJSONString(&json, "material", otype, (char**)&material))
							if (!getJSONNumber(&json, "dynamic", otype, dynamic))
								if (!getJSONVec3(&json, "position", otype, center))
									if (!getJSONVec3(&json, "center", otype, center))
										if (!getJSONVec3(&json, "size", otype, size))
											assert(0 && "error parsing box");
				}
				type = json_next(&json);
				assert(type == JSON_OBJECT_END);
				SceneObject *so;
				t->insert(so = new Box((char*)name, center, size, t->getMaterialByName((char*)material)));
				so->mDynamic = dynamic != 0;
			}
			else
				if (strcmp(otype, "plane") == 0)
				{
					const char *name = "[untitled]";
					const char *material = "default";
					glm::vec3 point;
					glm::vec3 normal;
					float dynamic = 0;

					type = json_next(&json);
					assert(type == JSON_OBJECT);
					while (json_peek(&json) != JSON_OBJECT_END)
					{
						type = json_next(&json);
						assert(type == JSON_STRING);
						otype = json_get_string(&json, 0);
						if (!getJSONString(&json, "name", otype, (char**)&name))
							if (!getJSONString(&json, "material", otype, (char**)&material))
								if (!getJSONNumber(&json, "dynamic", otype, dynamic))
									if (!getJSONVec3(&json, "point", otype, point))
										if (!getJSONVec3(&json, "normal", otype, normal))
											assert(0 && "error parsing box");
					}
					type = json_next(&json);
					assert(type == JSON_OBJECT_END);
					SceneObject *so;
					t->insert(so = new Plane((char*)name, point, normal, t->getMaterialByName((char*)material)));
					so->mDynamic = dynamic != 0;
				}
				else
					if (strcmp(otype, "sphere") == 0)
					{
						const char *name = "[untitled]";
						const char *material = "default";
						glm::vec3 center;
						float radius = 5;
						float dynamic = 0;

						type = json_next(&json);
						assert(type == JSON_OBJECT);
						while (json_peek(&json) != JSON_OBJECT_END)
						{
							type = json_next(&json);
							assert(type == JSON_STRING);
							otype = json_get_string(&json, 0);
							if (!getJSONString(&json, "name", otype, (char**)&name))
								if (!getJSONString(&json, "material", otype, (char**)&material))
									if (!getJSONNumber(&json, "dynamic", otype, dynamic))
										if (!getJSONVec3(&json, "center", otype, center))
											if (!getJSONVec3(&json, "position", otype, center))
												if (!getJSONNumber(&json, "radius", otype, radius))
												assert(0 && "error parsing sphere");
						}
						type = json_next(&json);
						assert(type == JSON_OBJECT_END);
						SceneObject *so;
						t->insert(so = new Sphere((char*)name, center, radius, t->getMaterialByName((char*)material)));
						so->mDynamic = dynamic != 0;
					}
					else
						if (strcmp(otype, "light") == 0)
						{
							const char *name = "[untitled]";
							const char *material = "default";
							glm::vec3 position;

							type = json_next(&json);
							assert(type == JSON_OBJECT);
							while (json_peek(&json) != JSON_OBJECT_END)
							{
								type = json_next(&json);
								assert(type == JSON_STRING);
								otype = json_get_string(&json, 0);
								if (!getJSONString(&json, "name", otype, (char**)&name))
									if (!getJSONString(&json, "material", otype, (char**)&material))
										if (!getJSONVec3(&json, "position", otype, position))
											assert(0 && "error parsing light");
							}
							type = json_next(&json);
							assert(type == JSON_OBJECT_END);
							t->insert(new Light((char*)name, position, t->getMaterialByName((char*)material)));
						}
						else
						{
							assert(0);
						}
	}
	type = json_next(&json);
	if (type == JSON_ERROR)
	{
		const char * err = json_get_error(&json);
		err = err;
	}
	assert(type == JSON_OBJECT_END);
	type = json_next(&json);
	assert(type == JSON_DONE);
	json_close(&json);

	setupScene(t);

	t->optimize();
	return t;
};
static void
google_subscription_opml_cb (subscriptionPtr subscription, const struct updateResult * const result, updateFlags flags)
{
	InoreaderSourcePtr	source = (InoreaderSourcePtr) subscription->node->data;

	subscription->updateJob = NULL;
	
	// FIXME: the following code is very similar to ttrss!
	if (result->data && result->httpstatus == 200) {
		JsonParser	*parser = json_parser_new ();

		if (json_parser_load_from_data (parser, result->data, -1, NULL)) {
			JsonArray	*array = json_node_get_array (json_get_node (json_parser_get_root (parser), "subscriptions"));
			GList		*iter, *elements;
			GSList		*siter;
	
			/* We expect something like this:

			   [{"id":"feed\/http:\/\/rss.slashdot.org\/Slashdot\/slashdot",
                             "title":"Slashdot",
                             "categories":[],
                             "firstitemmsec":"1368112925514",
                             "htmlUrl":"null"},
                           ... 

			   Note that the data doesn't contain an URL. 
			   We recover it from the id field.
			*/
			elements = iter = json_array_get_elements (array);
			/* Add all new nodes we find */
			while (iter) {
				JsonNode *node = (JsonNode *)iter->data;
				
				/* ignore everything without a feed url */
				if (json_get_string (node, "id")) {
					inoreader_source_merge_feed (source, 
					                          json_get_string (node, "id") + 5,	// FIXME: Unescape string!
					                          json_get_string (node, "title"),
					                          json_get_string (node, "id"));
				}
				iter = g_list_next (iter);
			}
			g_list_free (elements);

			/* Remove old nodes we cannot find anymore */
			siter = source->root->children;
			while (siter) {
				nodePtr node = (nodePtr)siter->data;
				gboolean found = FALSE;
				
				elements = iter = json_array_get_elements (array);
				while (iter) {
					JsonNode *json_node = (JsonNode *)iter->data;
					// FIXME: Compare with unescaped string
					if (g_str_equal (node->subscription->source, json_get_string (json_node, "id") + 5)) {
						debug1 (DEBUG_UPDATE, "node: %s", node->subscription->source);
						found = TRUE;
						break;
					}
					iter = g_list_next (iter);
				}
				g_list_free (elements);

				if (!found)			
					feedlist_node_removed (node);
				
				siter = g_slist_next (siter);
			}
			
			opml_source_export (subscription->node);	/* save new feeds to feed list */				   
			subscription->node->available = TRUE;			
			//return;
		} else {
			g_warning ("Invalid JSON returned on Inoreader feed list request! >>>%s<<<", result->data);
		}

		g_object_unref (parser);
	} else {
		subscription->node->available = FALSE;
		debug0 (DEBUG_UPDATE, "inoreader_subscription_cb(): ERROR: failed to get subscription list!");
	}

	if (!(flags & INOREADER_SOURCE_UPDATE_ONLY_LIST))
		node_foreach_child_data (subscription->node, node_update_subscription, GUINT_TO_POINTER (0));
}
Beispiel #22
0
int linda_out(hlinda *h, const char *s)
{
	if (!h)
		return 0;

	json *j = json_open(s);
	json *j1 = json_get_object(j);
	json *joid = json_find(j1, LINDA_OID);
	uuid u;

	if (joid)
	{
		uuid_from_string(json_get_string(joid), &u);
	}
	else
		uuid_gen(&u);

	json *jid = json_find(j1, LINDA_ID);

	if (jid)
	{
		if (json_is_integer(jid))
		{
			long long k = json_get_integer(jid);

			if (h->l->sl && !h->l->is_int)
			{
				printf("linda_out: expected integer id\n");
				return 0;
			}

			if (!h->l->sl)
			{
				h->l->sl = sb_int_uuid_create2();
				h->l->is_int = 1;
			}

			sb_int_uuid_set(h->l->sl, k, &u);
		}
		else if (json_is_string(jid))
		{
			const char *k = json_get_string(jid);

			if (h->l->sl && !h->l->is_string)
			{
				printf("linda_out: expected string id\n");
				return 0;
			}

			if (!h->l->sl)
			{
				h->l->sl = sb_string_uuid_create2();
				h->l->is_string = 1;
			}

			sb_string_uuid_set(h->l->sl, k, &u);
		}
	}

	store_hadd(h->hst, &u, s, strlen(s));
	h->last_oid = u;
	json_close(j);
	return 0;
}
Beispiel #23
0
void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value *json_result)
{
	char eheight[64];
	ser_number(templ->height, eheight);

	char etime[64];
	ser_number(time(NULL), etime);

	char entime[64];
	memset(entime, 0, 64);

	if(coind->pos)
		ser_string_be(templ->ntime, entime, 1);

	char eversion1[64] = "01000000";

	if(coind->txmessage)
		strcpy(eversion1, "02000000");

	char script1[4*1024];
	sprintf(script1, "%s%s%s08", eheight, templ->flags, etime);

	char script2[4*1024] = "7961616d702e636f6d00";		// yaamp.com
	if(!coind->pos && !coind->isaux && templ->auxs_size)
		coinbase_aux(templ, script2);

	int script_len = strlen(script1)/2 + strlen(script2)/2 + 8;

	sprintf(templ->coinb1,
		"%s%s010000000000000000000000000000000000000000000000000000000000000000ffffffff%02x%s",		// 8+8+74+2 -> height
		eversion1, entime, script_len, script1);

	sprintf(templ->coinb2, "%s00000000", script2);
	json_int_t available = templ->value;

	if(strcmp(coind->symbol, "DRK") == 0 || strcmp(coind->symbol, "DASH") == 0 || strcmp(coind->symbol, "BOD") == 0)
//	if(strcmp(coind->symbol, "DRK") == 0)
	{
		char charity_payee[1024] = "";
		strcpy(charity_payee, json_get_string(json_result, "payee"));

		json_int_t charity_amount = json_get_int(json_result, "payee_amount");
		bool charity_payments = json_get_bool(json_result, "masternode_payments");
		bool charity_enforce = json_get_bool(json_result, "enforce_masternode_payments");

		if(charity_payments && charity_enforce)
		{
			strcat(templ->coinb2, "02");
			available -= charity_amount;

			char script_payee[1024];
			base58_decode(charity_payee, script_payee);

			job_pack_tx(coind, templ->coinb2, charity_amount, script_payee);
		}
		else
			strcat(templ->coinb2, "01");
	}

	else
		strcat(templ->coinb2, "01");

	job_pack_tx(coind, templ->coinb2, available, NULL);
	strcat(templ->coinb2, "00000000");				// locktime

	coind->reward = (double)available/100000000*coind->reward_mul;
//	debuglog("coinbase %f\n", coind->reward);

//	debuglog("new job: %x, %s, %s, %s\n", coind->templ->id, coind->templ->version, coind->templ->nbits, coind->templ->ntime);
//	debuglog("coinb1 %s\n", templ->coinb1);
//	debuglog("coinb2 %s\n", templ->coinb2);
}
Beispiel #24
0
int linda_rm(hlinda *h, const char *s)
{
	json *j = json_open(s);
	json *j1 = json_get_object(j);
	int is_int = 0, is_string = 0;
	const char *string_id = NULL;
	long long int_id = 0;
	uuid u;

	json *joid = json_find(j1, LINDA_OID);

	if (!joid)
	{
		json_close(j);
		return 0;
	}

	uuid_from_string(json_get_string(joid), &u);
	json *jid = json_find(j1, LINDA_ID);

	if (jid)
	{
		if (h->l->is_int && !json_is_integer(jid))
		{
			printf("linda_read: expected integer id\n");
			json_close(j);
			return 0;
		}
		else if (h->l->is_string && !json_is_string(jid))
		{
			printf("linda_read: expected string id\n");
			json_close(j);
			return 0;
		}

		if (json_is_integer(jid))
		{
			int_id = json_get_integer(jid);
			is_int = 1;
		}
		else if (json_is_string(jid))
		{
			string_id = json_get_string(jid);
			json_close(h->jquery);
			is_string = 1;
		}
		else
		{
			json_close(j);
			return 0;
		}
	}

	json_close(j);

	if (is_int)
	{
		char tmpbuf[1024];
		int tmplen = sprintf(tmpbuf, "{\"%s\":%lld}\n", LINDA_ID, int_id);
		store_hrem2(h->hst, &u, tmpbuf, tmplen);
		sb_int_uuid_erase(h->l->sl, int_id, &u);
	}
	else if (is_string)
	{
		char tmpbuf[1024], tmpbuf2[1024];
		json_format_string(string_id, tmpbuf2, sizeof(tmpbuf2));
		int tmplen = sprintf(tmpbuf, "{\"%s\":\"%s\"}\n", LINDA_ID, tmpbuf2);
		store_hrem2(h->hst, &u, tmpbuf, tmplen);
		sb_string_uuid_erase(h->l->sl, string_id, &u);
	}
	else
	{
		store_rem(h->l->st, &u);
		sb_uuid_efface(h->l->sl, &u);
	}

	return 1;
}
Beispiel #25
0
static void linda_store_handler(void *p1, const uuid *u, const void *_s, int len)
{
	linda *l = (linda*)p1;
	const char *s = (const char*)_s;

	if (len > 0)							// add
	{
		json *j = json_open(s);
		json *j1 = json_get_object(j);
		json *jid = json_find(j1, LINDA_ID);

		if (!jid)
			return;

		if (json_is_integer(jid))
		{
			long long k = json_get_integer(jid);

			if (l->sl && !l->is_int)
			{
				printf("linda_store_handler: expected integer id\n");
				return;
			}

			if (!l->sl)
			{
				l->sl = sb_int_uuid_create2();
				l->is_int = 1;
			}

			sb_int_uuid_set(l->sl, k, u);
		}
		else if (json_is_string(jid))
		{
			const char *k = json_get_string(jid);

			if (l->sl && !l->is_string)
			{
				printf("linda_store_handler: expected string id\n");
				return;
			}

			if (!l->sl)
			{
				l->sl = sb_string_uuid_create2();
				l->is_string = 1;
			}

			sb_string_uuid_set(l->sl, k, u);
		}

		json_close(j);
	}
	else if (len < 0)					// remove (with hint)
	{
		json *j = json_open(s);
		json *j1 = json_get_object(j);
		json *jid = json_find(j1, LINDA_ID);

		if (!jid)
			return;

		if (json_is_integer(jid))
		{
			long long k = json_get_integer(jid);

			if (l->sl && !l->is_int)
			{
				printf("linda_out: expected integer id\n");
				return;
			}

			if (!l->sl)
			{
				l->sl = sb_int_uuid_create2();
				l->is_int = 1;
			}

			sb_int_uuid_erase(l->sl, k, u);
		}
		else if (json_is_string(jid))
		{
			const char *k = json_get_string(jid);

			if (l->sl && !l->is_string)
			{
				printf("linda_out: expected string id\n");
				return;
			}

			if (!l->sl)
			{
				l->sl = sb_string_uuid_create2();
				l->is_string = 1;
			}

			sb_string_uuid_erase(l->sl, k, u);
		}

		json_close(j);
	}
	else 								// remove (brute search)
	{
		sb_uuid_efface(l->sl, u);
	}
}
Beispiel #26
0
static int linda_read(hlinda *h, const char *s, const char **buf, int rm, int nowait)
{
	json *j = json_open(s);
	json *j1 = json_get_object(j);
	h->oid.u1 = h->oid.u2 = 0;
	int is_int = 0, is_string = 0;

	json *jid = json_find(j1, LINDA_ID);

	if (jid)
	{
		if (h->l->is_int && !json_is_integer(jid))
		{
			printf("linda_read: expected integer id\n");
			json_close(j);
			return 0;
		}
		else if (h->l->is_string && !json_is_string(jid))
		{
			printf("linda_read: expected string id\n");
			json_close(j);
			return 0;
		}

		if (json_is_integer(jid))
		{
			h->int_id = json_get_integer(jid);
			h->jquery = json_open(s);
			sb_int_uuid_find(h->l->sl, h->int_id, &read_int_handler, h);
			json_close(h->jquery);
			is_int = 1;
		}
		else if (json_is_string(jid))
		{
			h->string_id = json_get_string(jid);
			h->jquery = json_open(s);
			sb_string_uuid_find(h->l->sl, h->string_id, &read_string_handler, h);
			json_close(h->jquery);
			is_string = 1;
		}
		else
		{
			json_close(j);
			return 0;
		}
	}
	else
	{
		h->jquery = json_open(s);
		sb_iter(h->l->sl, &read_handler, h);
		json_close(h->jquery);
	}

	json_close(j);

	if (!h->oid.u1 && !h->oid.u2)
		return 0;

	if (rm)
	{
		if (is_int)
		{
			char tmpbuf[1024];
			int tmplen = sprintf(tmpbuf, "{\"%s\":%lld}\n", LINDA_ID, h->int_id);
			store_hrem2(h->hst, &h->oid, tmpbuf, tmplen);
			sb_int_uuid_erase(h->l->sl, h->int_id, &h->oid);
		}
		else if (is_string)
		{
			char tmpbuf[1024], tmpbuf2[1024];
			json_format_string(h->string_id, tmpbuf2, sizeof(tmpbuf2));
			int tmplen = sprintf(tmpbuf, "{\"%s\":\"%s\"}\n", LINDA_ID, tmpbuf2);
			store_hrem2(h->hst, &h->oid, tmpbuf, tmplen);
			sb_string_uuid_erase(h->l->sl, h->string_id, &h->oid);
		}
		else
		{
			store_hrem(h->hst, &h->oid);
			sb_uuid_efface(h->l->sl, &h->oid);
		}
	}

	*buf = h->dst;
	return 1;
}
Beispiel #27
0
void ParserImpl::handle()
{
	enum json_type type = json_next(_pJSON);
	switch (type)
	{
		case JSON_DONE:
			return;
		case JSON_NULL:
			_pHandler->null();
			break;
		case JSON_TRUE:
			if (_pHandler) _pHandler->value(true);
			break;
		case JSON_FALSE:
			if (_pHandler) _pHandler->value(false);
			break;
		case JSON_NUMBER:
		{
			if (_pHandler)
			{
				std::string str(json_get_string(_pJSON, NULL));
				if (str.find(_decimalPoint) != str.npos || str.find('e') != str.npos || str.find('E') != str.npos)
				{
					_pHandler->value(NumberParser::parseFloat(str));
				}
				else
				{
					Poco::Int64 val;
					if (NumberParser::tryParse64(str, val))
						_pHandler->value(val);
					else
						_pHandler->value(NumberParser::parseUnsigned64(str));
				}
			}
			break;
		}
		case JSON_STRING:
			if (_pHandler) _pHandler->value(std::string(json_get_string(_pJSON, NULL)));
			break;
		case JSON_OBJECT:
			if (_pHandler) _pHandler->startObject();
			handleObject();
			break;
		case JSON_OBJECT_END:
			if (_pHandler) _pHandler->endObject();
			return;
		case JSON_ARRAY:
			if (_pHandler) _pHandler->startArray();
			handleArray();
			break;
		case JSON_ARRAY_END:
			if (_pHandler) _pHandler->endArray();
			return;
		case JSON_ERROR:
		{
			const char* pErr = json_get_error(_pJSON);
			std::string err(pErr ? pErr : "JSON parser error.");
			throw JSONException(err);
		}
	}
}
Beispiel #28
0
static void
ttrss_feed_subscription_process_update_result (subscriptionPtr subscription, const struct updateResult* const result, updateFlags flags)
{
	if (result->data && result->httpstatus == 200) {
		JsonParser	*parser = json_parser_new ();

		if (json_parser_load_from_data (parser, result->data, -1, NULL)) {
			JsonArray	*array = json_node_get_array (json_get_node (json_parser_get_root (parser), "content"));
			GList		*elements = json_array_get_elements (array);
			GList		*iter = elements;
			GList		*items = NULL;

			/*
			   We expect to get something like this
			   
			   [{"id":118,
			     "unread":true,
			     "marked":false,
			     "updated":1287927675,
			     "is_updated":false,
			     "title":"IBM Says New ...",
			     "link":"http:\/\/rss.slashdot.org\/~r\/Slashdot\/slashdot\/~3\/ALuhNKO3NV4\/story01.htm",
			     "feed_id":"5",
			     "content":"coondoggie writes ..."
			    },
			    {"id":117,
			     "unread":true,
			     "marked":false,
			     "updated":1287923814,
                           [...]
                         */
                         
			while (iter) {
				JsonNode *node = (JsonNode *)iter->data;
				itemPtr item = item_new ();
				gchar *id;
				const gchar *content; 
				gchar *xhtml;

				id = g_strdup_printf ("%" G_GINT64_FORMAT, json_get_int (node, "id"));
				item_set_id (item, id);
				g_free (id);
				item_set_title (item, json_get_string (node, "title"));
				item_set_source (item, json_get_string (node, "link"));

				content = json_get_string (node, "content");
				xhtml = xhtml_extract_from_string (content, NULL);
				item_set_description (item, xhtml);
				xmlFree (xhtml);

				item->time = json_get_int (node, "updated");
				
				if (json_get_bool (node, "unread")) {
					item->readStatus = FALSE;
				}
				else {
					item->readStatus = TRUE;
				}
				if (json_get_bool (node, "marked"))
					item->flagStatus = TRUE;
					
				items = g_list_append (items, (gpointer)item);
				
				iter = g_list_next (iter);
			}

			g_list_free (elements);

			/* merge against feed cache */
			if (items) {
				itemSetPtr itemSet = node_get_itemset (subscription->node);
				gint newCount = itemset_merge_items (itemSet, items, TRUE /* feed valid */, FALSE /* markAsRead */);
				itemlist_merge_itemset (itemSet);
				itemset_free (itemSet);

				feedlist_node_was_updated (subscription->node, newCount);
			}

			subscription->node->available = TRUE;
		} else {
			subscription->node->available = FALSE;

			g_string_append (((feedPtr)subscription->node->data)->parseErrors, _("Could not parse JSON returned by TinyTinyRSS API!"));
		}

		g_object_unref (parser);
	} else {
		subscription->node->available = FALSE;
	}
}
Beispiel #29
0
YAAMP_JOB_TEMPLATE *coind_create_template(YAAMP_COIND *coind)
{
	if(coind->usememorypool)
		return coind_create_template_memorypool(coind);

	char params[4*1024] = "[{}]";
	if(!strcmp(coind->symbol, "PPC")) strcpy(params, "[]");

	json_value *json = rpc_call(&coind->rpc, "getblocktemplate", params);
	if(!json || json->type == json_null)
	{
		coind_error(coind, "getblocktemplate");
		return NULL;
	}

	json_value *json_result = json_get_object(json, "result");
	if(!json_result || json_result->type == json_null)
	{
		coind_error(coind, "getblocktemplate");
		json_value_free(json);

		return NULL;
	}

	json_value *json_tx = json_get_array(json_result, "transactions");
	if(!json_tx)
	{
		coind_error(coind, "getblocktemplate");
		json_value_free(json);

		return NULL;
	}

	json_value *json_coinbaseaux = json_get_object(json_result, "coinbaseaux");
	if(!json_coinbaseaux)
	{
		coind_error(coind, "getblocktemplate");
		json_value_free(json);

		return NULL;
	}

	YAAMP_JOB_TEMPLATE *templ = new YAAMP_JOB_TEMPLATE;
	memset(templ, 0, sizeof(YAAMP_JOB_TEMPLATE));

	templ->created = time(NULL);
	templ->value = json_get_int(json_result, "coinbasevalue");
	templ->height = json_get_int(json_result, "height");
	sprintf(templ->version, "%08x", (unsigned int)json_get_int(json_result, "version"));
	sprintf(templ->ntime, "%08x", (unsigned int)json_get_int(json_result, "curtime"));
	strcpy(templ->nbits, json_get_string(json_result, "bits"));
	strcpy(templ->prevhash_hex, json_get_string(json_result, "previousblockhash"));
	strcpy(templ->flags, json_get_string(json_coinbaseaux, "flags"));

//	debuglog("%s ntime %s\n", coind->symbol, templ->ntime);
//	uint64_t target = decode_compact(json_get_string(json_result, "bits"));
//	coind->difficulty = target_to_diff(target);

//	string_lower(templ->ntime);
//	string_lower(templ->nbits);

//	char target[1024];
//	strcpy(target, json_get_string(json_result, "target"));
//	uint64_t coin_target = decode_compact(templ->nbits);
//	debuglog("%s\n", templ->nbits);
//	debuglog("%s\n", target);
//	debuglog("0000%016llx\n", coin_target);

	if(coind->isaux)
	{
		json_value_free(json);

		coind_getauxblock(coind);
		return templ;
	}

	//////////////////////////////////////////////////////////////////////////////////////////

	vector<string> txhashes;
	txhashes.push_back("");

	for(int i = 0; i < json_tx->u.array.length; i++)
	{
		const char *p = json_get_string(json_tx->u.array.values[i], "hash");

		char hash_be[1024];
		memset(hash_be, 0, 1024);
		string_be(p, hash_be);

		txhashes.push_back(hash_be);

		const char *d = json_get_string(json_tx->u.array.values[i], "data");
		templ->txdata.push_back(d);
	}

	templ->txmerkles[0] = 0;
	templ->txcount = txhashes.size();
	templ->txsteps = merkle_steps(txhashes);

	vector<string>::const_iterator i;
	for(i = templ->txsteps.begin(); i != templ->txsteps.end(); ++i)
		sprintf(templ->txmerkles + strlen(templ->txmerkles), "\"%s\",", (*i).c_str());

	if(templ->txmerkles[0])
		templ->txmerkles[strlen(templ->txmerkles)-1] = 0;

//	debuglog("merkle transactions %d [%s]\n", templ->txcount, templ->txmerkles);
	ser_string_be2(templ->prevhash_hex, templ->prevhash_be, 8);

	if(!coind->pos)
		coind_aux_build_auxs(templ);

	coinbase_create(coind, templ, json_result);
	json_value_free(json);

	return templ;
}
static void
ttrss_source_subscription_list_cb (const struct updateResult * const result, gpointer user_data, guint32 flags)
{
	subscriptionPtr subscription = (subscriptionPtr) user_data;
	ttrssSourcePtr source = (ttrssSourcePtr) subscription->node->data;

	debug1 (DEBUG_UPDATE,"ttrss_subscription_cb(): %s", result->data);

	subscription->updateJob = NULL;
	
	if (result->data && result->httpstatus == 200) {
		JsonParser	*parser = json_parser_new ();

		if (json_parser_load_from_data (parser, result->data, -1, NULL)) {
			JsonNode	*content = json_get_node (json_parser_get_root (parser), "content");
			JsonArray	*array;
			GList		*iter, *elements;
		
			/* We expect something like this:
			
			[ {"feed_url":"http://feeds.arstechnica.com/arstechnica/everything", 
			   "title":"Ars Technica", 
			   "id":6, 
			   "unread":20, 
			   "has_icon":true, 
			   "cat_id":0, 
			   "last_updated":1287853210}, 
			  {"feed_url":"http://rss.slashdot.org/Slashdot/slashdot", 
			   "title":"Slashdot", 
			   "id":5, 
			   "unread":33, 
			   "has_icon":true, 
			   "cat_id":0, 
			   "last_updated":1287853206}, 
			   [...]
			   

			   Or an error message that could look like this:
	
			      {"seq":null,"status":1,"content":{"error":"NOT_LOGGED_IN"}}

			   */

			if (!content || (JSON_NODE_TYPE (content) != JSON_NODE_ARRAY)) {
				debug0 (DEBUG_UPDATE, "ttrss_subscription_cb(): Failed to get subscription list!");
				subscription->node->available = FALSE;
				return;
			}

			array = json_node_get_array (content);
			elements = iter = json_array_get_elements (array);
			/* Add all new nodes we find */
			while (iter) {
				JsonNode *node = (JsonNode *)iter->data;
				
				/* ignore everything without a feed url */
				if (json_get_string (node, "feed_url")) {
					ttrss_source_merge_feed (source, 
					                         json_get_string (node, "feed_url"),
					                         json_get_string (node, "title"),
					                         json_get_int (node, "id"));
				}
				iter = g_list_next (iter);
			}
			g_list_free (elements);

			/* Remove old nodes we cannot find anymore */
			node_foreach_child_data (source->root, ttrss_source_check_node_for_removal, array);
			
			/* Save new subscription tree to OPML cache file */
			opml_source_export (subscription->node);

			subscription->node->available = TRUE;			
		} else {
			g_warning ("Invalid JSON returned on TinyTinyRSSS request! >>>%s<<<", result->data);
		}

		g_object_unref (parser);
	} else {
		subscription->node->available = FALSE;
		debug0 (DEBUG_UPDATE, "ttrss_subscription_cb(): ERROR: failed to get TinyTinyRSS subscription list!");
	}

	if (!(flags & TTRSS_SOURCE_UPDATE_ONLY_LIST))
		node_foreach_child_data (subscription->node, node_update_subscription, GUINT_TO_POINTER (0));	
}