当前位置: 首页>>代码示例>>C++>>正文


C++ cJSON_Duplicate函数代码示例

本文整理汇总了C++中cJSON_Duplicate函数的典型用法代码示例。如果您正苦于以下问题:C++ cJSON_Duplicate函数的具体用法?C++ cJSON_Duplicate怎么用?C++ cJSON_Duplicate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cJSON_Duplicate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: cJSON_CreateNull

cJSON *cJSONUtils_GenerateMergePatch(cJSON *from, cJSON *to)
{
    cJSON *patch = 0;
    if (!to)
    {
        /* patch to delete everything */
        return cJSON_CreateNull();
    }
    if ((to->type != cJSON_Object) || !from || (from->type != cJSON_Object))
    {
        return cJSON_Duplicate(to, 1);
    }

    cJSONUtils_SortObject(from);
    cJSONUtils_SortObject(to);

    from = from->child;
    to = to->child;
    patch = cJSON_CreateObject();
    while (from || to)
    {
        int compare = from ? (to ? strcmp(from->string, to->string) : -1) : 1;
        if (compare < 0)
        {
            /* from has a value that to doesn't have -> remove */
            cJSON_AddItemToObject(patch, from->string, cJSON_CreateNull());
            from = from->next;
        }
        else if (compare > 0)
        {
            /* to has a value that from doesn't have -> add to patch */
            cJSON_AddItemToObject(patch, to->string, cJSON_Duplicate(to, 1));
            to = to->next;
        }
        else
        {
            /* object key exists in both objects */
            if (cJSONUtils_Compare(from, to))
            {
                /* not identical --> generate a patch */
                cJSON_AddItemToObject(patch, to->string, cJSONUtils_GenerateMergePatch(from, to));
            }
            /* next key in the object */
            from = from->next;
            to = to->next;
        }
    }
    if (!patch->child)
    {
        cJSON_Delete(patch);
        return 0;
    }

    return patch;
}
开发者ID:DuongNguyenHai,项目名称:Aquaponics,代码行数:55,代码来源:cJSON_Utils.c

示例2: cJSONUtils_MergePatch

cJSON* cJSONUtils_MergePatch(cJSON *target, cJSON *patch)
{
    if (!patch || (patch->type != cJSON_Object))
    {
        /* scalar value, array or NULL, just duplicate */
        cJSON_Delete(target);
        return cJSON_Duplicate(patch, 1);
    }

    if (!target || (target->type != cJSON_Object))
    {
        cJSON_Delete(target);
        target = cJSON_CreateObject();
    }

    patch = patch->child;
    while (patch)
    {
        if (patch->type == cJSON_NULL)
        {
            /* NULL is the indicator to remove a value, see RFC7396 */
            cJSON_DeleteItemFromObject(target, patch->string);
        }
        else
        {
            cJSON *replaceme = cJSON_DetachItemFromObject(target, patch->string);
            cJSON_AddItemToObject(target, patch->string, cJSONUtils_MergePatch(replaceme, patch));
        }
        patch = patch->next;
    }
    return target;
}
开发者ID:DuongNguyenHai,项目名称:Aquaponics,代码行数:32,代码来源:cJSON_Utils.c

示例3: compose_patch

static void compose_patch(cJSON * const patches, const unsigned char * const operation, const unsigned char * const path, const unsigned char *suffix, const cJSON * const value)
{
    cJSON *patch = cJSON_CreateObject();
    if (patch == NULL)
    {
        return;
    }
    cJSON_AddItemToObject(patch, "op", cJSON_CreateString((const char*)operation));

    if (suffix == NULL)
    {
        cJSON_AddItemToObject(patch, "path", cJSON_CreateString((const char*)path));
    }
    else
    {
        size_t suffix_length = pointer_encoded_length(suffix);
        size_t path_length = strlen((const char*)path);
        unsigned char *full_path = (unsigned char*)cJSON_malloc(path_length + suffix_length + sizeof("/"));

        sprintf((char*)full_path, "%s/", (const char*)path);
        encode_string_as_pointer(full_path + path_length + 1, suffix);

        cJSON_AddItemToObject(patch, "path", cJSON_CreateString((const char*)full_path));
        cJSON_free(full_path);
    }

    if (value != NULL)
    {
        cJSON_AddItemToObject(patch, "value", cJSON_Duplicate(value, 1));
    }
    cJSON_AddItemToArray(patches, patch);
}
开发者ID:HanYu1983,项目名称:HanWork,代码行数:32,代码来源:cJSON_Utils.c

示例4: cJSON_Delete

static cJSON *merge_patch(cJSON *target, const cJSON * const patch, const cJSON_bool case_sensitive)
{
    cJSON *patch_child = NULL;

    if (!cJSON_IsObject(patch))
    {
        /* scalar value, array or NULL, just duplicate */
        cJSON_Delete(target);
        return cJSON_Duplicate(patch, 1);
    }

    if (!cJSON_IsObject(target))
    {
        cJSON_Delete(target);
        target = cJSON_CreateObject();
    }

    patch_child = patch->child;
    while (patch_child != NULL)
    {
        if (cJSON_IsNull(patch_child))
        {
            /* NULL is the indicator to remove a value, see RFC7396 */
            if (case_sensitive)
            {
                cJSON_DeleteItemFromObjectCaseSensitive(target, patch_child->string);
            }
            else
            {
                cJSON_DeleteItemFromObject(target, patch_child->string);
            }
        }
        else
        {
            cJSON *replace_me = NULL;
            cJSON *replacement = NULL;

            if (case_sensitive)
            {
                replace_me = cJSON_DetachItemFromObjectCaseSensitive(target, patch_child->string);
            }
            else
            {
                replace_me = cJSON_DetachItemFromObject(target, patch_child->string);
            }

            replacement = merge_patch(replace_me, patch_child, case_sensitive);
            if (replacement == NULL)
            {
                return NULL;
            }

            cJSON_AddItemToObject(target, patch_child->string, replacement);
        }
        patch_child = patch_child->next;
    }
    return target;
}
开发者ID:HanYu1983,项目名称:HanWork,代码行数:58,代码来源:cJSON_Utils.c

示例5: while

/* Duplication */
cJSON *cJSON_Duplicate(cJSON *item,int recurse)
{
	cJSON *newitem,*cptr,*nptr=0,*newchild;
	/* Bail on bad ptr */
	if (!item) return 0;
	/* Create new item */
	newitem=cJSON_New_Item();
	if (!newitem) return 0;
	/* Copy over all vars */
	newitem->type=item->type&(~cJSON_IsReference),newitem->valueint=item->valueint,newitem->valuedouble=item->valuedouble;
	if (item->valuestring)	{newitem->valuestring=cJSON_strdup(item->valuestring);	if (!newitem->valuestring)	{cJSON_Delete(newitem);return 0;}}
	if (item->string)		{newitem->string=cJSON_strdup(item->string);			if (!newitem->string)		{cJSON_Delete(newitem);return 0;}}
	/* If non-recursive, then we're done! */
	if (!recurse) return newitem;
	/* Walk the ->next chain for the child. */
	cptr=item->child;
	while (cptr)
	{
		newchild=cJSON_Duplicate(cptr,1);		/* Duplicate (with recurse) each item in the ->next chain */
		if (!newchild) {cJSON_Delete(newitem);return 0;}
		if (nptr)	{nptr->next=newchild,newchild->prev=nptr;nptr=newchild;}	/* If newitem->child already set, then crosswire ->prev and ->next and move on */
		else		{newitem->child=newchild;nptr=newchild;}					/* Set newitem->child and move to it */
		cptr=cptr->next;
	}
	return newitem;
}
开发者ID:englercj,项目名称:gamesparks-cpp-unreal,代码行数:27,代码来源:cJSON.cpp

示例6: GenerateOutData

/*-------------------------------------------------------------------
Function: GenerateOutData();
Purpose: 通过比较现有数据跟原有数据,产生要输出的字符串.
Parameters: 
Return: 0 --- successful, -1 --- failed
-------------------------------------------------------------------*/
int CRedWoodDataParse::GenerateOutData(void)
{
    int iRet = 0;

    if (!oldDataJson) 
        return GenerateOutDataFromJson(updatedDataJson);
    else {
        assert(updatedDataJson);

        cJSON* outJson = NULL;
        outJson = cJSON_Duplicate(updatedDataJson, 1);
        if (!outJson)
            return -1;

        cJSON* newJsonFixture = NULL;
        cJSON* oldJsonFixture = NULL;

        newJsonFixture = cJSON_GetObjectItem(outJson, "fixture");
        oldJsonFixture = cJSON_GetObjectItem(oldDataJson, "fixture");

        if (!newJsonFixture || !oldJsonFixture) {
            cJSON_Delete(outJson);
            return -1;
        }        

        int iDataLen = 0;
        iDataLen = cJSON_GetArraySize(newJsonFixture); 

        assert(iDataLen == cJSON_GetArraySize(oldJsonFixture));

        //比较 fixture 节点的 每个子节点,如果相同,则从输出中删除
        for (int i = iDataLen - 1; i >= 0; i--) {
            cJSON* oldJsonTemp = cJSON_GetArrayItem(oldJsonFixture, i);
            cJSON* newJsonTemp = cJSON_GetArrayItem(newJsonFixture, i);

            char* pOldDataTemp = cJSON_Print(oldJsonTemp);
            char* pNewDataTemp = cJSON_Print(newJsonTemp);

            if (strcmp(pOldDataTemp, pNewDataTemp) == 0)
                cJSON_DeleteItemFromArray(newJsonFixture, i);

            free(pOldDataTemp);
            free(pNewDataTemp);
        }

        //改变输出的数据个数
        if (iDataLen != cJSON_GetArraySize(newJsonFixture)) {
            iDataLen = cJSON_GetArraySize(newJsonFixture); 
            cJSON_ReplaceItemInObject(outJson, "data length", cJSON_CreateNumber(iDataLen));
        }

        //生成目标字符串,以便输出
        iRet = GenerateOutDataFromJson(outJson);
        cJSON_Delete(outJson);
    }

    return iRet;
}
开发者ID:qzluo,项目名称:nbrwapp,代码行数:64,代码来源:redWoodDataParse.cpp

示例7: SAManager_WrapAutoReportPacket

susiaccess_packet_body_t * SAManager_WrapAutoReportPacket(Handler_info const * plugin, void const * const requestData, unsigned int const requestLen, bool bCust)
{
	PJSON ReqInfoJSON = NULL;
	char* pReqInfoPayload = NULL;
	susiaccess_packet_body_t* packet = NULL;

	cJSON* node = NULL;
	cJSON* root = NULL;
	cJSON* pfinfoNode = NULL;
	char* buff = NULL;
	char* data = NULL;
	int length = 0;

	if(plugin == NULL)
		return packet;
	if(plugin->agentInfo == NULL)
		return packet;

	if(requestData)
	{
		data = ConvertMessageToUTF8(requestData);
	}

	root = cJSON_CreateObject();
	pfinfoNode = cJSON_CreateObject();
	//node = cJSON_Parse((const char *)requestData);
	node = cJSON_Parse((const char *)data);
	free(data);
	
	if(pfinfoNode)
	{
		cJSON* chNode = node->child;
		cJSON_AddItemToObject(pfinfoNode, chNode->string, cJSON_Duplicate(chNode, true));	
	}
	cJSON_Delete(node);
	cJSON_AddItemToObject(root, "data", pfinfoNode);
	buff = cJSON_PrintUnformatted(root);
	cJSON_Delete(root);
	length = strlen(buff);
	
	packet = malloc(sizeof(susiaccess_packet_body_t));
	memset(packet, 0, sizeof(susiaccess_packet_body_t));
	packet->content = (char*)malloc(length+1);
	memset(packet->content, 0, length+1);
	memcpy(packet->content, buff, length);

	free(buff);

	strcpy(packet->devId, plugin->agentInfo->devId);
	strcpy(packet->handlerName, "general");  //Special case for auto report.

	packet->requestID = cagent_action_general;

	packet->cmd = general_info_upload_rep;
	//SAManagerLog(g_samanagerlogger, Normal, "Parser_CreateRequestInfo");

	return packet;
}
开发者ID:advlinda,项目名称:cagentoniotcore,代码行数:58,代码来源:SAManager.c

示例8: UpdateData

/*-------------------------------------------------------------------
Function: UpdateData();
Purpose: Upatate json data from raw json. For user, ParseFromStr 
         should be called before called this function.
Parameters: 
Return: 0 --- successful, -1 --- failed
-------------------------------------------------------------------*/
int CRedWoodDataParse::UpdateData(void)
{
    if (!rawJson)
        return -1;

    //save data gotten last time
    if (updatedDataJson) {
        if (oldDataJson) {
            cJSON_Delete(oldDataJson);
            oldDataJson = NULL;
        }

        oldDataJson = updatedDataJson;
    }
    
    //create new json from raw data
    cJSON* fixtureJson = NULL;    //son 'fuxture' of rawjson
    int iDataCount = 0;
    cJSON* srcJson = NULL;
    cJSON* descJson = NULL;       //as variable to save fixture
    cJSON* srcJsonTemp = NULL;
    cJSON* descJsonTemp = NULL;

    fixtureJson = cJSON_GetObjectItem(rawJson, "fixture");
    if (!fixtureJson)
        return -1;

    iDataCount = cJSON_GetArraySize(fixtureJson); 

    updatedDataJson = cJSON_CreateObject();	
    cJSON_AddStringToObject(updatedDataJson, "version", TRANSER_JSON_VERSION);
    cJSON_AddNumberToObject(updatedDataJson, "data length", iDataCount);
    cJSON_AddNumberToObject(updatedDataJson, "currentTime", 
                            cJSON_GetObjectItem(rawJson, "currentTime")->valueint);

    cJSON_AddItemToObject(updatedDataJson, "fixture",  
        descJson = cJSON_CreateArray());

    //create each sub json
    for (int i = 0; i < iDataCount; i++) {        
        srcJsonTemp = cJSON_GetArrayItem(fixtureJson, i);
        descJsonTemp = cJSON_Duplicate(srcJsonTemp, 1);
        cJSON_AddItemToArray(descJson, descJsonTemp);

        //将要保存目标结点的 sensorStats 节点删除
        cJSON_DeleteItemFromObject(descJsonTemp, "sensorStats");

        //将原有数据的 sensorStats 节点中的数据经转化保存到 目标结点
        AddSensorDataToJson(cJSON_GetObjectItem(srcJsonTemp, "sensorStats"), descJsonTemp);        
    }

    GenerateFullOutDataFromJson(updatedDataJson);

    return 0;
}
开发者ID:qzluo,项目名称:nbrwapp,代码行数:62,代码来源:redWoodDataParse.cpp

示例9: conference_event_channel_handler

void conference_event_channel_handler(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id)
{
	char *domain = NULL, *name = NULL;
	conference_obj_t *conference = NULL;
	cJSON *data, *reply = NULL, *conference_desc = NULL;
	const char *action = NULL;
	char *dup = NULL;

	if ((data = cJSON_GetObjectItem(json, "data"))) {
		action = cJSON_GetObjectCstr(data, "action");
	}

	if (!action) action = "";

	reply = cJSON_Duplicate(json, 1);
	cJSON_DeleteItemFromObject(reply, "data");

	if ((name = strchr(event_channel, '.'))) {
		dup = strdup(name + 1);
		switch_assert(dup);
		name = dup;

		if ((domain = strchr(name, '@'))) {
			*domain++ = '\0';
		}
	}

	if (!strcasecmp(action, "bootstrap")) {
		if (!zstr(name) && (conference = conference_find(name, domain))) {
			conference_desc = conference_cdr_json_render(conference, json);
		} else {
			conference_desc = cJSON_CreateObject();
			json_add_child_string(conference_desc, "conferenceDescription", "FreeSWITCH Conference");
			json_add_child_string(conference_desc, "conferenceState", "inactive");
			json_add_child_array(conference_desc, "users");
			json_add_child_array(conference_desc, "oldUsers");
		}
	} else {
		conference_desc = cJSON_CreateObject();
		json_add_child_string(conference_desc, "error", "Invalid action");
	}

	json_add_child_string(conference_desc, "action", "conferenceDescription");

	cJSON_AddItemToObject(reply, "data", conference_desc);

	switch_safe_free(dup);

	switch_event_channel_broadcast(event_channel, &reply, "mod_conference", conference_globals.event_channel_id);
}
开发者ID:prashantchoudhary,项目名称:FreeswitchModified,代码行数:50,代码来源:conference_event.c

示例10: PLUGNAME

int32_t PLUGNAME(_process_json)(char *forwarder,char *sender,int32_t valid,struct plugin_info *plugin,uint64_t tag,char *retbuf,int32_t maxlen,char *jsonstr,cJSON *json,int32_t initflag,char *tokenstr)
{
    char *SuperNET_install(char *plugin,char *jsonstr,cJSON *json);
    char *retstr,*resultstr,*methodstr,*destplugin;
    int32_t len;
    retbuf[0] = 0;
    //printf("<<<<<<<<<<<< INSIDE PLUGIN.(%s)! (%s) initflag.%d process %s\n",plugin->name,jsonstr,initflag,plugin->name);
    if ( initflag > 0 )
    {
        SUPERNET.ppid = OS_getppid();
        SUPERNET.argjson = cJSON_Duplicate(json,1);
        SUPERNET.readyflag = 1;
        if ( SUPERNET.UPNP != 0 )
        {
            char portstr[64];
            sprintf(portstr,"%d",SUPERNET.serviceport), upnpredirect(portstr,portstr,"TCP","SuperNET");
            sprintf(portstr,"%d",SUPERNET.port + LB_OFFSET), upnpredirect(portstr,portstr,"TCP","SuperNET");
            sprintf(portstr,"%d",SUPERNET.port + PUBGLOBALS_OFFSET), upnpredirect(portstr,portstr,"TCP","SuperNET");
            sprintf(portstr,"%d",SUPERNET.port + PUBRELAYS_OFFSET), upnpredirect(portstr,portstr,"TCP","SuperNET");
        }
    }
    else
    {
        if ( plugin_result(retbuf,json,tag) > 0 )
            return((int32_t)strlen(retbuf));
        methodstr = cJSON_str(cJSON_GetObjectItem(json,"method"));
        resultstr = cJSON_str(cJSON_GetObjectItem(json,"result"));
        if ( (destplugin= cJSON_str(cJSON_GetObjectItem(json,"name"))) == 0 )
            destplugin = cJSON_str(cJSON_GetObjectItem(json,"path"));
        printf("SUPERNET\n");
        if ( resultstr != 0 && strcmp(resultstr,"registered") == 0 )
        {
            plugin->registered = 1;
            retstr = "return registered";
        }
        else if ( methodstr != 0 && strcmp(methodstr,"install") == 0 && destplugin != 0 && destplugin[0] != 0 )
            retstr = SuperNET_install(destplugin,jsonstr,json);
        else retstr = "return JSON result";
        strcpy(retbuf,retstr);
        len = (int32_t)strlen(retbuf);
        while ( --len > 0 )
            if ( retbuf[len] == '}' )
                break;
        sprintf(retbuf + len,",\"debug\":%d,\"USESSL\":%d,\"MAINNET\":%d,\"DATADIR\":\"%s\",\"NXTAPI\":\"%s\",\"WEBSOCKETD\":\"%s\",\"SUPERNET_PORT\":%d,\"APISLEEP\":%d,\"domain\":\"%s\"}",Debuglevel,SUPERNET.usessl,SUPERNET.ismainnet,SUPERNET.DATADIR,SUPERNET.NXTAPIURL,SUPERNET.WEBSOCKETD,SUPERNET.port,SUPERNET.APISLEEP,SUPERNET.hostname);
    }
    return((int32_t)strlen(retbuf));
}
开发者ID:mezzovide,项目名称:btcd,代码行数:47,代码来源:libjl777.c

示例11: cJSONUtils_GeneratePatch

static void cJSONUtils_GeneratePatch(cJSON *patches, const char *op, const char *path, const char *suffix, cJSON *val)
{
    cJSON *patch = cJSON_CreateObject();
    cJSON_AddItemToObject(patch, "op", cJSON_CreateString(op));
    if (suffix)
    {
        char *newpath = (char*)malloc(strlen(path) + cJSONUtils_PointerEncodedstrlen(suffix) + 2);
        cJSONUtils_PointerEncodedstrcpy(newpath + sprintf(newpath, "%s/", path), suffix);
        cJSON_AddItemToObject(patch, "path", cJSON_CreateString(newpath));
        free(newpath);
    }
    else
    {
        cJSON_AddItemToObject(patch, "path", cJSON_CreateString(path));
    }
    if (val)
    {
        cJSON_AddItemToObject(patch, "value", cJSON_Duplicate(val, 1));
    }
    cJSON_AddItemToArray(patches, patch);
}
开发者ID:DuongNguyenHai,项目名称:Aquaponics,代码行数:21,代码来源:cJSON_Utils.c

示例12: genFromDevArrayJson

/*-------------------------------------------------------------------
 Function: genFromDevArrayJson(json_devArray)
 Purpose: generate json data from dev list json
 Parameters: json_devArray -- [IN], dev list json in json file
 return: 0 -- success
         -1 -- failed
-------------------------------------------------------------------*/
int CEhJsonReader::genFromDevArrayJson(cJSON* json_devArray)
{
    cJSON* json_dev = NULL;
    cJSON* json_addrArray = NULL;
    cJSON* json_addr = NULL;
    int devCount = 0;
    int addrCount = 0;
    int devPos = 0;
    int addrPos = 0;

    if (!json_devArray)
        return -1;

    if (!m_jsonTransData)
        m_jsonTransData = cJSON_CreateArray();

    devCount = cJSON_GetArraySize(json_devArray);
    for (devPos = 0; devPos < devCount; devPos++) {
        json_dev = cJSON_GetArrayItem(json_devArray, devPos);
        if (!json_dev)
            return -1;

        json_addrArray = cJSON_GetObjectItem(json_dev, JSONADDRESS);
        if (!json_addrArray)
            return -1;

        addrCount = cJSON_GetArraySize(json_addrArray);
        for (addrPos = 0; addrPos < addrCount; addrPos++) {
            json_addr = cJSON_GetArrayItem(json_addrArray, addrPos);

            //copy
            cJSON_AddItemToArray(m_jsonTransData, 
                cJSON_Duplicate(json_addr, 1));
        }
    }

    return 0;
}
开发者ID:Yoko2012,项目名称:ehome,代码行数:45,代码来源:ehdbManager.cpp

示例13: calloc

struct coin777 *coin777_create(char *coinstr,cJSON *argjson)
{
    char *serverport,*path=0,*conf=0; struct destbuf tmp;
    struct coin777 *coin = calloc(1,sizeof(*coin));
    if ( coinstr == 0 || coinstr[0] == 0 )
    {
        printf("null coinstr?\n");
        //getchar();
        return(0);
    }
    safecopy(coin->name,coinstr,sizeof(coin->name));
    coin->jvin = -1;
    if ( argjson == 0 || strcmp(coinstr,"NXT") == 0 )
    {
        coin->usep2sh = 1;
        coin->minconfirms = (strcmp("BTC",coinstr) == 0) ? 3 : 10;
        coin->estblocktime = (strcmp("BTC",coinstr) == 0) ? 600 : 120;
        coin->mgw.use_addmultisig = (strcmp("BTC",coinstr) != 0);
    }
    else
    {
        coin->minoutput = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"minoutput"));
        coin->minconfirms = get_API_int(cJSON_GetObjectItem(argjson,"minconfirms"),(strcmp("BTC",coinstr) == 0) ? 3 : 10);
        coin->estblocktime = get_API_int(cJSON_GetObjectItem(argjson,"estblocktime"),(strcmp("BTC",coinstr) == 0) ? 600 : 120);
        coin->jsonstr = cJSON_Print(argjson);
        coin->argjson = cJSON_Duplicate(argjson,1);
        if ( (serverport= cJSON_str(cJSON_GetObjectItem(argjson,"rpc"))) != 0 )
            safecopy(coin->serverport,serverport,sizeof(coin->serverport));
        path = cJSON_str(cJSON_GetObjectItem(argjson,"path"));
        conf = cJSON_str(cJSON_GetObjectItem(argjson,"conf"));

        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"assetid")), safecopy(coin->mgw.assetidstr,tmp.buf,sizeof(coin->mgw.assetidstr));
        if ( (coin->mgw.assetidbits= calc_nxt64bits(coin->mgw.assetidstr)) == 0 )
            coin->mgw.assetidbits = is_MGWcoin(coinstr);
        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"issuer")), safecopy(coin->mgw.issuer,tmp.buf,sizeof(coin->mgw.issuer));;
        coin->mgw.issuerbits = conv_acctstr(coin->mgw.issuer);
        printf(">>>>>>>>>>>> a issuer.%s %llu assetid.%llu minoutput.%llu\n",coin->mgw.issuer,(long long)coin->mgw.issuerbits,(long long)coin->mgw.assetidbits,(long long)coin->minoutput);
        //uint32_t set_assetname(uint64_t *multp,char *name,uint64_t assetbits);
        if ( coin->mgw.assetidbits != 0 )
            _set_assetname(&coin->mgw.ap_mult,coin->mgw.assetname,0,coin->mgw.assetidbits);
        printf("assetname.(%s) mult.%llu\n",coin->mgw.assetname,coin->mgw.ap_mult);
        strcpy(coin->mgw.coinstr,coinstr);
        if ( (coin->mgw.special= cJSON_GetObjectItem(argjson,"special")) == 0 )
            coin->mgw.special = cJSON_GetObjectItem(COINS.argjson,"special");
        if ( coin->mgw.special != 0 )
        {
            coin->mgw.special = NXT_convjson(coin->mgw.special);
            printf("CONVERTED.(%s)\n",cJSON_Print(coin->mgw.special));
        }
        coin->mgw.limbo = cJSON_GetObjectItem(argjson,"limbo");
        coin->mgw.dust = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"dust"));
        coin->mgw.txfee = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"txfee_satoshis"));
        if ( coin->mgw.txfee == 0 )
            coin->mgw.txfee = (uint64_t)(SATOSHIDEN * get_API_float(cJSON_GetObjectItem(argjson,"txfee")));
        coin->mgw.NXTfee_equiv = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"NXTfee_equiv_satoshis"));
        if ( coin->mgw.NXTfee_equiv == 0 )
            coin->mgw.NXTfee_equiv = (uint64_t)(SATOSHIDEN * get_API_float(cJSON_GetObjectItem(argjson,"NXTfee_equiv")));
        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"opreturnmarker")), safecopy(coin->mgw.opreturnmarker,tmp.buf,sizeof(coin->mgw.opreturnmarker));
        printf("OPRETURN.(%s)\n",coin->mgw.opreturnmarker);
        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"marker2")), safecopy(coin->mgw.marker2,tmp.buf,sizeof(coin->mgw.marker2));
        coin->mgw.redeemheight = get_API_int(cJSON_GetObjectItem(argjson,"redeemheight"),430000);
        coin->mgw.use_addmultisig = get_API_int(cJSON_GetObjectItem(argjson,"useaddmultisig"),(strcmp("BTC",coinstr) != 0));
        coin->mgw.do_opreturn = get_API_int(cJSON_GetObjectItem(argjson,"do_opreturn"),(strcmp("BTC",coinstr) == 0));
        coin->mgw.oldtx_format = get_API_int(cJSON_GetObjectItem(argjson,"oldtx_format"),(strcmp("BTC",coinstr) == 0));
        coin->mgw.firstunspentind = get_API_int(cJSON_GetObjectItem(argjson,"firstunspent"),(strcmp("BTCD",coinstr) == 0) ? 2500000 : 0);
        if ( (coin->mgw.NXTconvrate = get_API_float(cJSON_GetObjectItem(argjson,"NXTconvrate"))) == 0 )
        {
            if ( coin->mgw.NXTfee_equiv != 0 && coin->mgw.txfee != 0 )
                coin->mgw.NXTconvrate = ((double)coin->mgw.NXTfee_equiv / coin->mgw.txfee);
        }
        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"marker")), safecopy(coin->mgw.marker,tmp.buf,sizeof(coin->mgw.marker));
        printf("OPRETURN.(%s)\n",coin->mgw.opreturnmarker);
        coin->addrtype = get_API_int(jobj(argjson,"addrtype"),0);
        coin->p2shtype = get_API_int(jobj(argjson,"p2shtype"),0);
        coin->usep2sh = get_API_int(jobj(argjson,"usep2sh"),1);
    }
    if ( coin->mgw.txfee == 0 )
        coin->mgw.txfee = 10000;
    if ( strcmp(coin->name,"BTC") == 0 )
    {
        coin->addrtype = 0, coin->p2shtype = 5;
        if ( coin->donationaddress[0] == 0 )
        {
            strcpy(coin->donationaddress,"177MRHRjAxCZc7Sr5NViqHRivDu1sNwkHZ");
            sprintf(coin->donationscript,"76a91443044b8d5dc8f3758dbc83374c596e96d25ead4f88ac");
        }
    }
    else if ( strcmp(coin->name,"LTC") == 0 )
        coin->addrtype = 48, coin->p2shtype = 5, coin->minconfirms = 1, coin->mgw.txfee = 100000, coin->usep2sh = 0;
    else if ( strcmp(coin->name,"BTCD") == 0 )
        coin->addrtype = 60, coin->p2shtype = 85, coin->mgw.txfee = 1000000;//, strcpy(coin->donationaddress,"RDRWMSrDdoUcfZRBWUz7KZQSxPS9bZRerM");
    else if ( strcmp(coin->name,"DOGE") == 0 )
        coin->addrtype = 30, coin->p2shtype = 35;
    else if ( strcmp(coin->name,"VRC") == 0 )
        coin->addrtype = 70, coin->p2shtype = 85;
    else if ( strcmp(coin->name,"OPAL") == 0 )
        coin->addrtype = 115, coin->p2shtype = 28;
    else if ( strcmp(coin->name,"BITS") == 0 )
        coin->addrtype = 25, coin->p2shtype = 8;
    printf("coin777_create %s: (%s) %llu mult.%llu NXTconvrate %.8f minconfirms.%d issuer.(%s) %llu opreturn.%d oldformat.%d\n",coin->mgw.coinstr,coin->mgw.assetidstr,(long long)coin->mgw.assetidbits,(long long)coin->mgw.ap_mult,coin->mgw.NXTconvrate,coin->minconfirms,coin->mgw.issuer,(long long)coin->mgw.issuerbits,coin->mgw.do_opreturn,coin->mgw.oldtx_format);
//.........这里部分代码省略.........
开发者ID:satindergrewal,项目名称:btcd,代码行数:101,代码来源:coins777_main.c

示例14: calloc

struct coin777 *coin777_create(char *coinstr,cJSON *argjson)
{
    char *serverport,*path=0,*conf=0; struct destbuf tmp;
    struct coin777 *coin = calloc(1,sizeof(*coin));
    safecopy(coin->name,coinstr,sizeof(coin->name));
    if ( argjson == 0 )
    {
        coin->minconfirms = (strcmp("BTC",coinstr) == 0) ? 3 : 10;
        coin->estblocktime = (strcmp("BTC",coinstr) == 0) ? 600 : 120;
    }
    else
    {
        coin->minoutput = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"minoutput"));
        coin->minconfirms = get_API_int(cJSON_GetObjectItem(argjson,"minconfirms"),(strcmp("BTC",coinstr) == 0) ? 3 : 10);
        coin->estblocktime = get_API_int(cJSON_GetObjectItem(argjson,"estblocktime"),(strcmp("BTC",coinstr) == 0) ? 600 : 120);
        coin->jsonstr = cJSON_Print(argjson);
        coin->argjson = cJSON_Duplicate(argjson,1);
        if ( (serverport= cJSON_str(cJSON_GetObjectItem(argjson,"rpc"))) != 0 )
            safecopy(coin->serverport,serverport,sizeof(coin->serverport));
        path = cJSON_str(cJSON_GetObjectItem(argjson,"path"));
        conf = cJSON_str(cJSON_GetObjectItem(argjson,"conf"));

        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"assetid")), safecopy(coin->mgw.assetidstr,tmp.buf,sizeof(coin->mgw.assetidstr));
        coin->mgw.assetidbits = calc_nxt64bits(coin->mgw.assetidstr);
        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"issuer")), safecopy(coin->mgw.issuer,tmp.buf,sizeof(coin->mgw.issuer));;
        coin->mgw.issuerbits = conv_acctstr(coin->mgw.issuer);
        printf(">>>>>>>>>>>> a issuer.%s %llu assetid.%llu minoutput.%llu\n",coin->mgw.issuer,(long long)coin->mgw.issuerbits,(long long)coin->mgw.assetidbits,(long long)coin->minoutput);
        //uint32_t set_assetname(uint64_t *multp,char *name,uint64_t assetbits);
        _set_assetname(&coin->mgw.ap_mult,coin->mgw.assetname,0,coin->mgw.assetidbits);
        printf("assetname.(%s) mult.%llu\n",coin->mgw.assetname,coin->mgw.ap_mult);
        strcpy(coin->mgw.coinstr,coinstr);
        if ( (coin->mgw.special= cJSON_GetObjectItem(argjson,"special")) == 0 )
            coin->mgw.special = cJSON_GetObjectItem(COINS.argjson,"special");
        if ( coin->mgw.special != 0 )
            coin->mgw.special = NXT_convjson(coin->mgw.special);
        printf("CONVERTED.(%s)\n",cJSON_Print(coin->mgw.special));
        coin->mgw.limbo = cJSON_GetObjectItem(argjson,"limbo");
        coin->mgw.dust = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"dust"));
        coin->mgw.txfee = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"txfee_satoshis"));
        if ( coin->mgw.txfee == 0 )
            coin->mgw.txfee = (uint64_t)(SATOSHIDEN * get_API_float(cJSON_GetObjectItem(argjson,"txfee")));
        if ( coin->mgw.txfee == 0 )
            coin->mgw.txfee = 10000;
        coin->mgw.NXTfee_equiv = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"NXTfee_equiv_satoshis"));
        if ( coin->mgw.NXTfee_equiv == 0 )
            coin->mgw.NXTfee_equiv = (uint64_t)(SATOSHIDEN * get_API_float(cJSON_GetObjectItem(argjson,"NXTfee_equiv")));
        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"opreturnmarker")), safecopy(coin->mgw.opreturnmarker,tmp.buf,sizeof(coin->mgw.opreturnmarker));
        printf("OPRETURN.(%s)\n",coin->mgw.opreturnmarker);
        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"marker2")), safecopy(coin->mgw.marker2,tmp.buf,sizeof(coin->mgw.marker2));
        coin->mgw.redeemheight = get_API_int(cJSON_GetObjectItem(argjson,"redeemheight"),430000);
        coin->mgw.use_addmultisig = get_API_int(cJSON_GetObjectItem(argjson,"useaddmultisig"),(strcmp("BTC",coinstr) != 0));
        coin->mgw.do_opreturn = get_API_int(cJSON_GetObjectItem(argjson,"do_opreturn"),(strcmp("BTC",coinstr) == 0));
        coin->mgw.oldtx_format = get_API_int(cJSON_GetObjectItem(argjson,"oldtx_format"),(strcmp("BTC",coinstr) == 0));
        coin->mgw.firstunspentind = get_API_int(cJSON_GetObjectItem(argjson,"firstunspent"),(strcmp("BTCD",coinstr) == 0) ? 2500000 : 0);
        if ( (coin->mgw.NXTconvrate = get_API_float(cJSON_GetObjectItem(argjson,"NXTconvrate"))) == 0 )
        {
            if ( coin->mgw.NXTfee_equiv != 0 && coin->mgw.txfee != 0 )
                coin->mgw.NXTconvrate = ((double)coin->mgw.NXTfee_equiv / coin->mgw.txfee);
        }
        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"marker")), safecopy(coin->mgw.marker,tmp.buf,sizeof(coin->mgw.marker));
        printf("OPRETURN.(%s)\n",coin->mgw.opreturnmarker);
    }
    printf("coin777_create %s: (%s) %llu mult.%llu NXTconvrate %.8f minconfirms.%d issuer.(%s) %llu opreturn.%d oldformat.%d\n",coin->mgw.coinstr,coin->mgw.assetidstr,(long long)coin->mgw.assetidbits,(long long)coin->mgw.ap_mult,coin->mgw.NXTconvrate,coin->minconfirms,coin->mgw.issuer,(long long)coin->mgw.issuerbits,coin->mgw.do_opreturn,coin->mgw.oldtx_format);
    extract_userpass(coin->serverport,coin->userpass,coinstr,SUPERNET.userhome,path,conf);
    printf("COIN.%s serverport.(%s) userpass.(%s)\n",coin->name,coin->serverport,coin->userpass);
    COINS.LIST = realloc(COINS.LIST,(COINS.num+1) * sizeof(*coin));
    COINS.LIST[COINS.num] = coin, COINS.num++;
    //ensure_packedptrs(coin);
    return(coin);
}
开发者ID:Bitcoinsulting,项目名称:libjl777,代码行数:70,代码来源:coins777_main.c

示例15: PLUGNAME

int32_t PLUGNAME(_process_json)(char *forwarder,char *sender,int32_t valid,struct plugin_info *plugin,uint64_t tag,char *retbuf,int32_t maxlen,char *jsonstr,cJSON *json,int32_t initflag,char *tokenstr)
{
    char *resultstr,*methodstr,zerobuf[1],*coinstr,*str = 0; cJSON *array,*item; int32_t i,n,j = 0; struct coin777 *coin; struct destbuf tmp;
    retbuf[0] = 0;
    if ( initflag > 0 )
    {
        if ( json != 0 )
        {
            COINS.argjson = cJSON_Duplicate(json,1);
            COINS.slicei = get_API_int(cJSON_GetObjectItem(json,"slice"),0);
            if ( (array= cJSON_GetObjectItem(json,"coins")) != 0 && (n= cJSON_GetArraySize(array)) > 0 )
            {
                for (i=j=0; i<n; i++)
                {
                    item = cJSON_GetArrayItem(array,i);
                    coinstr = cJSON_str(cJSON_GetObjectItem(item,"name"));
                    if ( coinstr != 0 && coinstr[0] != 0 && (coin= coin777_find(coinstr,0)) == 0 )
                    {
                        printf("CALL coin777_create.(%s) (%s)\n",coinstr,cJSON_Print(item));
                        coin777_create(coinstr,item);
                    }
                }
            }
        } else strcpy(retbuf,"{\"result\":\"no JSON for init\"}");
        COINS.readyflag = 1;
        plugin->allowremote = 1;
        //plugin->sleepmillis = 1;
    }
    else
    {
        if ( plugin_result(retbuf,json,tag) > 0 )
            return((int32_t)strlen(retbuf));
        resultstr = cJSON_str(cJSON_GetObjectItem(json,"result"));
        methodstr = cJSON_str(cJSON_GetObjectItem(json,"method"));
        coinstr = cJSON_str(cJSON_GetObjectItem(json,"coin"));
        if ( methodstr == 0 || methodstr[0] == 0 )
        {
            printf("(%s) has not method\n",jsonstr);
            return(0);
        }
        //printf("COINS.(%s) for (%s) (%s)\n",methodstr,coinstr!=0?coinstr:"",jsonstr);
        if ( resultstr != 0 && strcmp(resultstr,"registered") == 0 )
        {
            plugin->registered = 1;
            strcpy(retbuf,"{\"result\":\"activated\"}");
        }
        else
        {
            zerobuf[0] = 0;
            str = 0;
            //printf("INSIDE COINS.(%s) methods.%ld\n",jsonstr,sizeof(coins_methods)/sizeof(*coins_methods));
            copy_cJSON(&tmp,cJSON_GetObjectItem(json,"NXT")), safecopy(sender,tmp.buf,32);
            if ( coinstr == 0 )
                coinstr = zerobuf;
            else coin = coin777_find(coinstr,1);
#ifdef INSIDE_MGW
            if ( strcmp(methodstr,"acctpubkeys") == 0 )
            {
                if ( SUPERNET.gatewayid >= 0 )
                {
                    if ( coinstr[0] == 0 )
                        strcpy(retbuf,"{\"result\":\"need to specify coin\"}");
                    else if ( (coin= coin777_find(coinstr,1)) != 0 )
                    {
                        int32_t MGW_publish_acctpubkeys(char *coinstr,char *str);
                        char *get_msig_pubkeys(char *coinstr,char *serverport,char *userpass);
                        if ( (str= get_msig_pubkeys(coin->name,coin->serverport,coin->userpass)) != 0 )
                        {
                            MGW_publish_acctpubkeys(coin->name,str);
                            strcpy(retbuf,"{\"result\":\"published and processed acctpubkeys\"}");
                            free(str), str= 0;
                        } else sprintf(retbuf,"{\"error\":\"no get_msig_pubkeys result\",\"method\":\"%s\"}",methodstr);
                    } else sprintf(retbuf,"{\"error\":\"no coin777\",\"method\":\"%s\"}",methodstr);
                } else sprintf(retbuf,"{\"error\":\"gateway only method\",\"method\":\"%s\"}",methodstr);
            }
            else if ( strcmp(methodstr,"gotmsigaddr") == 0 )
            {
                if ( SUPERNET.gatewayid < 0 )
                    printf("GOTMSIG.(%s)\n",jsonstr);
            }
            else
#endif
                sprintf(retbuf,"{\"error\":\"unsupported method\",\"method\":\"%s\"}",methodstr);
        }
    }
    //printf("<<<<<<<<<<<< INSIDE PLUGIN.(%s) initflag.%d process %s slice.%d\n",SUPERNET.myNXTaddr,initflag,plugin->name,COINS.slicei);
    return(plugin_copyretstr(retbuf,maxlen,str));
}
开发者ID:Bitcoinsulting,项目名称:libjl777,代码行数:88,代码来源:coins777_main.c


注:本文中的cJSON_Duplicate函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。