LONGBOW_TEST_CASE(Global, ccnxPortalFactory_GetKeyId) { const char *keystoreName = "ccnxPortalFactory_keystore"; parcSecurity_Init(); bool success = parcPkcs12KeyStore_CreateFile(keystoreName, "keystore_password", "consumer", 1024, 30); assertTrue(success, "parcPkcs12KeyStore_CreateFile('%s', 'keystore_password') failed.", keystoreName); PARCIdentityFile *identityFile = parcIdentityFile_Create(keystoreName, "keystore_password"); PARCIdentity *identity = parcIdentity_Create(identityFile, PARCIdentityFileAsPARCIdentity); CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity); const PARCKeyId *actual = ccnxPortalFactory_GetKeyId(factory); PARCSigner *signer = parcIdentity_CreateSigner(identity); PARCKeyId *expected = parcSigner_CreateKeyId(signer); parcSigner_Release(&signer); assertTrue(parcKeyId_Equals(expected, actual), "KeyIds not equal"); parcKeyId_Release(&expected); ccnxPortalFactory_Release(&factory); parcIdentityFile_Release(&identityFile); parcIdentity_Release(&identity); parcSecurity_Fini(); }
CCNxPortalFactory * setupConsumerFactory(void) { PARCIdentity *identity = createAndGetIdentity(); CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity); parcIdentity_Release(&identity); return factory; }
CCNxPortalFactory * ccnxPingCommon_SetupPortalFactory(const char *keystoreName, const char *keystorePassword, const char *subjectName) { PARCIdentity *identity = _ccnxPingCommon_CreateAndGetIdentity(keystoreName, keystorePassword, subjectName); CCNxPortalFactory *result = ccnxPortalFactory_Create(identity); parcIdentity_Release(&identity); return result; }
int ccnServe(const PARCIdentity *identity, const CCNxName *listenName, const char *commandString) { parcSecurity_Init(); CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity); CCNxPortal *portal = ccnxPortalFactory_CreatePortal(factory, ccnxPortalRTA_Message); assertNotNull(portal, "Expected a non-null CCNxPortal pointer."); if (ccnxPortal_Listen(portal, listenName, 365 * 86400, CCNxStackTimeout_Never)) { while (true) { CCNxMetaMessage *request = ccnxPortal_Receive(portal, CCNxStackTimeout_Never); if (request == NULL) { break; } CCNxInterest *interest = ccnxMetaMessage_GetInterest(request); if (interest != NULL) { CCNxName *interestName = ccnxInterest_GetName(interest); PARCBuffer *payload = makePayload(interestName, commandString); CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(interestName, payload); CCNxMetaMessage *message = ccnxMetaMessage_CreateFromContentObject(contentObject); if (ccnxPortal_Send(portal, message, CCNxStackTimeout_Never) == false) { fprintf(stderr, "ccnxPortal_Write failed: %d\n", ccnxPortal_GetError(portal)); } { char *name = ccnxName_ToString(interestName); time_t theTime = time(0); char *time = ctime(&theTime); printf("%24.24s %s\n", time, name); parcMemory_Deallocate((void **) &name); } parcBuffer_Release(&payload); } ccnxMetaMessage_Release(&request); } } ccnxPortal_Release(&portal); ccnxPortalFactory_Release(&factory); parcSecurity_Fini(); return 0; }
LONGBOW_TEST_CASE(CreateAcquireRelease, ccnxPortalFactory_Create) { const char *keystoreName = "ccnxPortalFactory_keystore"; parcSecurity_Init(); bool success = parcPublicKeySignerPkcs12Store_CreateFile(keystoreName, "keystore_password", "consumer", 1024, 30); assertTrue(success, "parcPublicKeySignerPkcs12Store_CreateFile('%s', 'keystore_password') failed.", keystoreName); PARCIdentityFile *identityFile = parcIdentityFile_Create(keystoreName, "keystore_password"); PARCIdentity *identity = parcIdentity_Create(identityFile, PARCIdentityFileAsPARCIdentity); parcIdentityFile_Release(&identityFile); CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity); parcIdentity_Release(&identity); ccnxPortalFactory_Release(&factory); parcSecurity_Fini(); }
int ccnx_Portal_Reader(char *keystoreFileName, const char *password, const char *uri) { parcSecurity_Init(); PARCIdentity *identity = getIdentity_FromFile(keystoreFileName, password); if (identity != NULL) { CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity); reader_writer(factory, uri); ccnxPortalFactory_Release(&factory); parcIdentity_Release(&identity); } parcSecurity_Fini(); return 0; }
int ccnGet(PARCIdentity *identity, CCNxName *name) { CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity); CCNxPortal *portal = ccnxPortalFactory_CreatePortal(factory, ccnxPortalRTA_Message); assertNotNull(portal, "Expected a non-null CCNxPortal pointer."); CCNxInterest *interest = ccnxInterest_CreateSimple(name); ccnxName_Release(&name); CCNxMetaMessage *message = ccnxMetaMessage_CreateFromInterest(interest); if (ccnxPortal_Send(portal, message, CCNxStackTimeout_Never)) { while (ccnxPortal_IsError(portal) == false) { CCNxMetaMessage *response = ccnxPortal_Receive(portal, CCNxStackTimeout_Never); if (response != NULL) { if (ccnxMetaMessage_IsContentObject(response)) { CCNxContentObject *contentObject = ccnxMetaMessage_GetContentObject(response); PARCBuffer *payload = ccnxContentObject_GetPayload(contentObject); size_t length = parcBuffer_Remaining(payload); ssize_t nwritten = write(1, parcBuffer_Overlay(payload, length), length); assertTrue(nwritten == length, "Did not write whole buffer, got %zd expected %zu", nwritten, length); break; } ccnxMetaMessage_Release(&response); } } } ccnxPortal_Release(&portal); ccnxPortalFactory_Release(&factory); return 0; }
LONGBOW_TEST_CASE(Global, ccnxPortalFactory_GetIdentity) { const char *keystoreName = "ccnxPortalFactory_keystore"; parcSecurity_Init(); bool success = parcPkcs12KeyStore_CreateFile(keystoreName, "keystore_password", "consumer", 1024, 30); assertTrue(success, "parcPkcs12KeyStore_CreateFile('%s', 'keystore_password') failed.", keystoreName); PARCIdentityFile *identityFile = parcIdentityFile_Create(keystoreName, "keystore_password"); PARCIdentity *identity = parcIdentity_Create(identityFile, PARCIdentityFileAsPARCIdentity); CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity); const PARCIdentity *actual = ccnxPortalFactory_GetIdentity(factory); assertTrue(identity == actual, "Expected the result to be the same as provided to the constructor"); parcIdentityFile_Release(&identityFile); parcIdentity_Release(&identity); ccnxPortalFactory_Release(&factory); parcSecurity_Fini(); }
LONGBOW_TEST_CASE(CreateAcquireRelease, ccnxPortalFactory_AcquireRelease) { const char *keystoreName = "ccnxPortalFactory_keystore"; parcSecurity_Init(); bool success = parcPkcs12KeyStore_CreateFile(keystoreName, "keystore_password", "consumer", 1024, 30); assertTrue(success, "parcPkcs12KeyStore_CreateFile('%s', 'keystore_password') failed.", keystoreName); PARCIdentityFile *identityFile = parcIdentityFile_Create(keystoreName, "keystore_password"); PARCIdentity *identity = parcIdentity_Create(identityFile, PARCIdentityFileAsPARCIdentity); CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity); parcIdentityFile_Release(&identityFile); parcIdentity_Release(&identity); CCNxPortalFactory *reference = ccnxPortalFactory_Acquire(factory); assertTrue(factory == reference, "Expected Acquire to return its argument."); ccnxPortalFactory_Release(&factory); ccnxPortalFactory_Release(&reference); parcSecurity_Fini(); }
static const char * _athenactl_SendInterestControl(PARCIdentity *identity, CCNxMetaMessage *message) { const char *result = NULL; CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity); CCNxPortal *portal = ccnxPortalFactory_CreatePortal(factory, ccnxPortalRTA_Message); assertNotNull(portal, "Expected a non-null CCNxPortal pointer."); athenactl_EncodeMessage(message); if (ccnxPortal_Send(portal, message, CCNxStackTimeout_Never)) { while (ccnxPortal_IsError(portal) == false) { CCNxMetaMessage *response = ccnxPortal_Receive(portal, CCNxStackTimeout_Never); if (response != NULL) { if (ccnxMetaMessage_IsContentObject(response)) { CCNxContentObject *contentObject = ccnxMetaMessage_GetContentObject(response); PARCBuffer *payload = ccnxContentObject_GetPayload(contentObject); if (payload) { result = parcBuffer_ToString(payload); } } ccnxMetaMessage_Release(&response); break; } } } ccnxPortal_Release(&portal); ccnxPortalFactory_Release(&factory); return result; }
return LONGBOW_STATUS_SUCCEEDED; } LONGBOW_TEST_FIXTURE_TEARDOWN(Errors) { unlink("ccnxPortalFactory_keystore"); uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); if (outstandingAllocations != 0) { printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); return LONGBOW_STATUS_MEMORYLEAK; } return LONGBOW_STATUS_SUCCEEDED; } LONGBOW_TEST_CASE_EXPECTS(Errors, ccnxPortalFactory_Create_NULL_Identity, .event = &LongBowTrapInvalidValue) { CCNxPortalFactory *factory = ccnxPortalFactory_Create(NULL); ccnxPortalFactory_Release(&factory); } int main(int argc, char *argv[argc]) { LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(test_ccnx_PortalFactory); int exitStatus = longBowMain(argc, argv, testRunner, NULL); longBowTestRunner_Destroy(&testRunner); exit(exitStatus); }