Ejemplo n.º 1
0
int
athenaTransportLinkAdapter_CloseByName(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, const char *linkName)
{
    if (athenaTransportLinkAdapter->listenerList) {
        for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->listenerList); index++) {
            AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->listenerList, index);
            if (strcmp(athenaTransportLink_GetName(athenaTransportLink), linkName) == 0) {
                athenaTransportLink_Close(athenaTransportLink);
                return 0;
            }
        }
    }
    if (athenaTransportLinkAdapter->instanceList) {
        for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->instanceList); index++) {
            AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->instanceList, index);
            if (athenaTransportLink) {
                if (strcmp(athenaTransportLink_GetName(athenaTransportLink), linkName) == 0) {
                    athenaTransportLink_Close(athenaTransportLink);
                    return 0;
                }
            }
        }
    }
    errno = ENOENT;
    return -1;
}
Ejemplo n.º 2
0
LONGBOW_TEST_CASE(Global, PARCList_InsertAtIndex_Last)
{
    PARCArrayList *array = parcArrayList_Create(NULL);

    parcArrayList_Add(array, (void *) 1);
    parcArrayList_Add(array, (void *) 2);
    size_t actual = parcArrayList_Size(array);

    assertTrue(2 == actual, "Expected=%d, actual=%zu", 2, actual);

    parcArrayList_InsertAtIndex(array, 2, (void *) 3);

    actual = parcArrayList_Size(array);
    assertTrue(3 == actual, "Expected=%d, actual=%zu", 3, actual);

    void *element0 = parcArrayList_Get(array, 0);
    assertTrue(element0 == (void *) 1, "Element 1 moved?");

    void *element1 = parcArrayList_Get(array, 1);
    assertTrue(element1 == (void *) 2, "Element 1 moved?");

    void *element2 = parcArrayList_Get(array, 2);
    assertTrue(element2 == (void *) 3, "Element 1 moved?");

    parcArrayList_Destroy(&array);
}
Ejemplo n.º 3
0
void
athenaTransportLinkAdapter_SetLogLevel(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, const PARCLogLevel level)
{
    // set log level on main athena module
    parcLog_SetLevel(athenaTransportLinkAdapter->log, level);

    // set log level on all modules
    if (athenaTransportLinkAdapter->moduleList) {
        for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->moduleList); index++) {
            AthenaTransportLinkModule *athenaTransportLinkModule = parcArrayList_Get(athenaTransportLinkAdapter->moduleList, index);
            athenaTransportLinkModule_SetLogLevel(athenaTransportLinkModule, level);
        }
    }
    // set log level on all instances
    if (athenaTransportLinkAdapter->listenerList) {
        for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->listenerList); index++) {
            AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->listenerList, index);
            athenaTransportLink_SetLogLevel(athenaTransportLink, level);
        }
    }
    // set log level on all listener instances
    if (athenaTransportLinkAdapter->instanceList) {
        for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->instanceList); index++) {
            AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->instanceList, index);
            if (athenaTransportLink) {
                athenaTransportLink_SetLogLevel(athenaTransportLink, level);
            }
        }
    }
}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
0
/**
 * @abstract add a new link instance to the AthenaTransportLinkAdapter instance list
 * @discussion
 *
 * When athenaTransportLinkAdapter_Open is called on a link specific module, the module instantiates
 * the link and then creates a new AthenaTransportLink to interface with the AthenaTransportLinkAdapter.
 * The AthenaTransportLinkModule passes the new AthenaTransportLink to the AthenaTransportLinkAdapter by
 * calling AthenaTransportLinkAdapter_AddLink with the new link AthenaTransportLink data. The AthenaTransportLinkAdapter
 * then places the new link instance on its internal instance list in a pending state until it has been verified and ensures
 * that the new link doesn't collide (i.e. by name) with any currently registered link before returning success.
 *
 * New routable links are placed into instanceList slots that have previously been vacated before being added
 * to the end of the instanceList.  This is in order to keep bit vectors that are based on the instanceList as
 * small as is necessary.
 *
 * @param [in] athenaTransportLinkAdapter link adapter instance
 * @param [in] linkInstance instance structure created by the link specific module
 * @return 0 on success, -1 with errno set to indicate the error
 *
 * Example:
 * @code
 * {
 * }
 * @endcode
 */
static int
_athenaTransportLinkAdapter_AddLink(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, AthenaTransportLink *newTransportLink)
{
    int linkId = -1;

    // Check for existing linkName in listenerList
    if (athenaTransportLinkAdapter->listenerList) {
        for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->listenerList); index++) {
            AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->listenerList, index);
            if (strcmp(athenaTransportLink_GetName(athenaTransportLink), athenaTransportLink_GetName(newTransportLink)) == 0) {
                errno = EADDRINUSE; // name is already in listenerList
                return -1;
            }
        }
    }

    // Check for existing linkName in the instanceList
    if (athenaTransportLinkAdapter->instanceList) {
        for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->instanceList); index++) {
            AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->instanceList, index);
            if (athenaTransportLink) {
                if (strcmp(athenaTransportLink_GetName(athenaTransportLink), athenaTransportLink_GetName(newTransportLink)) == 0) {
                    errno = EADDRINUSE; // name is already in instanceList
                    return -1;
                }
            } else {
                // remember the first available index found along the way
                if (linkId == -1) {
                    linkId = index;
                }
            }
        }
    }

    // Add to listenerList or instanceList
    athenaTransportLink_Acquire(newTransportLink);
    if (athenaTransportLink_IsNotRoutable(newTransportLink)) { // listener
        bool result = parcArrayList_Add(athenaTransportLinkAdapter->listenerList, newTransportLink);
        assertTrue(result, "parcArrayList_Add failed to add new listener");
    } else { // routable link, add to instances using the last available id if one was seen
        if (linkId != -1) {
            parcArrayList_Set(athenaTransportLinkAdapter->instanceList, linkId, newTransportLink);
        } else {
            bool result = parcArrayList_Add(athenaTransportLinkAdapter->instanceList, newTransportLink);
            assertTrue(result, "parcArrayList_Add failed to add new link instance");
        }
    }

    // If any transport link has a registered file descriptor add it to the general polling list.
    int eventFd = athenaTransportLink_GetEventFd(newTransportLink);
    if (eventFd != -1) {
        _add_to_pollfdList(athenaTransportLinkAdapter, newTransportLink, eventFd);
    }
    return 0;
}
Ejemplo n.º 6
0
/**
 * @abstract called from below the link adapter to coordinate termination of a link instance
 * @discussion
 *
 * This is called exclusively from the Transport Link Module to instigate the removal of
 * an active link.  The link has been flagged closing by the originator.  This method
 * must ensure that all references to the link have been removed and then call the
 * instance close method to finish the operation.
 *
 * @param [in] athenaTransportLinkAdapter link adapter instance
 * @param [in] athenaTransportLink link instance to remove
 *
 * Example:
 * @code
 * {
 *
 * }
 * @endcode
 */
static void
_athenaTransportLinkAdapter_RemoveLink(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, AthenaTransportLink *athenaTransportLink)
{
    int linkId = -1;

    // if this is a listener it can simply be removed
    if (athenaTransportLink_IsNotRoutable(athenaTransportLink)) {
        if (athenaTransportLinkAdapter->listenerList) {
            for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->listenerList); index++) {
                AthenaTransportLink *transportLink = parcArrayList_Get(athenaTransportLinkAdapter->listenerList, index);
                if (athenaTransportLink == transportLink) {
                    parcArrayList_RemoveAtIndex(athenaTransportLinkAdapter->listenerList, index);
                    _remove_from_pollfdList(athenaTransportLinkAdapter, athenaTransportLink);
                    parcLog_Debug(athenaTransportLinkAdapter_GetLogger(athenaTransportLinkAdapter), "listener removed: %s",
                                  athenaTransportLink_GetName(athenaTransportLink));
                    athenaTransportLink_Release(&athenaTransportLink);
                    return;
                }
            }
        }
    }

    // Remove from our internal instance list.
    // The index entry remains to be reused by links that are added in the future.
    if (athenaTransportLinkAdapter->instanceList) {
        for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->instanceList); index++) {
            AthenaTransportLink *transportLink = parcArrayList_Get(athenaTransportLinkAdapter->instanceList, index);
            if (athenaTransportLink == transportLink) {
                parcArrayList_Set(athenaTransportLinkAdapter->instanceList, index, NULL);
                _remove_from_pollfdList(athenaTransportLinkAdapter, athenaTransportLink);
                linkId = index;
                break;
            }
        }
    }

    assertFalse(linkId == -1, "Attempt to remove link not found in link adapter lists");

    // Callback to notify that the link has been removed and references need to be dropped.
    PARCBitVector *linkVector = parcBitVector_Create();
    parcBitVector_Set(linkVector, linkId);
    athenaTransportLinkAdapter->removeLink(athenaTransportLinkAdapter->removeLinkContext, linkVector);
    parcBitVector_Release(&linkVector);

    // we assume all references to the linkId associated with this instance have been
    // cleared from the PIT and FIB when removeLink returns.

    parcLog_Debug(athenaTransportLinkAdapter_GetLogger(athenaTransportLinkAdapter),
                  "link removed: %s", athenaTransportLink_GetName(athenaTransportLink));

    athenaTransportLink_Release(&athenaTransportLink);
}
Ejemplo n.º 7
0
void
parcPublicKey_Validate(PARCArrayList *args)
{
    char *fileName = parcArrayList_Get(args, 2);
    char *password = parcArrayList_Get(args, 3);

    PARCSigningInterface *interface = parcPublicKeySignerPkcs12Store_Open(fileName, password, PARC_HASH_SHA256);
    if (interface == NULL) {
        printf("Invalid %s\n", fileName);
        return;
    }
    printf("Valid %s\n", fileName);
}
Ejemplo n.º 8
0
int
main(int argc, char *argv[])
{
    char *programName = "parc_publickey";
    if (argc < 2) {
        printUsage(programName);
        exit(1);
    }

    PARCArrayList *args = parcArrayList_Create(NULL);
    parcArrayList_AddAll(args, (void **) argv, argc);

    parcSecurity_Init();

    char *arg = parcArrayList_Get(args, 1);
    if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) {
        printUsage(programName);
        return 0;
    } else if (strcmp(arg, "-c") == 0 || strcmp(arg, "--create") == 0) {
        parcPublicKey_Create(args);
    } else if (strcmp(arg, "-v") == 0 || strcmp(arg, "--validate") == 0) {
        parcPublicKey_Validate(args);
    } else {
        printUsage(programName);
        exit(1);
    }

    parcSecurity_Fini();
    return 0;
}
Ejemplo n.º 9
0
/**
 * @function metisListenerSet_Add
 * @abstract Adds the listener to the set
 * @discussion
 *     Unique set based on pair (MetisEncapType, localAddress)
 *
 * @param <#param1#>
 * @return <#return#>
 */
bool
metisListenerSet_Add(MetisListenerSet *set, MetisListenerOps *ops)
{
    assertNotNull(set, "Parameter set must be non-null");
    assertNotNull(ops, "Parameter ops must be non-null");

    int opsEncap = ops->getEncapType(ops);
    const CPIAddress *opsAddress = ops->getListenAddress(ops);

    // make sure its not in the set
    size_t length = parcArrayList_Size(set->listOfListeners);
    for (size_t i = 0; i < length; i++) {
        MetisListenerOps *entry = parcArrayList_Get(set->listOfListeners, i);

        int entryEncap = entry->getEncapType(entry);
        const CPIAddress *entryAddress = entry->getListenAddress(entry);

        if (opsEncap == entryEncap && cpiAddress_Equals(opsAddress, entryAddress)) {
            // duplicate
            return false;
        }
    }

    parcArrayList_Add(set->listOfListeners, ops);
    return true;
}
Ejemplo n.º 10
0
CPIConnection *
cpiConnectionList_Get(CPIConnectionList *list, size_t index)
{
    assertNotNull(list, "Parameter list must be non-null");
    CPIConnection *original = (CPIConnection *) parcArrayList_Get(list->listOfConnections, index);
    return cpiConnection_Copy(original);
}
Ejemplo n.º 11
0
static AthenaTransportLinkModule *
_LoadModule(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, const char *moduleName)
{
    PARCArrayList *newModuleList = NULL;

    // XXX need to dynamically load these, they're all hardwired for now
    if (strcasecmp(moduleName, "TCP") == 0) {
        newModuleList = athenaTransportLinkModuleTCP_Init();
    }
    if (strcasecmp(moduleName, "UDP") == 0) {
        newModuleList = athenaTransportLinkModuleUDP_Init();
    }
    if (strcasecmp(moduleName, "ETH") == 0) {
        newModuleList = athenaTransportLinkModuleETH_Init();
    }

    if (newModuleList) {
        for (int index = 0; index < parcArrayList_Size(newModuleList); index++) {
            AthenaTransportLinkModule *athenaTransportLinkModule = parcArrayList_Get(newModuleList, index);
            _AddModule(athenaTransportLinkAdapter, athenaTransportLinkModule);
        }
        parcArrayList_Destroy(&newModuleList);
    }
    return _LookupModule(athenaTransportLinkAdapter, moduleName);
}
Ejemplo n.º 12
0
static MetisNumberSet *
_metisStandardPIT_SatisfyInterest(MetisPIT *generic, const MetisMessage *objectMessage)
{
    assertNotNull(generic, "Parameter pit must be non-null");
    assertNotNull(objectMessage, "Parameter objectMessage must be non-null");

    MetisStandardPIT *pit = metisPIT_Closure(generic);

    // we need to look in all three tables to see if there's anything
    // to satisy in each of them and take the union of the reverse path sets.

    MetisNumberSet *ingressSetUnion = metisNumberSet_Create();

    PARCArrayList *list = metisMatchingRulesTable_GetUnion(pit->table, objectMessage);
    for (size_t i = 0; i < parcArrayList_Size(list); i++) {
        MetisPitEntry *pitEntry = (MetisPitEntry *) parcArrayList_Get(list, i);

        // this is a reference counted return
        const MetisNumberSet *ingressSet = metisPitEntry_GetIngressSet(pitEntry);
        metisNumberSet_AddSet(ingressSetUnion, ingressSet);

        // and remove it from the PIT.  Key is a reference counted copy of the pit entry message
        MetisMessage *key = metisPitEntry_GetMessage(pitEntry);
        metisMatchingRulesTable_RemoveFromBest(pit->table, key);
        metisMessage_Release(&key);
    }
    parcArrayList_Destroy(&list);

    return ingressSetUnion;
}
Ejemplo n.º 13
0
MetisConnection *
metisConnectionList_Get(MetisConnectionList *list, size_t index)
{
    assertNotNull(list, "Parameter list must be non-null");
    MetisConnection *original = (MetisConnection *) parcArrayList_Get(list->listOfConnections, index);
    return original;
}
Ejemplo n.º 14
0
bool
cpiInterfaceSet_Equals(const CPIInterfaceSet *a, const CPIInterfaceSet *b)
{
    if (a == NULL && b == NULL) {
        return true;
    }

    if (a == NULL || b == NULL) {
        return false;
    }

    size_t length_a = parcArrayList_Size(a->listOfInterfaces);
    size_t length_b = parcArrayList_Size(b->listOfInterfaces);

    if (length_a == length_b) {
        for (size_t i = 0; i < length_a; i++) {
            CPIInterface *iface_a = (CPIInterface *) parcArrayList_Get(a->listOfInterfaces, i);

            // the set is unique by interface id, so if it exists in set b, it
            // exists there by interface id
            CPIInterface *iface_b = cpiInterfaceSet_GetByInterfaceIndex(b, cpiInterface_GetInterfaceIndex(iface_a));
            if (!cpiInterface_Equals(iface_b, iface_b)) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Ejemplo n.º 15
0
PARCBitVector *
athenaTransportLinkAdapter_Send(AthenaTransportLinkAdapter *athenaTransportLinkAdapter,
                                CCNxMetaMessage *ccnxMetaMessage,
                                PARCBitVector *linkOutputVector)
{
    PARCBitVector *resultVector = parcBitVector_Create();
    int nextLinkToWrite = 0;

    if (athenaTransportLinkAdapter->instanceList == NULL) {
        return resultVector;
    }

    while ((nextLinkToWrite = parcBitVector_NextBitSet(linkOutputVector, nextLinkToWrite)) >= 0) {
        athenaTransportLinkAdapter->stats.messageSend_Attempted++;
        if (nextLinkToWrite >= parcArrayList_Size(athenaTransportLinkAdapter->instanceList)) {
            athenaTransportLinkAdapter->stats.messageSend_LinkDoesNotExist++;
            nextLinkToWrite++;
            continue;
        }
        AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->instanceList, nextLinkToWrite);
        if (athenaTransportLink == NULL) {
            athenaTransportLinkAdapter->stats.messageSend_LinkDoesNotExist++;
            nextLinkToWrite++;
            continue;
        }
        if (!(athenaTransportLink_GetEvent(athenaTransportLink) & AthenaTransportLinkEvent_Send)) {
            athenaTransportLinkAdapter->stats.messageSend_LinkNotAcceptingSendRequests++;
            nextLinkToWrite++;
            continue;
        }
        // If we're sending an interest to a non-local link,
        // check that it has a sufficient hoplimit.
        if (ccnxMetaMessage_IsInterest(ccnxMetaMessage)) {
            if (athenaTransportLink_IsNotLocal(athenaTransportLink)) {
                if (ccnxInterest_GetHopLimit(ccnxMetaMessage) == 0) {
                    athenaTransportLinkAdapter->stats.messageSend_HopLimitExceeded++;
                    nextLinkToWrite++;
                    continue;
                }
            }
        }
        int result = athenaTransportLink_Send(athenaTransportLink, ccnxMetaMessage);
        if (result == 0) {
            athenaTransportLinkAdapter->stats.messageSent++;
            parcBitVector_Set(resultVector, nextLinkToWrite);
        } else {
            athenaTransportLinkAdapter->stats.messageSend_LinkSendFailed++;
        }
        nextLinkToWrite++;
    }

    return resultVector;
}
Ejemplo n.º 16
0
int
athenaTransportLinkModule_Poll(AthenaTransportLinkModule *athenaTransportLinkModule, int timeout)
{
    athenaTransportLinkModule->stats.module_Poll++;
    int events = 0;
    for (int index = 0; index < parcArrayList_Size(athenaTransportLinkModule->instanceList); index++) {
        AthenaTransportLink *transportLink = parcArrayList_Get(athenaTransportLinkModule->instanceList, index);
        assertNotNull(transportLink, "Unexpected Null entry in module instance list");
        events += athenaTransportLinkModule->pollMethod(transportLink, timeout);
    }
    return events;
}
Ejemplo n.º 17
0
/**
 * Uses the system name (e.g. "en0")
 *
 *   <#Discussion#>
 *
 * @param <#param1#>
 * @return NULL if not found
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
CPIInterface *
cpiInterfaceSet_GetByName(CPIInterfaceSet *set, const char *name)
{
    size_t length = parcArrayList_Size(set->listOfInterfaces);
    for (size_t i = 0; i < length; i++) {
        CPIInterface *listEntry = (CPIInterface *) parcArrayList_Get(set->listOfInterfaces, i);
        if (cpiInterface_NameEquals(listEntry, name)) {
            return listEntry;
        }
    }
    return NULL;
}
Ejemplo n.º 18
0
CPIInterface *
cpiInterfaceSet_GetByInterfaceIndex(const CPIInterfaceSet *set, unsigned interfaceIndex)
{
    size_t length = parcArrayList_Size(set->listOfInterfaces);
    for (size_t i = 0; i < length; i++) {
        CPIInterface *listEntry = (CPIInterface *) parcArrayList_Get(set->listOfInterfaces, i);
        unsigned entryInterfaceIndex = cpiInterface_GetInterfaceIndex(listEntry);
        if (entryInterfaceIndex == interfaceIndex) {
            return listEntry;
        }
    }
    return NULL;
}
Ejemplo n.º 19
0
bool
parcURIPath_Equals(const PARCURIPath *pathA, const PARCURIPath *pathB)
{
    if (pathA == pathB) {
        return true;
    }
    if (pathA == NULL || pathB == NULL) {
        return false;
    }

    if (parcArrayList_Size(pathA->segments) == parcArrayList_Size(pathB->segments)) {
        for (size_t i = 0; i < parcArrayList_Size(pathA->segments); i++) {
            PARCURISegment *segmentA = parcArrayList_Get(pathA->segments, i);
            PARCURISegment *segmentB = parcArrayList_Get(pathB->segments, i);
            if (!parcURISegment_Equals(segmentA, segmentB)) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Ejemplo n.º 20
0
LONGBOW_TEST_CASE(Global, PARCList_Get)
{
    PARCArrayList *array = parcArrayList_Create(parcArrayList_StdlibFreeFunction);

    char *expected = strdup("Hello World");
    parcArrayList_Add(array, expected);

    char *actual = parcArrayList_Get(array, 0);

    assertTrue(expected == actual, "Expected=%p, actual=%p", (void *) expected, (void *) actual);

    parcArrayList_Destroy(&array);
}
Ejemplo n.º 21
0
static void
_metisCommandLineInterface_RemoveSession(MetisCommandLineInterface *cli, _MetisCommandLineInterface_Session *session)
{
    size_t length = parcArrayList_Size(cli->openSessions);
    for (size_t i = 0; i < length; i++) {
        _MetisCommandLineInterface_Session *x = parcArrayList_Get(cli->openSessions, i);
        if (x == session) {
            // removing from list will call the session destroyer
            parcArrayList_RemoveAndDestroyAtIndex(cli->openSessions, i);
            return;
        }
    }
    assertTrue(0, "Illegal state: did not find a session in openSessions %p", (void *) session);
}
Ejemplo n.º 22
0
bool
athenaTransportLinkAdapter_IsNotLocal(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, int linkId)
{
    if (athenaTransportLinkAdapter->instanceList == NULL) {
        return false;
    }
    if ((linkId >= 0) && (linkId < parcArrayList_Size(athenaTransportLinkAdapter->instanceList))) {
        AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->instanceList, linkId);
        if (athenaTransportLink) {
            return athenaTransportLink_IsNotLocal(athenaTransportLink);
        }
    }
    return false;
}
Ejemplo n.º 23
0
const char *
athenaTransportLinkAdapter_LinkIdToName(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, int linkId)
{
    if (athenaTransportLinkAdapter->instanceList == NULL) {
        return NULL;
    }
    if (linkId < parcArrayList_Size(athenaTransportLinkAdapter->instanceList)) {
        AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->instanceList, linkId);
        if (athenaTransportLink) {
            return athenaTransportLink_GetName(athenaTransportLink);
        }
    }
    return NULL;
}
Ejemplo n.º 24
0
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);
}
Ejemplo n.º 25
0
bool
cpiConnectionList_Equals(const CPIConnectionList *a, const CPIConnectionList *b)
{
    if (a == NULL && b == NULL) {
        return true;
    }
    if (a == NULL || b == NULL) {
        return false;
    }

    if (parcArrayList_Size(a->listOfConnections) == parcArrayList_Size(b->listOfConnections)) {
        size_t length = parcArrayList_Size(a->listOfConnections);
        for (size_t i = 0; i < length; i++) {
            CPIConnection *tunnel_a = (CPIConnection *) parcArrayList_Get(a->listOfConnections, i);
            CPIConnection *tunnel_b = (CPIConnection *) parcArrayList_Get(b->listOfConnections, i);
            if (!cpiConnection_Equals(tunnel_a, tunnel_b)) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Ejemplo n.º 26
0
void
parcPublicKey_Create(PARCArrayList *args)
{
    unsigned int keyLength = 1024;
    unsigned int validityDays = 30;

    char *fileName = parcArrayList_Get(args, 2);
    char *password = parcArrayList_Get(args, 3);
    char *subjectName = parcArrayList_Get(args, 4);

    if (parcArrayList_Size(args) > 5) {
        keyLength = (unsigned int) strtoul(parcArrayList_Get(args, 5), NULL, 10);
    }

    if (parcArrayList_Size(args) > 6) {
        validityDays = (unsigned int) strtoul(parcArrayList_Get(args, 6), NULL, 10);
    }
    bool result = parcPublicKeySignerPkcs12Store_CreateFile(fileName, password, subjectName, keyLength, validityDays);
    if (!result) {
        printf("Error: %s %s", fileName, strerror(errno));
        return;
    }
    printf("Created %s, key length %d valid for %d days.\n", fileName, keyLength, validityDays);
}
Ejemplo n.º 27
0
PARCBitVector *
athenaTransportLinkAdapter_Close(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, PARCBitVector *linkVector)
{
    PARCBitVector *resultVector = parcBitVector_Create();
    int nextLinkToClose = 0;
    while ((nextLinkToClose = parcBitVector_NextBitSet(linkVector, nextLinkToClose)) >= 0) {
        AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->instanceList, nextLinkToClose);
        if (athenaTransportLink) {
            athenaTransportLink_Close(athenaTransportLink);
            parcBitVector_Set(resultVector, nextLinkToClose);
            nextLinkToClose++;
        }
    }
    return resultVector;
}
Ejemplo n.º 28
0
/**
 * @abstract called from the link specific adapter to coordinate termination of a link instance
 * @discussion
 *
 * This is called exclusively from the Transport Link specific Module to instigate the
 * removal of an active link.  The link is flagged as closing and the link module is called
 * to continue the operation.  Eventually this should result in the link specific close
 * method being called, which should finish cleaning state, and deallocate the instance.
 *
 * @param [in] athenaTransportLink link adapter instance
 * @param [in] athenaTransportLink link instance to remove
 *
 * Example:
 * @code
 * {
 *
 * }
 * @endcode
 */
static void
_athenaTransportLinkModule_RemoveLink(AthenaTransportLinkModule *athenaTransportLinkModule, AthenaTransportLink *athenaTransportLink)
{
    // remove from our list
    for (int index = 0; index < parcArrayList_Size(athenaTransportLinkModule->instanceList); index++) {
        AthenaTransportLink *transportLink = parcArrayList_Get(athenaTransportLinkModule->instanceList, index);
        if (athenaTransportLink == transportLink) {
            AthenaTransportLink *removedInstance = parcArrayList_RemoveAtIndex(athenaTransportLinkModule->instanceList, index);
            assertTrue(removedInstance == athenaTransportLink, "Wrong link removed");
            break;
        }
    }
    athenaTransportLinkModule->removeLink(athenaTransportLinkModule->removeLinkContext, athenaTransportLink);
    athenaTransportLink_Release(&athenaTransportLink);
}
Ejemplo n.º 29
0
static AthenaTransportLinkModule *
_LookupModule(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, const char *moduleName)
{
    AthenaTransportLinkModule *athenaTransportLinkModule;
    if (athenaTransportLinkAdapter->moduleList) {
        for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->moduleList); index++) {
            athenaTransportLinkModule = parcArrayList_Get(athenaTransportLinkAdapter->moduleList, index);
            if (strcasecmp(athenaTransportLinkModule_GetName(athenaTransportLinkModule), moduleName) == 0) {
                return athenaTransportLinkModule;
            }
        }
    }
    errno = ENOENT;
    return NULL;
}
Ejemplo n.º 30
0
int
athenaTransportLinkAdapter_LinkNameToId(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, const char *linkName)
{
    if (athenaTransportLinkAdapter->instanceList == NULL) {
        return -1;
    }
    for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->instanceList); index++) {
        AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->instanceList, index);
        if (athenaTransportLink) {
            if (strcmp(athenaTransportLink_GetName(athenaTransportLink), linkName) == 0) {
                return index;
            }
        }
    }
    return -1;
}