void athenaTransportLinkAdapter_Destroy(AthenaTransportLinkAdapter **athenaTransportLinkAdapter) { // release listener instances if ((*athenaTransportLinkAdapter)->listenerList) { for (int index = 0; index < parcArrayList_Size((*athenaTransportLinkAdapter)->listenerList); index++) { AthenaTransportLink *athenaTransportLink = parcArrayList_Get((*athenaTransportLinkAdapter)->listenerList, index); athenaTransportLink_Close(athenaTransportLink); } } // release live instances if ((*athenaTransportLinkAdapter)->instanceList) { for (int index = 0; index < parcArrayList_Size((*athenaTransportLinkAdapter)->instanceList); index++) { AthenaTransportLink *athenaTransportLink = parcArrayList_Get((*athenaTransportLinkAdapter)->instanceList, index); if (athenaTransportLink) { athenaTransportLink_Close(athenaTransportLink); } } } parcArrayList_Destroy(&((*athenaTransportLinkAdapter)->moduleList)); parcArrayList_Destroy(&((*athenaTransportLinkAdapter)->instanceList)); parcArrayList_Destroy(&((*athenaTransportLinkAdapter)->listenerList)); if ((*athenaTransportLinkAdapter)->pollfdReceiveList) { parcMemory_Deallocate(&((*athenaTransportLinkAdapter)->pollfdReceiveList)); parcMemory_Deallocate(&((*athenaTransportLinkAdapter)->pollfdSendList)); parcMemory_Deallocate(&((*athenaTransportLinkAdapter)->pollfdTransportLink)); } parcLog_Release(&((*athenaTransportLinkAdapter)->log)); parcMemory_Deallocate(athenaTransportLinkAdapter); }
static CCNxMetaMessage * _PIT_Command(Athena *athena, CCNxInterest *interest) { CCNxMetaMessage *responseMessage; responseMessage = athenaPIT_ProcessMessage(athena->athenaPIT, interest); if (responseMessage) { return responseMessage; } CCNxName *ccnxName = ccnxInterest_GetName(interest); if (ccnxName_GetSegmentCount(ccnxName) > AthenaCommandSegment) { CCNxNameSegment *nameSegment = ccnxName_GetSegment(ccnxName, AthenaCommandSegment); char *command = ccnxNameSegment_ToString(nameSegment); if (strcasecmp(command, AthenaCommand_List) == 0) { parcLog_Debug(athena->log, "PIT List command invoked"); PARCList *pitEntries = athenaPIT_CreateEntryList(athena->athenaPIT); printf("\n"); for (size_t i = 0; i < parcList_Size(pitEntries); ++i) { PARCBuffer *strbuf = parcList_GetAtIndex(pitEntries, i); char *toprint = parcBuffer_ToString(strbuf); parcLog_Info(athena->log, "%s\n", toprint); parcMemory_Deallocate(&toprint); } parcList_Release(&pitEntries); responseMessage = _create_response(athena, ccnxName, "PIT listed on forwarder output log."); } else { responseMessage = _create_response(athena, ccnxName, "Unknown command: %s", command); } parcMemory_Deallocate(&command); } return responseMessage; }
/** * Given a CCnxInterest that matched our domain prefix, see what the embedded command is and * create a corresponding CCNxContentObject as a response. The resulting CCNxContentObject * must eventually be released by calling ccnxContentObject_Release(). * * @param [in] interest A CCNxInterest that matched the specified domain prefix. * @param [in] domainPrefix A CCNxName containing the domain prefix. * @param [in] directoryPath A string containing the path to the directory being served. * * @return A newly creatd CCNxContentObject contaning a response to the specified Interest, * or NULL if the Interest couldn't be answered. */ static CCNxContentObject * _createInterestResponse(const CCNxInterest *interest, const CCNxName *domainPrefix, const char *directoryPath) { CCNxName *interestName = ccnxInterest_GetName(interest); char *command = tutorialCommon_CreateCommandStringFromName(interestName, domainPrefix); uint64_t requestedChunkNumber = tutorialCommon_GetChunkNumberFromName(interestName); char *interestNameString = ccnxName_ToString(interestName); printf("tutorialServer: received Interest for chunk %d of %s, command = %s\n", (int) requestedChunkNumber, interestNameString, command); parcMemory_Deallocate((void **) &interestNameString); CCNxContentObject *result = NULL; if (strncasecmp(command, tutorialCommon_CommandList, strlen(command)) == 0) { // This was a 'list' command. We should return the requested chunk of the directory listing. result = _createListResponse(interestName, directoryPath, requestedChunkNumber); } else if (strncasecmp(command, tutorialCommon_CommandFetch, strlen(command)) == 0) { // This was a 'fetch' command. We should return the requested chunk of the file specified. char *fileName = tutorialCommon_CreateFileNameFromName(interestName); result = _createFetchResponse(interestName, directoryPath, fileName, requestedChunkNumber); parcMemory_Deallocate((void **) &fileName); } parcMemory_Deallocate((void **) &command); return result; }
static void _metisStreamConnection_DestroyOperations(MetisIoOperations **opsPtr) { assertNotNull(opsPtr, "Parameter opsPtr must be non-null double pointer"); assertNotNull(*opsPtr, "Parameter opsPtr must dereference to non-null pointer"); MetisIoOperations *ops = *opsPtr; assertNotNull(metisIoOperations_GetClosure(ops), "ops->context must not be null"); _MetisStreamState *stream = (_MetisStreamState *) metisIoOperations_GetClosure(ops); parcEventQueue_Destroy(&stream->bufferEventVector); metisAddressPair_Release(&stream->addressPair); if (!stream->isClosed) { stream->isClosed = true; metisMessenger_Send(metisForwarder_GetMessenger(stream->metis), metisMissive_Create(MetisMissiveType_ConnectionClosed, stream->id)); } metisMessenger_Send(metisForwarder_GetMessenger(stream->metis), metisMissive_Create(MetisMissiveType_ConnectionDestroyed, stream->id)); if (metisLogger_IsLoggable(stream->logger, MetisLoggerFacility_IO, PARCLogLevel_Info)) { metisLogger_Log(stream->logger, MetisLoggerFacility_IO, PARCLogLevel_Info, __func__, "StreamConnection %p destroyed", (void *) stream); } metisLogger_Release(&stream->logger); parcMemory_Deallocate((void **) &stream); parcMemory_Deallocate((void **) &ops); *opsPtr = NULL; }
void athena_ProcessMessage(Athena *athena, CCNxMetaMessage *ccnxMessage, PARCBitVector *ingressVector) { if (ccnxMetaMessage_IsInterest(ccnxMessage)) { const char *name = ccnxName_ToString(ccnxInterest_GetName(ccnxMessage)); parcLog_Debug(athena->log, "Processing Interest Message: %s", name); parcMemory_Deallocate(&name); CCNxInterest *interest = ccnxMetaMessage_GetInterest(ccnxMessage); _processInterest(athena, interest, ingressVector); athena->stats.numProcessedInterests++; } else if (ccnxMetaMessage_IsContentObject(ccnxMessage)) { const char *name = ccnxName_ToString(ccnxContentObject_GetName(ccnxMessage)); parcLog_Debug(athena->log, "Processing Content Object Message: %s", name); parcMemory_Deallocate(&name); CCNxContentObject *contentObject = ccnxMetaMessage_GetContentObject(ccnxMessage); _processContentObject(athena, contentObject, ingressVector); athena->stats.numProcessedContentObjects++; } else if (ccnxMetaMessage_IsControl(ccnxMessage)) { parcLog_Debug(athena->log, "Processing Control Message"); CCNxControl *control = ccnxMetaMessage_GetControl(ccnxMessage); _processControl(athena, control, ingressVector); athena->stats.numProcessedControlMessages++; } else if (ccnxMetaMessage_IsInterestReturn(ccnxMessage)) { parcLog_Debug(athena->log, "Processing Interest Return Message"); CCNxInterestReturn *interestReturn = ccnxMetaMessage_GetInterestReturn(ccnxMessage); _processInterestReturn(athena, interestReturn, ingressVector); athena->stats.numProcessedInterestReturns++; } else { trapUnexpectedState("Invalid CCNxMetaMessage type"); } }
LONGBOW_TEST_CASE(JSON, parcJSON_BuildString) { TestData *data = longBowTestCase_GetClipBoardData(testCase); PARCBufferComposer *composer = parcBufferComposer_Create(); parcJSON_BuildString(data->json, composer, false); PARCBuffer *tempBuffer = parcBufferComposer_ProduceBuffer(composer); char *actual = parcBuffer_ToString(tempBuffer); parcBuffer_Release(&tempBuffer); parcBufferComposer_Release(&composer); assertTrue(strcmp(data->expected, actual) == 0, "Expected %s, actual %s", data->expected, actual); parcMemory_Deallocate((void **) &actual); composer = parcBufferComposer_Create(); parcJSON_BuildString(data->json, composer, true); tempBuffer = parcBufferComposer_ProduceBuffer(composer); actual = parcBuffer_ToString(tempBuffer); parcBuffer_Release(&tempBuffer); parcBufferComposer_Release(&composer); assertTrue(strcmp(data->compactExpected, actual) == 0, "Expected %s, actual %s", data->compactExpected, actual); parcMemory_Deallocate((void **) &actual); }
static void _expand(PARCHashCodeTable *hashCodeTable) { LinearAddressingHashTable temp_table; LinearAddressingHashTable *old_table = &hashCodeTable->hashtable; size_t expandby = EXPAND_FACTOR; // start with a copy of the current table PARCHashCodeTable_AddResult result = ADD_OK; do { hashCodeTable->expandCount++; temp_table.tableSize = 0; temp_table.tableLimit = old_table->tableLimit * expandby; temp_table.expandThreshold = temp_table.tableLimit - temp_table.tableLimit / 4; temp_table.entries = parcMemory_AllocateAndClear(temp_table.tableLimit * sizeof(HashTableEntry)); assertNotNull(temp_table.entries, "parcMemory_AllocateAndClear(%zu) returned NULL", temp_table.tableLimit * sizeof(HashTableEntry)); result = _rehash(old_table, &temp_table, hashCodeTable->keyEqualsFunc); if (result == ADD_NOSPACE) { // could not rehash, so expand by more and try again parcMemory_Deallocate((void **) &(temp_table.entries)); expandby++; } } while (result == ADD_NOSPACE); parcMemory_Deallocate((void **) &old_table->entries); hashCodeTable->hashtable = temp_table; }
static void _TemplateLinkData_Destroy(_TemplateLinkData **linkData) { parcMemory_Deallocate(&((*linkData)->linkIdentity)); parcDeque_Release(&((*linkData)->queue)); parcMemory_Deallocate(linkData); }
/** * Receive a ContentObject message that comes back from the tutorial_Server in response to an Interest we sent. * This message will be a chunk of the requested content, and should be received in ordered sequence. * Depending on the CCNxName in the content object, we hand it off to either _receiveFileChunk() or * _receiveDirectoryListingChunk() to process. * * @param [in] contentObject A CCNxContentObject containing a response to an CCNxInterest we sent. * @param [in] domainPrefix A CCNxName containing the domain prefix of the content we requested. * * @return The number of chunks of the content left to transfer. */ static uint64_t _receiveContentObject(CCNxContentObject *contentObject, const CCNxName *domainPrefix) { CCNxName *contentName = ccnxContentObject_GetName(contentObject); uint64_t chunkNumber = tutorialCommon_GetChunkNumberFromName(contentName); // Get the number of the final chunk, as specified by the sender. uint64_t finalChunkNumberSpecifiedByServer = ccnxContentObject_GetFinalChunkNumber(contentObject); // Get the type of the incoming message. Was it a response to a fetch' or a 'list' command? char *command = tutorialCommon_CreateCommandStringFromName(contentName, domainPrefix); // Process the payload. PARCBuffer *payload = ccnxContentObject_GetPayload(contentObject); if (strncasecmp(command, tutorialCommon_CommandList, strlen(command)) == 0) { // This is a chunk of the directory listing. _receiveDirectoryListingChunk(payload, chunkNumber, finalChunkNumberSpecifiedByServer); } else if (strncasecmp(command, tutorialCommon_CommandFetch, strlen(command)) == 0) { // This is a chunk of a file. char *fileName = tutorialCommon_CreateFileNameFromName(contentName); _receiveFileChunk(fileName, payload, chunkNumber, finalChunkNumberSpecifiedByServer); parcMemory_Deallocate((void **) &fileName); } else { printf("tutorial_Client: Unknown command: %s\n", command); } parcMemory_Deallocate((void **) &command); return (finalChunkNumberSpecifiedByServer - chunkNumber); // number of chunks left to transfer }
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); }
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; }
static CCNxMetaMessage * _Control_Command_Set(Athena *athena, CCNxName *ccnxName, const char *command) { CCNxMetaMessage *responseMessage = NULL; if (ccnxName_GetSegmentCount(ccnxName) <= (AthenaCommandSegment + 2)) { responseMessage = _create_response(athena, ccnxName, "Athena set arguments required <name> <value>"); return responseMessage; } // Check for required set name argument CCNxNameSegment *nameSegment = ccnxName_GetSegment(ccnxName, AthenaCommandSegment + 1); char *name = ccnxNameSegment_ToString(nameSegment); if (strcasecmp(name, AthenaCommand_LogLevel) == 0) { // Check the level to set the log to nameSegment = ccnxName_GetSegment(ccnxName, AthenaCommandSegment + 2); char *level = ccnxNameSegment_ToString(nameSegment); if (strcasecmp(level, AthenaCommand_LogDebug) == 0) { athenaTransportLinkAdapter_SetLogLevel(athena->athenaTransportLinkAdapter, PARCLogLevel_Debug); parcLog_SetLevel(athena->log, PARCLogLevel_Debug); athenaInterestControl_LogConfigurationChange(athena, ccnxName, NULL); responseMessage = _create_response(athena, ccnxName, "set athena logging level to %s", AthenaCommand_LogDebug); } else if (strcasecmp(level, AthenaCommand_LogInfo) == 0) { athenaTransportLinkAdapter_SetLogLevel(athena->athenaTransportLinkAdapter, PARCLogLevel_Info); parcLog_SetLevel(athena->log, PARCLogLevel_Info); athenaInterestControl_LogConfigurationChange(athena, ccnxName, NULL); responseMessage = _create_response(athena, ccnxName, "set athena logging level to %s", AthenaCommand_LogInfo); } else if (strcasecmp(level, AthenaCommand_LogOff) == 0) { athenaTransportLinkAdapter_SetLogLevel(athena->athenaTransportLinkAdapter, PARCLogLevel_Off); parcLog_SetLevel(athena->log, PARCLogLevel_Off); athenaInterestControl_LogConfigurationChange(athena, ccnxName, NULL); responseMessage = _create_response(athena, ccnxName, "set athena logging level to %s", AthenaCommand_LogOff); } else if (strcasecmp(level, AthenaCommand_LogAll) == 0) { athenaTransportLinkAdapter_SetLogLevel(athena->athenaTransportLinkAdapter, PARCLogLevel_All); parcLog_SetLevel(athena->log, PARCLogLevel_All); athenaInterestControl_LogConfigurationChange(athena, ccnxName, NULL); responseMessage = _create_response(athena, ccnxName, "set athena logging level to %s", AthenaCommand_LogAll); } else if (strcasecmp(level, AthenaCommand_LogError) == 0) { athenaTransportLinkAdapter_SetLogLevel(athena->athenaTransportLinkAdapter, PARCLogLevel_Error); parcLog_SetLevel(athena->log, PARCLogLevel_Error); athenaInterestControl_LogConfigurationChange(athena, ccnxName, NULL); responseMessage = _create_response(athena, ccnxName, "set athena logging level to %s", AthenaCommand_LogError); } else if (strcasecmp(level, AthenaCommand_LogNotice) == 0) { athenaTransportLinkAdapter_SetLogLevel(athena->athenaTransportLinkAdapter, PARCLogLevel_Notice); parcLog_SetLevel(athena->log, PARCLogLevel_Notice); athenaInterestControl_LogConfigurationChange(athena, ccnxName, NULL); responseMessage = _create_response(athena, ccnxName, "set athena logging level to %s", AthenaCommand_LogNotice); } else { responseMessage = _create_response(athena, ccnxName, "unknown logging level (%s)", level); } parcMemory_Deallocate(&level); } else { responseMessage = _create_response(athena, ccnxName, "Athena unknown set name (%s)", name); } parcMemory_Deallocate(&name); return responseMessage; }
static bool _metisConfiguration_AddConnectionEthernet(MetisConfiguration *config, CPIConnectionEthernet *etherConn, CPIAddress *linkAddress, MetisListenerOps *listenerOps) { bool success = false; const char *symbolic = cpiConnectionEthernet_GetSymbolicName(etherConn); if (!metisSymbolicNameTable_Exists(config->symbolicNameTable, symbolic)) { const CPIAddress *remote = cpiConnectionEthernet_GetPeerLinkAddress(etherConn); MetisAddressPair *pair = metisAddressPair_Create(linkAddress, remote); MetisGenericEther *ether = metisEtherListener_GetGenericEtherFromListener(listenerOps); if (ether) { MetisIoOperations *ops = metisEtherConnection_Create(config->metis, ether, pair); if (ops) { MetisConnection *conn = metisConnection_Create(ops); assertNotNull(conn, "Failed to create connection"); metisConnectionTable_Add(metisForwarder_GetConnectionTable(config->metis), conn); metisSymbolicNameTable_Add(config->symbolicNameTable, symbolic, metisConnection_GetConnectionId(conn)); success = true; if (metisLogger_IsLoggable(config->logger, MetisLoggerFacility_Config, PARCLogLevel_Debug)) { char *peerAddressString = cpiAddress_ToString(remote); metisLogger_Log(config->logger, MetisLoggerFacility_Config, PARCLogLevel_Debug, __func__, "Add connection %s on %s to %s, connid %u", symbolic, cpiConnectionEthernet_GetInterfaceName(etherConn), peerAddressString, metisConnection_GetConnectionId(conn)); parcMemory_Deallocate((void **) &peerAddressString); } } } else { metisLogger_Log(config->logger, MetisLoggerFacility_Config, PARCLogLevel_Error, __func__, "Could not get MetisGenericEther for listener %p", listenerOps); } metisAddressPair_Release(&pair); } else { if (metisLogger_IsLoggable(config->logger, MetisLoggerFacility_Config, PARCLogLevel_Warning)) { const CPIAddress *remote = cpiConnectionEthernet_GetPeerLinkAddress(etherConn); char *peerAddressString = cpiAddress_ToString(remote); metisLogger_Log(config->logger, MetisLoggerFacility_Config, PARCLogLevel_Warning, __func__, "Add connection %s on %s to %s failed, symbolic name exists", symbolic, cpiConnectionEthernet_GetInterfaceName(etherConn), peerAddressString); parcMemory_Deallocate((void **) &peerAddressString); } } return success; }
static CCNxMetaMessage * _TransportLinkAdapter_Command(Athena *athena, CCNxInterest *interest) { CCNxMetaMessage *responseMessage; responseMessage = athenaTransportLinkAdapter_ProcessMessage(athena->athenaTransportLinkAdapter, interest); if (responseMessage) { return responseMessage; } CCNxName *ccnxName = ccnxInterest_GetName(interest); if (ccnxName_GetSegmentCount(ccnxName) > AthenaCommandSegment) { CCNxNameSegment *nameSegment = ccnxName_GetSegment(ccnxName, AthenaCommandSegment); char *command = ccnxNameSegment_ToString(nameSegment); char *arguments = _get_arguments(interest); if (arguments == NULL) { responseMessage = _create_response(athena, ccnxName, "No link arguments given to %s command", command); parcMemory_Deallocate(&command); return responseMessage; } if (strcasecmp(command, AthenaCommand_Add) == 0) { if (arguments) { PARCURI *connectionURI = parcURI_Parse(arguments); if (connectionURI == NULL) { responseMessage = _create_response(athena, ccnxName, "Could not parse URI: %s", arguments); return responseMessage; } const char *linkName = athenaTransportLinkAdapter_Open(athena->athenaTransportLinkAdapter, connectionURI); parcURI_Release(&connectionURI); if (linkName) { responseMessage = _create_response(athena, ccnxName, "%s", linkName); athenaInterestControl_LogConfigurationChange(athena, ccnxName, "%s", arguments); } else { responseMessage = _create_response(athena, ccnxName, "New %s link failed: %s", arguments, strerror(errno)); } } } else if (strcasecmp(command, AthenaCommand_Remove) == 0) { if (arguments) { int result = athenaTransportLinkAdapter_CloseByName(athena->athenaTransportLinkAdapter, arguments); if (result) { responseMessage = _create_response(athena, ccnxName, "removal of %s failed", arguments); } else { responseMessage = _create_response(athena, ccnxName, "%s removed", arguments); athenaInterestControl_LogConfigurationChange(athena, ccnxName, "%s", arguments); } } } else { responseMessage = _create_response(athena, ccnxName, "Unknown TransportLinkAdapter command %s", command); } parcMemory_Deallocate(&command); parcMemory_Deallocate(&arguments); } return responseMessage; }
static void _parcLogger_Destroy(PARCLog **loggerPtr) { PARCLog *logger = *loggerPtr; parcMemory_Deallocate((void **) &logger->hostName); parcMemory_Deallocate((void **) &logger->applicationName); parcMemory_Deallocate((void **) &logger->processId); parcLogReporter_Release(&logger->reporter); }
static void _parcLogEntry_Destroy(PARCLogEntry **entryPtr) { PARCLogEntry *entry = *entryPtr; parcMemory_Deallocate((void **) &entry->hostName); parcMemory_Deallocate((void **) &entry->applicationName); parcMemory_Deallocate((void **) &entry->processName); parcBuffer_Release(&entry->payload); }
static void _strategyAll_ImplDestroy(MetisStrategyImpl **strategyPtr) { assertNotNull(strategyPtr, "Parameter must be non-null double pointer"); assertNotNull(*strategyPtr, "Parameter must dereference to non-null pointer"); MetisStrategyImpl *impl = *strategyPtr; StrategyAll *strategy = (StrategyAll *) impl->context; parcMemory_Deallocate((void **) &strategy); parcMemory_Deallocate((void **) &impl); *strategyPtr = NULL; }
/** * SHOULD ONLY BE CALLED FROM ARRAYLIST * * Do not call this on your own!! It should only be called when an * item is removed from the cli->openSessions array list. * * Will close the tcp session and free memory. * * @param <#param1#> * * Example: * @code * <#example#> * @endcode */ static void _metisCliSession_Destory(_MetisCommandLineInterface_Session **cliSessionPtr) { assertNotNull(cliSessionPtr, "Parameter must be non-null double pointer"); assertNotNull(*cliSessionPtr, "Parameter must dereference to non-null pointer"); _MetisCommandLineInterface_Session *session = *cliSessionPtr; assertTrue(session->doingTheRightThing, "Ha! caught you! You called Destroy outside the PARCArrayList"); parcEventQueue_Destroy(&(session->streamBuffer)); parcMemory_Deallocate((void **) &(session->clientAddress)); parcMemory_Deallocate((void **) &session); *cliSessionPtr = NULL; }
void athenaTransportLinkModule_Destroy(AthenaTransportLinkModule **athenaTransportLinkModule) { int index = (int) parcArrayList_Size((*athenaTransportLinkModule)->instanceList); while (index-- > 0) { AthenaTransportLink *transportLink; transportLink = parcArrayList_Get((*athenaTransportLinkModule)->instanceList, 0); athenaTransportLink_Close(transportLink); } parcArrayList_Destroy(&((*athenaTransportLinkModule)->instanceList)); parcMemory_Deallocate(&((*athenaTransportLinkModule)->name)); parcLog_Release(&((*athenaTransportLinkModule)->log)); parcMemory_Deallocate(athenaTransportLinkModule); }
LONGBOW_TEST_CASE(JSON, parcJSON_GetByPath) { TestData *data = longBowTestCase_GetClipBoardData(testCase); PARCJSON *json = data->json; char *s = parcJSON_ToString(json); printf("%s\n", s); parcMemory_Deallocate((void **) &s); const PARCJSONValue *value = parcJSON_GetByPath(json, "/string"); assertTrue(parcJSONValue_IsString(value), "Expected /string to be a string type."); value = parcJSON_GetByPath(json, "/null"); assertTrue(parcJSONValue_IsNull(value), "Expected /null to be a null type."); value = parcJSON_GetByPath(json, "/true"); assertTrue(parcJSONValue_IsBoolean(value), "Expected /true to be a boolean type."); value = parcJSON_GetByPath(json, "/integer"); assertTrue(parcJSONValue_IsNumber(value), "Expected /integer to be a number type."); value = parcJSON_GetByPath(json, "/float"); assertTrue(parcJSONValue_IsNumber(value), "Expected /float to be a number type."); value = parcJSON_GetByPath(json, "/array"); assertTrue(parcJSONValue_IsArray(value), "Expected /array to be an array type."); value = parcJSON_GetByPath(json, "/nonexistent"); assertNull(value, "Expected /nonexistent to be NULL"); value = parcJSON_GetByPath(json, "/array/1"); assertTrue(parcJSONValue_IsBoolean(value), "Expected /array/0 to be a boolean type."); value = parcJSON_GetByPath(json, "/array/5"); assertTrue(parcJSONValue_IsArray(value), "Expected /array/5 to be an array type."); assertNotNull(value, "Expected non-null pair"); }
LONGBOW_TEST_CASE(Global, parcNotifier_ThreadedTest) { TestData *data = parcMemory_AllocateAndClear(sizeof(TestData)); assertNotNull(data, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(TestData)); data->notifier = parcNotifier_Create(); data->notificationsToSend = 10; data->notificationsToRecieve = data->notificationsToSend; data->notificationsSent = 0; data->notificationsReceived = 0; data->barrier = 2; pthread_create(&data->consumerThread, NULL, consumer, data); pthread_create(&data->producerThread, NULL, producer, data); // wait for them to exit pthread_join(data->producerThread, NULL); pthread_join(data->consumerThread, NULL); assertTrue(data->notificationsReceived >= data->notificationsToRecieve, "Did not write all items got %u expected %u\n", data->notificationsReceived, data->notificationsToRecieve); parcNotifier_Release(&data->notifier); parcMemory_Deallocate((void **) &data); }
char * ccnxControlFacade_ToString(const CCNxTlvDictionary *contentDictionary) { char *string; char *jsonString = NULL; PARCJSON *json = ccnxControlFacade_GetJson(contentDictionary); if (json != NULL) { jsonString = parcJSON_ToString(json); } int failure = asprintf(&string, "CCNxControl { isCPI=%s, isNotification=%s, JSON=\"%s\"}", ccnxControlFacade_IsCPI(contentDictionary) ? "true" : "false", ccnxControlFacade_IsNotification(contentDictionary) ? "true" : "false", jsonString != NULL ? jsonString : "NULL"); if (jsonString) { parcMemory_Deallocate((void **) &jsonString); } assertTrue(failure > -1, "Error asprintf"); char *result = parcMemory_StringDuplicate(string, strlen(string)); free(string); return result; }
static PARCBuffer * _encodeControlPlaneInformation(const CCNxControl *cpiControlMessage) { PARCJSON *json = ccnxControl_GetJson(cpiControlMessage); char *str = parcJSON_ToCompactString(json); // include +1 because we need the NULL byte size_t len = strlen(str) + 1; size_t packetLength = sizeof(_MetisTlvFixedHeaderV0) + sizeof(MetisTlvType) + len; PARCBuffer *packet = parcBuffer_Allocate(packetLength); _MetisTlvFixedHeaderV0 hdr; memset(&hdr, 0, sizeof(hdr)); hdr.version = 0; hdr.packetType = METIS_PACKET_TYPE_CONTROL; hdr.payloadLength = htons(len + sizeof(MetisTlvType)); parcBuffer_PutArray(packet, sizeof(hdr), (uint8_t *) &hdr); MetisTlvType tlv = { .type = htons(T_CPI), .length = htons(len) }; parcBuffer_PutArray(packet, sizeof(tlv), (uint8_t *) &tlv); parcBuffer_PutArray(packet, len, (uint8_t *) str); parcMemory_Deallocate((void **) &str); return parcBuffer_Flip(packet); }
/** * string: "facility=level" * Set the right thing in the logger */ static void _setLogLevel(int logLevelArray[MetisLoggerFacility_END], const char *string) { char *tofree = parcMemory_StringDuplicate(string, strlen(string)); char *p = tofree; char *facilityString = strsep(&p, "="); if (facilityString) { char *levelString = p; if (strcasecmp(facilityString, "all") == 0) { for (MetisLoggerFacility facility = 0; facility < MetisLoggerFacility_END; facility++) { _setLogLevelToLevel(logLevelArray, facility, levelString); } } else { MetisLoggerFacility facility; for (facility = 0; facility < MetisLoggerFacility_END; facility++) { if (strcasecmp(facilityString, metisLogger_FacilityString(facility)) == 0) { break; } } if (facility < MetisLoggerFacility_END) { _setLogLevelToLevel(logLevelArray, facility, levelString); } else { printf("Invalid facility string %s\n", facilityString); _usage(EXIT_FAILURE); } } } parcMemory_Deallocate((void **) &tofree); }
static CCNxMetaMessage * _ContentStore_Command(Athena *athena, CCNxInterest *interest) { CCNxMetaMessage *responseMessage; responseMessage = athenaContentStore_ProcessMessage(athena->athenaContentStore, interest); if (responseMessage) { return responseMessage; } CCNxName *ccnxName = ccnxInterest_GetName(interest); if (ccnxName_GetSegmentCount(ccnxName) > AthenaCommandSegment) { CCNxNameSegment *nameSegment = ccnxName_GetSegment(ccnxName, AthenaCommandSegment); char *command = ccnxNameSegment_ToString(nameSegment); //char *arguments = _get_arguments(interest); //responseMessage = _create_response(athena, ccnxName, ... //parcMemory_Deallocate(&command); //if (arguments) { // parcMemory_Deallocate(&arguments); //} parcMemory_Deallocate(&command); } return responseMessage; }
LONGBOW_TEST_CASE(Global, metisSystem_Interfaces) { MetisForwarder *metis = metisForwarder_Create(NULL); CPIInterfaceSet *set = metisSystem_Interfaces(metis); assertNotNull(set, "metisSystem_Interfaces return null set"); // XXX we need some sort of validation test. e.g. open a socket, then ioctl to // XXX get the interface name, then verify its in the list. size_t length = cpiInterfaceSet_Length(set); assertTrue(length > 0, "metisSystem_Interfaces returned no interfaces"); for (size_t i = 0; i < length; i++) { CPIInterface *iface = cpiInterfaceSet_GetByOrdinalIndex(set, i); printf("Interface Index %u\n", cpiInterface_GetInterfaceIndex(iface)); const CPIAddressList *list = cpiInterface_GetAddresses(iface); PARCJSONArray *jsonArray = cpiAddressList_ToJson(list); char *str = parcJSONArray_ToString(jsonArray); printf("%s\n", str); parcMemory_Deallocate((void **) &str); parcJSONArray_Release(&jsonArray); } cpiInterfaceSet_Destroy(&set); metisForwarder_Destroy(&metis); }
static void _athenaLRUContentStoreEntry_Display(const _AthenaLRUContentStoreEntry *entry, int indentation) { int childIndentation = indentation + 2; //strlen("AthenaLRUContentStoreEntry"); parcDisplayIndented_PrintLine(indentation, "AthenaLRUContentStoreEntry {%p, prev = %p, next = %p, co = %p, size = %zu", entry, entry->prev, entry->next, entry->contentObject, entry->sizeInBytes); const CCNxName *name = ccnxContentObject_GetName(entry->contentObject); if (name) { char *nameString = ccnxName_ToString(name); parcDisplayIndented_PrintLine(childIndentation, "Name: %p [%s]", name, nameString); parcMemory_Deallocate(&nameString); } else { parcDisplayIndented_PrintLine(childIndentation, "Name: NULL"); } if (entry->hasExpiryTime) { parcDisplayIndented_PrintLine(childIndentation, "ExpiryTime: [%" PRIu64 "]", entry->expiryTime); } if (entry->hasRecommendedCacheTime) { parcDisplayIndented_PrintLine(childIndentation, "RecommendedCacheTime: [%" PRIu64 "]", entry->recommendedCacheTime); } parcDisplayIndented_PrintLine(childIndentation, "}"); }
static int compare_sends(struct fdstate *s, uint8_t *buffer, size_t buffer_len) { struct sendlist *expected = s->expected[ s->head ]; int res; s->head = (s->head + 1) % MAXPENDING; assertTrue(expected->length == buffer_len, "%s lengths do not match, expected %zu got %zu\n", __func__, expected->length, buffer_len); if (expected->length != buffer_len) { return -1; } res = memcmp(expected->buffer, buffer, buffer_len); assertTrue(res == 0, "%s buffers did not match\n", __func__); if (res != 0) { return -1; } assertTrue(expected->refcount > 0, "%s invalid refcount\n", __func__); expected->refcount--; if (expected->refcount == 0) { memset(expected, 0, sizeof(struct sendlist)); parcMemory_Deallocate((void **) &expected); } return 0; }
LONGBOW_TEST_CASE(Local, _Inet6_BuildString) { struct sockaddr_in6 addr_in6; memset(&addr_in6, 0, sizeof(struct sockaddr_in6)); inet_pton(AF_INET6, "2001:720:1500:1::a100", &(addr_in6.sin6_addr)); addr_in6.sin6_family = AF_INET6; addr_in6.sin6_port = htons(43215); char *expected = "inet6://[2001:720:1500:1::a100%0]:43215"; CPIAddress *cpiaddr = cpiAddress_CreateFromInet6(&addr_in6); PARCBufferComposer *composer = parcBufferComposer_Create(); _Inet6_BuildString(cpiaddr, composer); PARCBuffer *tempBuffer = parcBufferComposer_ProduceBuffer(composer); char *actual = parcBuffer_ToString(tempBuffer); parcBuffer_Release(&tempBuffer); parcBufferComposer_Release(&composer); assertTrue(strcmp(expected, actual) == 0, "Expected '%s' actual '%s'", expected, actual); parcMemory_Deallocate((void **) &actual); cpiAddress_Destroy(&cpiaddr); }
LONGBOW_TEST_CASE(Global, cpiAddress_ToString_INET) { struct sockaddr_in *addr_in = parcNetwork_SockInet4Address("1.2.3.4", 12345); char expected[] = "inet4://1.2.3.4:12345"; CPIAddress *cpiaddr = cpiAddress_CreateFromInet(addr_in); char *actual = cpiAddress_ToString(cpiaddr); assertTrue(strcmp(actual, expected) == 0, "Bad string, expected '%s' got '%s'", expected, actual); parcMemory_Deallocate((void **) &actual); cpiAddress_Destroy(&cpiaddr); parcMemory_Deallocate((void **) &addr_in); }