4u2change/msdb.c
uint8_t *msdb_communityList() {
    DIR            *dir_p           = NULL;
    struct  dirent *dirEntry_p      = NULL;
    char            tmpPath[ES_MAX_DIR_FILE_NAME_LEN];
    struct stat     file_info;
    uint8_t        *communityList   = NULL;

    /* Initialise storage structure. */
    memset(tmpPath,  0, sizeof(tmpPath));

    snprintf(tmpPath, sizeof(tmpPath), STORAGE_COMMUNITIES_DIRECTORY);
    dir_p = opendir(tmpPath);
    if (NULL != dir_p) {

        while (NULL != (dirEntry_p = readdir(dir_p))) {
            if ((strcmp(dirEntry_p->d_name,  ".") != 0) &&
                (strcmp(dirEntry_p->d_name, "..") != 0)) {
                memset(tmpPath,  0, sizeof(tmpPath));
                snprintf(tmpPath, sizeof(tmpPath), "%s/%s", 
                         STORAGE_COMMUNITIES_DIRECTORY, dirEntry_p->d_name);

                if ((!stat(tmpPath, &file_info)) && 
                    (S_ISREG(file_info.st_mode))) {

                    if (NULL == communityList) {
                        communityList = calloc(1, strlen(dirEntry_p->d_name)+1);
                        strcpy((char *)communityList, dirEntry_p->d_name);
                    }
                    else {
                        /* comma and NULL terminator. */
                        communityList = realloc(communityList,
                            strlen((char *)communityList)+strlen(dirEntry_p->d_name)+ 2); 
                        strcat((char *)communityList, ",");
                        strcat((char *)communityList, dirEntry_p->d_name);
                    }
                }
            }
        }
        closedir(dir_p);
    }

    return communityList;
}
/***************************************************************************/
/**
 * Get a comma separated list of stored communities.
 *
 * @return A pointer to the list of communities, NULL if none.
 ******************************************************************************/
Get a comma separated list of stored communities.
@return A pointer to the list of communities, NULL if none.
Get a comma separated list of stored communities . @return A pointer to the list of communities NULL if none .
uint8_t *msdb_communityList() {
    DIR            *dir_p           = NULL;
    struct  dirent *dirEntry_p      = NULL;
    char            tmpPath[ES_MAX_DIR_FILE_NAME_LEN];
    struct stat     file_info;
    uint8_t        *communityList   = NULL;
    memset(tmpPath,  0, sizeof(tmpPath));
    snprintf(tmpPath, sizeof(tmpPath), STORAGE_COMMUNITIES_DIRECTORY);
    dir_p = opendir(tmpPath);
    if (NULL != dir_p) {
        while (NULL != (dirEntry_p = readdir(dir_p))) {
            if ((strcmp(dirEntry_p->d_name,  ".") != 0) &&
                (strcmp(dirEntry_p->d_name, "..") != 0)) {
                memset(tmpPath,  0, sizeof(tmpPath));
                snprintf(tmpPath, sizeof(tmpPath), "%s/%s", 
                         STORAGE_COMMUNITIES_DIRECTORY, dirEntry_p->d_name);
                if ((!stat(tmpPath, &file_info)) && 
                    (S_ISREG(file_info.st_mode))) {
                    if (NULL == communityList) {
                        communityList = calloc(1, strlen(dirEntry_p->d_name)+1);
                        strcpy((char *)communityList, dirEntry_p->d_name);
                    }
                    else {
                        communityList = realloc(communityList,
                            strlen((char *)communityList)+strlen(dirEntry_p->d_name)+ 2); 
                        strcat((char *)communityList, ",");
                        strcat((char *)communityList, dirEntry_p->d_name);
                    }
                }
            }
        }
        closedir(dir_p);
    }
    return communityList;
}
uint8_t * msdb_communityList ( ) { DIR * dir_p = NULL ; struct dirent * dirEntry_p = NULL ; char tmpPath [ ES_MAX_DIR_FILE_NAME_LEN ] ; struct stat file_info ; uint8_t * communityList = NULL ; memset ( tmpPath , 0 , sizeof ( tmpPath ) ) ; snprintf ( tmpPath , sizeof ( tmpPath ) , STORAGE_COMMUNITIES_DIRECTORY ) ; dir_p = opendir ( tmpPath ) ; if ( NULL != dir_p ) { while ( NULL != ( dirEntry_p = readdir ( dir_p ) ) ) { if ( ( strcmp ( dirEntry_p -> d_name , " " ) != 0 ) && ( strcmp ( dirEntry_p -> d_name , " " ) != 0 ) ) { memset ( tmpPath , 0 , sizeof ( tmpPath ) ) ; snprintf ( tmpPath , sizeof ( tmpPath ) , " " , STORAGE_COMMUNITIES_DIRECTORY , dirEntry_p -> d_name ) ; if ( ( ! stat ( tmpPath , & file_info ) ) && ( S_ISREG ( file_info . st_mode ) ) ) { if ( NULL == communityList ) { communityList = calloc ( 1 , strlen ( dirEntry_p -> d_name ) + 1 ) ; strcpy ( ( char * ) communityList , dirEntry_p -> d_name ) ; } else { communityList = realloc ( communityList , strlen ( ( char * ) communityList ) + strlen ( dirEntry_p -> d_name ) + 2 ) ; strcat ( ( char * ) communityList , " " ) ; strcat ( ( char * ) communityList , dirEntry_p -> d_name ) ; } } } } closedir ( dir_p ) ; } return communityList ; }
Get a comma separated list of stored communities.
Get a comma separated list of stored communities .
/* Initialise storage structure. */ /* comma and NULL terminator. */