コード例 #1
0
ファイル: test_parc_JSONArray.c プロジェクト: isolis/Libparc
LONGBOW_TEST_CASE(parc_JSONArray, parcJSONArray_BuildString)
{
    PARCJSONArray *array = parcJSONArray_Create();
    PARCJSONValue *expected = parcJSONValue_CreateFromInteger(10);
    parcJSONArray_AddValue(array, expected);

    PARCBufferComposer *composer = parcBufferComposer_Create();
    parcJSONArray_BuildString(array, composer, false);

    PARCBuffer *tempBuffer = parcBufferComposer_ProduceBuffer(composer);
    parcBufferComposer_Release(&composer);
    char *result = parcBuffer_ToString(tempBuffer);
    parcBuffer_Release(&tempBuffer);

    assertTrue(strlen(result) > 0, "Expected non-empty string result");

    parcMemory_Deallocate((void **) &result);

    composer = parcBufferComposer_Create();
    parcJSONArray_BuildString(array, composer, true);
    tempBuffer = parcBufferComposer_ProduceBuffer(composer);
    parcBufferComposer_Release(&composer);
    result = parcBuffer_ToString(tempBuffer);
    parcBuffer_Release(&tempBuffer);

    assertTrue(strlen(result) > 0, "Expected non-empty string result");

    parcMemory_Deallocate((void **) &result);

    parcJSONValue_Release(&expected);
    parcJSONArray_Release(&array);
}
コード例 #2
0
PARCJSON *
ccnxManifest_ToJSON(const CCNxManifest *manifest)
{
    PARCJSON *root = parcJSON_Create();

    char *nameString = ccnxName_ToString(ccnxManifest_GetName(manifest));
    parcJSON_AddString(root, "locator", nameString);
    parcMemory_Deallocate(&nameString);

    PARCJSONArray *array = parcJSONArray_Create();
    for (size_t i = 0; i < ccnxManifest_GetNumberOfHashGroups(manifest); i++) {
        CCNxManifestHashGroup *group = ccnxManifest_GetHashGroupByIndex(manifest, i);
        PARCJSON *groupJson = ccnxManifestHashGroup_ToJson(group);
        PARCJSONValue *jsonValue = parcJSONValue_CreateFromJSON(groupJson);

        parcJSONArray_AddValue(array, jsonValue);

        parcJSONValue_Release(&jsonValue);
        parcJSON_Release(&groupJson);
        ccnxManifestHashGroup_Release(&group);
    }
    parcJSON_AddArray(root, "HashGroups", array);
    parcJSONArray_Release(&array);

    return root;
}
コード例 #3
0
ファイル: test_parc_JSON.c プロジェクト: PARC/Libparc
LONGBOW_TEST_CASE(JSON, parcJSON_AddValue)
{
    PARCJSON *json = parcJSON_Create();

    char *expectedName = "value";

    PARCJSONValue *value = parcJSONValue_CreateFromCString("Some Pig");

    parcJSON_AddValue(json, expectedName, value);

    const PARCJSONPair *pair = parcJSON_GetPairByName(json, expectedName);

    PARCBuffer *actualName = parcJSONPair_GetName(pair);
    PARCJSONValue *actualValue = parcJSONPair_GetValue(pair);
    assertTrue(strcmp(expectedName, parcBuffer_Overlay(actualName, 0)) == 0,
               "Expected name %s, actual %s", expectedName, (char *) parcBuffer_ToString(actualName));
    assertTrue(parcJSONValue_IsString(actualValue), "Expect value to be type PARCJSONArray");
    assertTrue(parcBuffer_Equals(parcJSONValue_GetString(actualValue), parcJSONValue_GetString(value)),
               "Expected %s actual %s",
               parcJSONValue_ToString(value),
               parcJSONValue_ToString(actualValue));

    parcJSONValue_Release(&value);

    parcJSON_Release(&json);
}
コード例 #4
0
PARCJSON *
ccnxManifestHashGroup_ToJson(const CCNxManifestHashGroup *group)
{
    PARCJSON *root = parcJSON_Create();

    PARCJSONArray *ptrList = parcJSONArray_Create();
    for (size_t i = 0; i < parcLinkedList_Size(group->pointers); i++) {
        CCNxManifestHashGroupPointer *ptr = (CCNxManifestHashGroupPointer *) parcLinkedList_GetAtIndex(group->pointers, i);
        PARCJSON *ptrJson = parcJSON_Create();

        // Type.
        parcJSON_AddInteger(ptrJson, "type", ccnxManifestHashGroupPointer_GetType(ptr));

        // Digest.
        char *digestString = parcBuffer_ToHexString(ptr->digest);
        parcJSON_AddString(ptrJson, "digest", digestString);
        parcMemory_Deallocate(&digestString);

        // Add the tuple to the list.
        PARCJSONValue *val = parcJSONValue_CreateFromJSON(ptrJson);
        parcJSONArray_AddValue(ptrList, val);

        // Cleanup
        parcJSONValue_Release(&val);
        parcJSON_Release(&ptrJson);
    }
    root = parcJSON_AddArray(root, "HashGroup", ptrList);
    parcJSONArray_Release(&ptrList);

    if (group->overallDataDigest != NULL) {
        char *digestString = parcBuffer_ToHexString(group->overallDataDigest);
        root = parcJSON_AddString(root, "overallDataDigest", digestString);
        parcMemory_Deallocate((void **) &digestString);
    }

    if (group->locator != NULL) {
        char *locatorString = ccnxName_ToString(group->locator);
        root = parcJSON_AddString(root, "locator", locatorString);
        parcMemory_Deallocate((void **) &locatorString);
    }

    if (group->entrySize > 0) {
        root = parcJSON_AddInteger(root, "entrySize", group->entrySize);
    }

    if (group->dataSize > 0) {
        root = parcJSON_AddInteger(root, "dataSize", group->dataSize);
    }

    if (group->blockSize > 0) {
        root = parcJSON_AddInteger(root, "blockSize", group->blockSize);
    }

    if (group->treeHeight > 0) {
        root = parcJSON_AddInteger(root, "treeHeight", group->treeHeight);
    }

    return root;
}
コード例 #5
0
CCNxConnectionConfig *
vegasFlowController_ConnectionConfig(CCNxConnectionConfig *connectionConfig)
{
    PARCJSONValue *value = parcJSONValue_CreateFromNULL();
    CCNxConnectionConfig *result = ccnxConnectionConfig_Add(connectionConfig, vegasFlowController_GetName(), value);
    parcJSONValue_Release(&value);
    return result;
}
コード例 #6
0
/**
 * Generates:
 *
 * { "FC_VEGAS" : { } }
 */
CCNxStackConfig *
vegasFlowController_ProtocolStackConfig(CCNxStackConfig *stackConfig)
{
    PARCJSONValue *value = parcJSONValue_CreateFromNULL();
    CCNxStackConfig *result = ccnxStackConfig_Add(stackConfig, vegasFlowController_GetName(), value);
    parcJSONValue_Release(&value);
    return result;
}
コード例 #7
0
CCNxConnectionConfig *
tlvCodec_ConnectionConfig(CCNxConnectionConfig *connectionConfig)
{
    PARCJSONValue *value = parcJSONValue_CreateFromNULL();
    CCNxConnectionConfig *result = ccnxConnectionConfig_Add(connectionConfig, tlvCodec_GetName(), value);
    parcJSONValue_Release(&value);
    return result;
}
コード例 #8
0
/**
 * Generates:
 *
 * { "CODEC_TLV" : { } }
 */
CCNxStackConfig *
tlvCodec_ProtocolStackConfig(CCNxStackConfig *stackConfig)
{
    PARCJSONValue *value = parcJSONValue_CreateFromNULL();
    CCNxStackConfig *result = ccnxStackConfig_Add(stackConfig, tlvCodec_GetName(), value);
    parcJSONValue_Release(&value);

    return result;
}
コード例 #9
0
ファイル: test_parc_JSONArray.c プロジェクト: isolis/Libparc
LONGBOW_TEST_CASE(parc_JSONArray, parcJSONArray_AddValue)
{
    PARCJSONArray *expected = parcJSONArray_Create();
    PARCJSONValue *value = parcJSONValue_CreateFromInteger(10);
    parcJSONArray_AddValue(expected, value);
    parcJSONValue_Release(&value);

    parcJSONArray_Release(&expected);
}
コード例 #10
0
ファイル: test_parc_JSONArray.c プロジェクト: isolis/Libparc
LONGBOW_TEST_CASE(parc_JSONArray, parcJSONArray_GetLength)
{
    PARCJSONArray *expected = parcJSONArray_Create();
    PARCJSONValue *value = parcJSONValue_CreateFromInteger(10);
    parcJSONArray_AddValue(expected, value);
    parcJSONValue_Release(&value);
    assertTrue(parcJSONArray_GetLength(expected) == 1, "Expected a length of 1");

    parcJSONArray_Release(&expected);
}
コード例 #11
0
ファイル: test_parc_JSONArray.c プロジェクト: isolis/Libparc
LONGBOW_TEST_CASE(parc_JSONArray, parcJSONArray_Display)
{
    PARCJSONArray *array = parcJSONArray_Create();
    PARCJSONValue *expected = parcJSONValue_CreateFromInteger(10);
    parcJSONArray_AddValue(array, expected);
    parcJSONValue_Release(&expected);

    parcJSONArray_Display(array, 0);

    parcJSONArray_Release(&array);
}
コード例 #12
0
CCNxConnectionConfig *
publicKeySignerPkcs12Store_ConnectionConfig(CCNxConnectionConfig *connConfig, const char *filename, const char *password)
{
    assertNotNull(connConfig, "Parameter connConfig must be non-null");
    assertNotNull(filename, "Parameter filename must be non-null");
    assertNotNull(password, "Parameter password must be non-null");

    PARCJSONValue *signerNameJson = parcJSONValue_CreateFromCString((char *) publicKeySignerPkcs12Store_GetName());
    ccnxConnectionConfig_Add(connConfig, param_SIGNER, signerNameJson);
    parcJSONValue_Release(&signerNameJson);

    PARCJSON *keystoreJson = parcJSON_Create();
    parcJSON_AddString(keystoreJson, param_KEYSTORE_NAME, filename);
    parcJSON_AddString(keystoreJson, param_KEYSTORE_PASSWD, password);

    PARCJSONValue *value = parcJSONValue_CreateFromJSON(keystoreJson);
    parcJSON_Release(&keystoreJson);
    CCNxConnectionConfig *result = ccnxConnectionConfig_Add(connConfig, publicKeySignerPkcs12Store_GetName(), value);
    parcJSONValue_Release(&value);
    return result;
}
コード例 #13
0
ファイル: test_parc_JSONArray.c プロジェクト: isolis/Libparc
LONGBOW_TEST_CASE(parc_JSONArray, parcJSONArray_GetValue)
{
    PARCJSONArray *array = parcJSONArray_Create();
    PARCJSONValue *expected = parcJSONValue_CreateFromInteger(10);
    parcJSONArray_AddValue(array, expected);

    PARCJSONValue *actual = parcJSONArray_GetValue(array, 0);

    assertTrue(expected == actual, "Expected different value");

    parcJSONValue_Release(&expected);
    parcJSONArray_Release(&array);
}
コード例 #14
0
ファイル: test_parc_JSONArray.c プロジェクト: isolis/Libparc
LONGBOW_TEST_CASE(parc_JSONArray, parcJSONArray_ToString)
{
    PARCJSONArray *array = parcJSONArray_Create();
    PARCJSONValue *expected = parcJSONValue_CreateFromInteger(10);
    parcJSONArray_AddValue(array, expected);
    parcJSONValue_Release(&expected);

    const char *string = parcJSONArray_ToString(array);

    parcMemory_Deallocate((void **) &string);

    parcJSONArray_Release(&array);
}
コード例 #15
0
ファイル: parc_JSONValue.c プロジェクト: PARC/Libparc
static PARCJSONValue *
_parcJSONValue_ArrayParser(PARCJSONParser *parser)
{
    PARCJSONValue *result = NULL;

    if (parcJSONParser_NextChar(parser) == '[') {
        PARCJSONArray *array = parcJSONArray_Create();

        while (parcJSONParser_Remaining(parser)) {
            char peek = parcJSONParser_PeekNextChar(parser);
            if (peek == ',') {
                parcJSONParser_NextChar(parser);
            } else if (peek == ']') {
                parcJSONParser_NextChar(parser); // absorb the ']' character
                result = parcJSONValue_CreateFromJSONArray(array);
                parcJSONArray_Release(&array);
                break;
            } else {
                PARCJSONValue *value = NULL;

                if (peek == 'n') {
                    value = _parcJSONValue_NullParser(parser);
                } else if (peek == 't') {
                    value = _parcJSONValue_TrueParser(parser);
                } else if (peek == 'f') {
                    value = _parcJSONValue_FalseParser(parser);
                } else if (peek == '"') {
                    value = _parcJSONValue_StringParser(parser);
                } else if (peek == '{') {
                    value = parcJSONValue_ObjectParser(parser);
                } else if (peek == '[') {
                    value = _parcJSONValue_ArrayParser(parser);
                } else {
                    value = _parcJSONValue_NumberParser(parser);
                }

                if (value != NULL) {
                    parcJSONArray_AddValue(array, value);
                    parcJSONValue_Release(&value);
                } else {
                    parcJSONArray_Release(&array);
                    break;
                }
            }
        }
    }

    return result;
}
コード例 #16
0
LONGBOW_TEST_CASE(Global, ccnxStackConfig_AddGet)
{
    CCNxStackConfig *instance = ccnxStackConfig_Create();

    PARCJSONValue *expected = parcJSONValue_CreateFromNULL();
    ccnxStackConfig_Add(instance, "key", expected);

    PARCJSONValue *actual = ccnxStackConfig_Get(instance, "key");

    assertTrue(parcJSONValue_Equals(expected, actual), "ccnxStackConfig_Get did not return what was 'added'");

    parcJSONValue_Release(&expected);

    ccnxStackConfig_Release(&instance);
}
コード例 #17
0
LONGBOW_TEST_CASE(Global, ccnxStackConfig_Equals)
{
    CCNxStackConfig *x = ccnxStackConfig_Create();
    CCNxStackConfig *y = ccnxStackConfig_Create();
    CCNxStackConfig *z = ccnxStackConfig_Create();

    CCNxStackConfig *u1 = ccnxStackConfig_Create();
    PARCJSONValue *val = parcJSONValue_CreateFromNULL();
    ccnxStackConfig_Add(u1, "key", val);
    parcJSONValue_Release(&val);

    parcObjectTesting_AssertEquals(x, y, z, NULL);

    ccnxStackConfig_Release(&x);
    ccnxStackConfig_Release(&y);
    ccnxStackConfig_Release(&z);
    ccnxStackConfig_Release(&u1);
}
コード例 #18
0
ファイル: test_parc_JSONArray.c プロジェクト: isolis/Libparc
LONGBOW_TEST_CASE(parc_JSONArray, parcJSONArray_Equals)
{
    PARCJSONArray *x = parcJSONArray_Create();
    PARCJSONArray *y = parcJSONArray_Create();
    PARCJSONArray *z = parcJSONArray_Create();

    PARCJSONArray *notEqual1 = parcJSONArray_Create();
    PARCJSONValue *value = parcJSONValue_CreateFromCString("Hello");
    parcJSONArray_AddValue(notEqual1, value);
    parcJSONValue_Release(&value);

    parcObjectTesting_AssertEqualsFunction(parcJSONArray_Equals, x, y, z, notEqual1);

    parcJSONArray_Release(&x);
    parcJSONArray_Release(&y);
    parcJSONArray_Release(&z);
    parcJSONArray_Release(&notEqual1);
}
コード例 #19
0
PARCJSON *
cpiConnectionList_ToJson(const CPIConnectionList *list)
{
    assertNotNull(list, "Parameter must be non-null");

    PARCJSONArray *inner_json = parcJSONArray_Create();

    size_t length = parcArrayList_Size(list->listOfConnections);
    for (size_t i = 0; i < length; i++) {
        CPIConnection *tunnel = (CPIConnection *) parcArrayList_Get(list->listOfConnections, i);
        PARCJSON *json = cpiConnection_ToJson(tunnel);
        PARCJSONValue *value = parcJSONValue_CreateFromJSON(json);
        parcJSON_Release(&json);
        parcJSONArray_AddValue(inner_json, value);
        parcJSONValue_Release(&value);
    }

    PARCJSON *outter_json = parcJSON_Create();
    parcJSON_AddArray(outter_json, cpi_ConnectionList, inner_json);
    parcJSONArray_Release(&inner_json);
    return outter_json;
}
コード例 #20
0
PARCJSON *
cpiInterfaceSet_ToJson(CPIInterfaceSet *set)
{
    assertNotNull(set, "Parameter must be non-null");

    PARCJSONArray *interfaceList = parcJSONArray_Create();

    size_t length = parcArrayList_Size(set->listOfInterfaces);
    for (size_t i = 0; i < length; i++) {
        CPIInterface *iface = (CPIInterface *) parcArrayList_Get(set->listOfInterfaces, i);
        PARCJSON *json = cpiInterface_ToJson(iface);
        PARCJSONValue *value = parcJSONValue_CreateFromJSON(json);
        parcJSON_Release(&json);
        parcJSONArray_AddValue(interfaceList, value);
        parcJSONValue_Release(&value);
    }

    PARCJSON *result = parcJSON_Create();
    parcJSON_AddArray(result, cpi_InterfaceList, interfaceList);
    parcJSONArray_Release(&interfaceList);

    return result;
}
コード例 #21
0
ファイル: test_parc_JSON.c プロジェクト: PARC/Libparc
LONGBOW_TEST_CASE(JSON, parcJSON_Add)
{
    PARCJSON *json = parcJSON_Create();
    {
        PARCBuffer *string = parcBuffer_WrapCString("string");
        PARCJSONValue *stringValue = parcJSONValue_CreateFromString(string);
        PARCBuffer *stringName = parcBuffer_WrapCString("string");
        PARCJSONPair *pair = parcJSONPair_Create(stringName, stringValue);
        parcJSON_AddPair(json, pair);
        parcJSONPair_Release(&pair);
        parcBuffer_Release(&stringName);
        parcJSONValue_Release(&stringValue);
        parcBuffer_Release(&string);
    }
    {
        PARCBuffer *name = parcBuffer_WrapCString("null");
        PARCJSONValue *value = parcJSONValue_CreateFromNULL();
        PARCJSONPair *pair = parcJSONPair_Create(name, value);
        parcJSON_AddPair(json, pair);
        parcJSONPair_Release(&pair);
        parcBuffer_Release(&name);
        parcJSONValue_Release(&value);
    }
    {
        PARCBuffer *name = parcBuffer_WrapCString("true");
        PARCJSONValue *value = parcJSONValue_CreateFromBoolean(true);
        PARCJSONPair *pair = parcJSONPair_Create(name, value);
        parcJSON_AddPair(json, pair);
        parcJSONPair_Release(&pair);
        parcBuffer_Release(&name);
        parcJSONValue_Release(&value);
    }
    {
        PARCBuffer *name = parcBuffer_WrapCString("false");
        PARCJSONValue *value = parcJSONValue_CreateFromBoolean(false);
        PARCJSONPair *pair = parcJSONPair_Create(name, value);
        parcJSON_AddPair(json, pair);
        parcJSONPair_Release(&pair);
        parcBuffer_Release(&name);
        parcJSONValue_Release(&value);
    }
    {
        PARCBuffer *name = parcBuffer_WrapCString("integer");
        PARCJSONValue *value = parcJSONValue_CreateFromInteger(31415);
        PARCJSONPair *pair = parcJSONPair_Create(name, value);
        parcJSON_AddPair(json, pair);
        parcJSONPair_Release(&pair);
        parcBuffer_Release(&name);
        parcJSONValue_Release(&value);
    }
    {
        PARCBuffer *name = parcBuffer_WrapCString("float");
        PARCJSONValue *value = parcJSONValue_CreateFromFloat(3.1415);
        PARCJSONPair *pair = parcJSONPair_Create(name, value);
        parcJSON_AddPair(json, pair);
        parcJSONPair_Release(&pair);
        parcBuffer_Release(&name);
        parcJSONValue_Release(&value);
    }

    parcJSON_Release(&json);
}
コード例 #22
0
ファイル: athena_InterestControl.c プロジェクト: PARC/Athena
static CCNxMetaMessage *
_create_FIBList_response(Athena *athena, CCNxName *ccnxName, PARCList *fibEntryList)
{
    PARCJSON *jsonPayload = parcJSON_Create();
    PARCJSONArray *jsonEntryList = parcJSONArray_Create();
    parcJSON_AddArray(jsonPayload, JSON_KEY_RESULT, jsonEntryList);

    for (size_t i = 0; i < parcList_Size(fibEntryList); ++i) {
        AthenaFIBListEntry *entry = parcList_GetAtIndex(fibEntryList, i);
        if (entry != NULL) {
            CCNxName *prefixName = athenaFIBListEntry_GetName(entry);
            if (prefixName) {
                char *prefix = ccnxName_ToString(prefixName);
                int linkId = athenaFIBListEntry_GetLinkId(entry);
                const char *linkName = athenaTransportLinkAdapter_LinkIdToName(athena->athenaTransportLinkAdapter, linkId);
                parcLog_Debug(athena->log, "  Route: %s->%s", prefix, linkName);

                PARCJSON *jsonItem = parcJSON_Create();
                parcJSON_AddString(jsonItem, JSON_KEY_NAME, prefix);
                parcJSON_AddString(jsonItem, JSON_KEY_LINK, linkName);

                PARCJSONValue *jsonItemValue = parcJSONValue_CreateFromJSON(jsonItem);
                parcJSON_Release(&jsonItem);

                parcJSONArray_AddValue(jsonEntryList, jsonItemValue);
                parcJSONValue_Release(&jsonItemValue);

                parcMemory_Deallocate(&prefix);
            } else {
                int linkId = athenaFIBListEntry_GetLinkId(entry);
                const char *linkName = athenaTransportLinkAdapter_LinkIdToName(athena->athenaTransportLinkAdapter, linkId);
                parcLog_Debug(athena->log, "  Route: <empty>->%s", linkName);

                PARCJSON *jsonItem = parcJSON_Create();
                parcJSON_AddString(jsonItem, JSON_KEY_NAME, "");
                parcJSON_AddString(jsonItem, JSON_KEY_LINK, linkName);

                PARCJSONValue *jsonItemValue = parcJSONValue_CreateFromJSON(jsonItem);
                parcJSON_Release(&jsonItem);

                parcJSONArray_AddValue(jsonEntryList, jsonItemValue);
                parcJSONValue_Release(&jsonItemValue);
            }
        }
    }

    char *jsonString = parcJSON_ToString(jsonPayload);

    parcJSONArray_Release(&jsonEntryList);
    parcJSON_Release(&jsonPayload);

    PARCBuffer *payload = parcBuffer_CreateFromArray(jsonString, strlen(jsonString));

    CCNxContentObject *contentObject =
        ccnxContentObject_CreateWithNameAndPayload(ccnxName, parcBuffer_Flip(payload));

    struct timeval tv;
    gettimeofday(&tv, NULL);
    uint64_t nowInMillis = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
    ccnxContentObject_SetExpiryTime(contentObject, nowInMillis + 100); // this response is good for 100 millis

    CCNxMetaMessage *result = ccnxMetaMessage_CreateFromContentObject(contentObject);

    ccnxContentObject_Release(&contentObject);
    parcBuffer_Release(&payload);
    parcMemory_Deallocate(&jsonString);

    athena_EncodeMessage(result);
    return result;
}
コード例 #23
0
static CCNxMetaMessage *
_create_linkList_response(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, CCNxName *ccnxName)
{
    PARCJSONArray *jsonLinkList = parcJSONArray_Create();

    for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->listenerList); index++) {
        AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->listenerList, index);
        const char *linkName = athenaTransportLink_GetName(athenaTransportLink);
        bool notLocal = athenaTransportLink_IsNotLocal(athenaTransportLink);
        bool localForced = athenaTransportLink_IsForceLocal(athenaTransportLink);
        PARCJSON *jsonItem = parcJSON_Create();
        parcJSON_AddString(jsonItem, "linkName", linkName);
        parcJSON_AddInteger(jsonItem, "index", -1);
        parcJSON_AddBoolean(jsonItem, "notLocal", notLocal);
        parcJSON_AddBoolean(jsonItem, "localForced", localForced);

        PARCJSONValue *jsonItemValue = parcJSONValue_CreateFromJSON(jsonItem);
        parcJSON_Release(&jsonItem);

        parcJSONArray_AddValue(jsonLinkList, jsonItemValue);
        parcJSONValue_Release(&jsonItemValue);

        if (notLocal) {
            parcLog_Debug(athenaTransportLinkAdapter->log, "\n    Link listener%s: %s", localForced ? " (forced remote)" : "", linkName);
        } else {
            parcLog_Debug(athenaTransportLinkAdapter->log, "\n    Link listener%s: %s", localForced ? " (forced local)" : "", linkName);
        }
    }
    for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->instanceList); index++) {
        AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->instanceList, index);
        if (athenaTransportLink) {
            const char *linkName = athenaTransportLink_GetName(athenaTransportLink);
            bool notLocal = athenaTransportLink_IsNotLocal(athenaTransportLink);
            bool localForced = athenaTransportLink_IsForceLocal(athenaTransportLink);
            PARCJSON *jsonItem = parcJSON_Create();
            parcJSON_AddString(jsonItem, "linkName", linkName);
            parcJSON_AddInteger(jsonItem, "index", index);
            parcJSON_AddBoolean(jsonItem, "notLocal", notLocal);
            parcJSON_AddBoolean(jsonItem, "localForced", localForced);

            PARCJSONValue *jsonItemValue = parcJSONValue_CreateFromJSON(jsonItem);
            parcJSON_Release(&jsonItem);

            parcJSONArray_AddValue(jsonLinkList, jsonItemValue);
            parcJSONValue_Release(&jsonItemValue);

            if (notLocal) {
                parcLog_Debug(athenaTransportLinkAdapter->log, "\n    Link instance [%d] %s: %s", index, localForced ? "(forced remote)" : "(remote)", linkName);
            } else {
                parcLog_Debug(athenaTransportLinkAdapter->log, "\n    Link instance [%d] %s: %s", index, localForced ? "(forced local)" : "(local)", linkName);
            }
        }
    }

    char *jsonString = parcJSONArray_ToString(jsonLinkList);

    parcJSONArray_Release(&jsonLinkList);

    PARCBuffer *payload = parcBuffer_CreateFromArray(jsonString, strlen(jsonString));

    CCNxContentObject *contentObject =
        ccnxContentObject_CreateWithDataPayload(ccnxName, parcBuffer_Flip(payload));

    struct timeval tv;
    gettimeofday(&tv, NULL);
    uint64_t nowInMillis = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
    ccnxContentObject_SetExpiryTime(contentObject, nowInMillis + 100); // this response is good for 100 millis

    CCNxMetaMessage *result = ccnxMetaMessage_CreateFromContentObject(contentObject);

    ccnxContentObject_Release(&contentObject);
    parcBuffer_Release(&payload);
    parcMemory_Deallocate(&jsonString);

    athena_EncodeMessage(result);
    return result;
}
コード例 #24
0
ファイル: athenactl.c プロジェクト: chris-wood/ghost
static int
_athenactl_ListLinks(PARCIdentity *identity, int argc, char **argv)
{
    CCNxName *name = ccnxName_CreateFromURI(CCNxNameAthenaCommand_LinkList);
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    ccnxName_Release(&name);

    const char *result = _athenactl_SendInterestControl(identity, interest);
    printf("Link: Interface list");
    if (result) {
        PARCBuffer *buffer = parcBuffer_WrapCString((char *) result);
        PARCJSONParser *parser = parcJSONParser_Create(buffer);
        PARCJSONValue *value = parcJSONValue_Parser(parser);

        if (value == NULL) {
            printf("\n\tCould not parse forwarder list response");
        } else {
            PARCJSONArray *array = parcJSONValue_GetArray(value);

            for (int i = 0; i < parcJSONArray_GetLength(array); i++) {
                PARCJSONValue *getvalue = parcJSONArray_GetValue(array, i);
                PARCJSON *json = parcJSONValue_GetJSON(getvalue);

                PARCJSONValue *pairValue = parcJSON_GetValueByName(json, "linkName");
                PARCBuffer *bufferString = parcJSONValue_GetString(pairValue);
                char *linkName = parcBuffer_ToString(bufferString);

                pairValue = parcJSON_GetValueByName(json, "index");
                int64_t index = parcJSONValue_GetInteger(pairValue);

                pairValue = parcJSON_GetValueByName(json, "notLocal");
                bool notLocal = parcJSONValue_GetBoolean(pairValue);

                pairValue = parcJSON_GetValueByName(json, "localForced");
                bool localForced = parcJSONValue_GetBoolean(pairValue);

                if (index < 0) {
                    if (notLocal) {
                        printf("\n    Link listener%s: %s", localForced ? " (forced remote)" : "", linkName);
                    } else {
                        printf("\n    Link listener%s: %s", localForced ? " (forced local)" : "", linkName);
                    }
                } else {
                    if (notLocal) {
                        printf("\n    Link instance [%" PRId64 "] %s: %s", index, localForced ? "(forced remote)" : "(remote)", linkName);
                    } else {
                        printf("\n    Link instance [%" PRId64 "] %s: %s", index, localForced ? "(forced local)" : "(local)", linkName);
                    }
                }
                parcMemory_Deallocate(&linkName);
            }
            parcJSONValue_Release(&value);
        }

        parcJSONParser_Release(&parser);
        parcBuffer_Release(&buffer);

        parcMemory_Deallocate(&result);
    }
    printf("\nDone.\n");

    ccnxMetaMessage_Release(&interest);

    return 0;
}