示例#1
0
struct timespec *
parcJSONValue_GetTimespec(const PARCJSONValue *jsonTimespec, struct timespec *timespec)
{
    assertNotNull(jsonTimespec, "Parameter jsonTimeval must be a non-null PARCJSON pointer.");

    PARCJSON *json = parcJSONValue_GetJSON(jsonTimespec);
    PARCJSONValue *value = parcJSON_GetValueByName(json, "seconds");
    timespec->tv_sec = parcJSONValue_GetInteger(value);
    value = parcJSON_GetValueByName(json, "nanos");
    timespec->tv_nsec = (int) parcJSONValue_GetInteger(value);

    return timespec;
}
示例#2
0
struct timeval *
parcJSONValue_GetTimeval(const PARCJSONValue *jsonTimeval, struct timeval *timeval)
{
    assertNotNull(jsonTimeval, "Parameter jsonTimeval must be a non-null PARCJSON pointer.");

    PARCJSON *json = parcJSONValue_GetJSON(jsonTimeval);
    PARCJSONValue *value = parcJSON_GetValueByName(json, "seconds");
    timeval->tv_sec = parcJSONValue_GetInteger(value);
    value = parcJSON_GetValueByName(json, "micros");
    timeval->tv_usec = (int) parcJSONValue_GetInteger(value);

    return timeval;
}
示例#3
0
LONGBOW_TEST_CASE(JSON, parcJSON_AddInteger)
{
    PARCJSON *json = parcJSON_Create();

    char *expectedName = "integer";
    uint64_t expectedValue = 12345;

    parcJSON_AddInteger(json, expectedName, expectedValue);

    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(expectedValue == parcJSONValue_GetInteger(actualValue),
               "Expected %" PRIi64 "d actual %" PRIi64 "d", expectedValue, parcJSONValue_GetInteger(actualValue));

    parcJSON_Release(&json);
}
示例#4
0
CCNxPortalAnchor *
ccnxPortalAnchor_CreateFromJSON(const PARCJSON *json)
{
    CCNxPortalAnchor *result = parcObject_CreateInstance(CCNxPortalAnchor);

    if (result != NULL) {
        result->prefix = ccnxName_CreateFromURI(parcBuffer_Overlay(parcJSONValue_GetString(parcJSON_GetByPath(json, "/namePrefix")), 0));
        result->expireTime = parcJSONValue_GetInteger(parcJSON_GetByPath(json, "/expireTime"));

       ccnxPortalAnchor_OptionalAssertValid(result);
    }

    return result;
}
示例#5
0
LONGBOW_TEST_CASE(JSON, parcJSON_GetValueByName)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);

    int expected = 31415;
    const PARCJSONValue *value = parcJSON_GetValueByName(data->json, "integer");

    int64_t actual = parcJSONValue_GetInteger(value);

    PARCBuffer *expectedName = parcBuffer_WrapCString("integer");

    assertTrue(expected == actual, "Expected %d, actual %" PRIi64 "", expected, actual);

    parcBuffer_Release(&expectedName);
}
示例#6
0
LONGBOW_TEST_CASE(JSON, parcJSON_GetPairByName)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);

    int expected = 31415;
    const PARCJSONPair *pair = parcJSON_GetPairByName(data->json, "integer");

    PARCBuffer *name = parcJSONPair_GetName(pair);
    PARCJSONValue *value = parcJSONPair_GetValue(pair);

    int64_t actual = parcJSONValue_GetInteger(value);

    PARCBuffer *expectedName = parcBuffer_WrapCString("integer");

    assertTrue(parcBuffer_Equals(expectedName, name),
               "Expected 'integer', actual '%s'", (char *) parcBuffer_ToString(name));

    assertTrue(expected == actual, "Expected %d, actual %" PRIi64 "", expected, actual);

    parcBuffer_Release(&expectedName);
}
uint64_t
controlPlaneInterface_GetSequenceNumber(const PARCJSON *controlPlaneMessage)
{
    assertNotNull(controlPlaneMessage, "Invalid state, got NULL json from control message");

    PARCJSONValue *value = parcJSON_GetValueByName(controlPlaneMessage, cpiRequest);
    if (value == NULL) {
        value = parcJSON_GetValueByName(controlPlaneMessage, cpiResponse);
    }
    if (value == NULL) {
        value = parcJSON_GetValueByName(controlPlaneMessage, cpiAck);
    }

    assertNotNull(value, "Could not get request or response");

    PARCJSON *json = parcJSONValue_GetJSON(value);
    value = parcJSON_GetValueByName(json, cpiSeqnum);
    assertNotNull(value, "Could not retrieve key %s from CPI section", cpiSeqnum);

    return parcJSONValue_GetInteger(value);
}
CCNxManifestHashGroup *
ccnxManifestHashGroup_CreateFromJson(const PARCJSON *json)
{
    CCNxManifestHashGroup *group = ccnxManifestHashGroup_Create();

    PARCJSONValue *ptrListValue = parcJSON_GetValueByName(json, "HashGroup");
    PARCJSONArray *ptrList = parcJSONValue_GetArray(ptrListValue);
    size_t numberOfPointers = parcJSONArray_GetLength(ptrList);
    for (size_t i = 0; i < numberOfPointers; i++) {
        PARCJSONValue *pointerValue = parcJSONArray_GetValue(ptrList, i);

        PARCJSON *typeJson = parcJSONValue_GetJSON(pointerValue);
        PARCJSONValue *typeValue = parcJSON_GetValueByName(typeJson, "type");
        CCNxManifestHashGroupPointerType type;

        if (parcJSONValue_GetInteger(typeValue) == 0) {
            type = CCNxManifestHashGroupPointerType_Data;
        } else {
            type = CCNxManifestHashGroupPointerType_Manifest;
        }

        PARCJSON *digestJson = parcJSONValue_GetJSON(pointerValue);
        PARCJSONValue *digestValue = parcJSON_GetValueByName(digestJson, "digest");
        PARCBuffer *digestHex = parcJSONValue_GetString(digestValue);

        char *hexString = parcBuffer_ToString(digestHex);
        PARCBuffer *digest = parcBuffer_Flip(parcBuffer_ParseHexString(hexString));
        parcMemory_Deallocate(&hexString);

        ccnxManifestHashGroup_AppendPointer(group, type, digest);
        parcBuffer_Release(&digest);
    }

    if (parcJSON_GetPairByName(json, "overallDataDigest") != NULL) {
        PARCJSONValue *overallDataDigestValue = parcJSON_GetValueByName(json, "overallDataDigest");
        PARCBuffer *digestHex = parcJSONValue_GetString(overallDataDigestValue);

        char *hexString = parcBuffer_ToString(digestHex);
        group->overallDataDigest = parcBuffer_Flip(parcBuffer_ParseHexString(hexString));
        parcMemory_Deallocate(&hexString);
    }

    if (parcJSON_GetPairByName(json, "locator") != NULL) {
        PARCJSONValue *locatorValue = parcJSON_GetValueByName(json, "locator");
        PARCBuffer *buffer = parcJSONValue_GetString(locatorValue);
        char *locator = parcBuffer_ToString(buffer);
        group->locator = ccnxName_CreateFromCString(locator);
        parcMemory_Deallocate(&locator);
    }

    if (parcJSON_GetPairByName(json, "entrySize") != NULL) {
        PARCJSONValue *childBlockNodeSizeValue = parcJSON_GetValueByName(json, "entrySize");
        group->entrySize = parcJSONValue_GetInteger(childBlockNodeSizeValue);
    }

    if (parcJSON_GetPairByName(json, "dataSize") != NULL) {
        PARCJSONValue *totalSizeValue = parcJSON_GetValueByName(json, "dataSize");
        group->dataSize = parcJSONValue_GetInteger(totalSizeValue);
    }

    if (parcJSON_GetPairByName(json, "blockSize") != NULL) {
        PARCJSONValue *blockSizeValue = parcJSON_GetValueByName(json, "blockSize");
        group->blockSize = parcJSONValue_GetInteger(blockSizeValue);
    }

    if (parcJSON_GetPairByName(json, "treeHeight") != NULL) {
        PARCJSONValue *treeHeightValue = parcJSON_GetValueByName(json, "treeHeight");
        group->treeHeight = parcJSONValue_GetInteger(treeHeightValue);
    }

    return group;
}
示例#9
0
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;
}