예제 #1
0
static void ApplyPlatformExtraTable(char **names, char **columns)
{
    int pidcol = -1;

    for (int i = 0; names[i] && columns[i]; i++)
    {
        if (strcmp(names[i], "PID") == 0)
        {
            pidcol = i;
            break;
        }
    }

    if (!StringMapHasKey(UCB_PS_MAP, columns[pidcol]))
    {
        return;
    }

    for (int i = 0; names[i] && columns[i]; i++)
    {
        if (strcmp(names[i], "COMMAND") == 0 || strcmp(names[i], "CMD") == 0)
        {
            free(columns[i]);
            columns[i] = xstrdup(StringMapGet(UCB_PS_MAP, columns[pidcol]));
            break;
        }
    }
}
예제 #2
0
static int AddOffsetToMapUnlessExists(StringMap ** tree, uint64_t offset,
                                      int64_t bucket_index)
{
    char *tmp;
    xasprintf(&tmp, "%" PRIu64, offset);
    char *val;
    if (StringMapHasKey(*tree, tmp) == false)
    {
        xasprintf(&val, "%" PRIu64, bucket_index);
        StringMapInsert(*tree, tmp, val);
    }
    else
    {
        Log(LOG_LEVEL_ERR,
            "Duplicate offset for value %" PRIu64 " at index %" PRId64 ", other value %" PRIu64 ", other index '%s'",
             offset, bucket_index,
             offset, (char *) StringMapGet(*tree, tmp));
        free(tmp);
    }
    return 0;
}
예제 #3
0
파일: lastseen.c 프로젝트: AsherBond/core
bool ScanLastSeenQuality(LastSeenQualityCallback callback, void *ctx)
{
    StringMap *lastseen_db = LoadDatabaseToStringMap(dbid_lastseen);
    if (!lastseen_db)
    {
        return false;
    }
    MapIterator it = MapIteratorInit(lastseen_db->impl);
    MapKeyValue *item;

    Seq *hostkeys = SeqNew(100, free);
    while ((item = MapIteratorNext(&it)) != NULL)
    {
        char *key = item->key;
        /* Only look for "keyhost" entries */
        if (key[0] != 'k')
        {
            continue;
        }

        SeqAppend(hostkeys, xstrdup(key + 1));
    }
    for (int i = 0; i < SeqLength(hostkeys); ++i)
    {
        const char *hostkey = SeqAt(hostkeys, i);

        char keyhost_key[CF_BUFSIZE];
        snprintf(keyhost_key, CF_BUFSIZE, "k%s", hostkey);
        char *address = NULL;
        address = (char*)StringMapGet(lastseen_db, keyhost_key);
        if (!address)
        {
            Log(LOG_LEVEL_ERR, "Failed to read address for key '%s'.", hostkey);
            continue;
        }

        char incoming_key[CF_BUFSIZE];
        snprintf(incoming_key, CF_BUFSIZE, "qi%s", hostkey);
        KeyHostSeen *incoming = NULL;
        incoming = (KeyHostSeen*)StringMapGet(lastseen_db, incoming_key);
        if (incoming)
        {
            if (!(*callback)(hostkey, address, true, incoming, ctx))
            {
                break;
            }
        }

        char outgoing_key[CF_BUFSIZE];
        snprintf(outgoing_key, CF_BUFSIZE, "qo%s", hostkey);
        KeyHostSeen *outgoing = NULL;
        outgoing = (KeyHostSeen*)StringMapGet(lastseen_db, outgoing_key);
        if (outgoing)
        {
            if (!(*callback)(hostkey, address, false, outgoing, ctx))
            {
                break;
            }
        }
    }

    StringMapDestroy(lastseen_db);
    SeqDestroy(hostkeys);

    return true;
}