コード例 #1
0
ファイル: util-storage.c プロジェクト: codercold/suricata
void *StorageAllocById(Storage **storage, StorageEnum type, int id)
{
#ifdef DEBUG
    BUG_ON(!storage_registraton_closed);
#endif
    SCLogDebug("storage %p id %d", storage, id);

    StorageMapping *map = &storage_map[type][id];
    Storage *store = *storage;
    if (store == NULL) {
        store = SCMalloc(sizeof(void *) * storage_max_id[type]);
        if (store == NULL)
            return NULL;
        memset(store, 0x00, sizeof(void *) * storage_max_id[type]);
    }
    SCLogDebug("store %p", store);

    if (store[id] == NULL && map->Alloc != NULL) {
        store[id] = map->Alloc(map->size);
        if (store[id] == NULL) {
            SCFree(store);
            *storage = NULL;
            return NULL;
        }
    }

    *storage = store;
    return store[id];
}
コード例 #2
0
ファイル: util-storage.c プロジェクト: H5eye/suricata
void StorageFree(Storage **storage, StorageEnum type)
{
    if (*storage == NULL)
        return;

#ifdef DEBUG
    BUG_ON(!storage_registraton_closed);
#endif
#ifdef UNITTESTS
    if (storage_map == NULL)
        return;
#endif

    Storage *store = *storage;
    int i;
    for (i = 0; i < storage_max_id[type]; i++) {
        if (store[i] != NULL) {
            StorageMapping *map = &storage_map[type][i];
            map->Free(store[i]);
            store[i] = NULL;
        }
    }
    SCFree(*storage);
    *storage = NULL;
}
コード例 #3
0
ファイル: util-storage.c プロジェクト: codercold/suricata
void StorageFreeById(Storage *storage, StorageEnum type, int id)
{
#ifdef DEBUG
    BUG_ON(!storage_registraton_closed);
#endif
    SCLogDebug("storage %p id %d", storage, id);

    StorageMapping *map = &storage_map[type][id];
    Storage *store = storage;
    if (store != NULL) {
        SCLogDebug("store %p", store);
        if (store[id] != NULL) {
            map->Free(store[id]);
            store[id] = NULL;
        }
    }
}
コード例 #4
0
ファイル: util-storage.c プロジェクト: codercold/suricata
void *StorageAllocByIdPrealloc(Storage *storage, StorageEnum type, int id)
{
#ifdef DEBUG
    BUG_ON(!storage_registraton_closed);
#endif
    SCLogDebug("storage %p id %d", storage, id);

    StorageMapping *map = &storage_map[type][id];
    if (storage[id] == NULL && map->Alloc != NULL) {
        storage[id] = map->Alloc(map->size);
        if (storage[id] == NULL) {
            return NULL;
        }
    }

    return storage[id];
}
コード例 #5
0
std::vector<StorageMapping::const_iterator>
select_compatible_storage(
  StorageMapping const& sm,
  std::vector<std::string>const& dap
)
{
  std::vector<StorageMapping::const_iterator> result;
  StorageMapping::const_iterator storage_it(sm.begin());
  StorageMapping::const_iterator const storage_end(sm.end());

  for( ; storage_it != storage_end; ++storage_it ) {

    StorageInfo::Protocols const& supported_protocols(
      storage_it->second.protocols
    );
    std::vector<std::string>::const_iterator it = find_if(
      dap.begin(),
      dap.end(),
      matches_any_protocol_in(supported_protocols)
    );
    if (it != dap.end()) {
      StorageInfo::CE_Mounts const& close_ce_binds(
        storage_it->second.ce_mounts
      );
      if (*it == "file"
          && find_if(
            close_ce_binds.begin(),
            close_ce_binds.end(),
            is_mount_defined
          ) == close_ce_binds.end()) {
        continue;
      }
      result.push_back(storage_it);
    }
  }
  return result;
}