Back to index

im-sdk  12.3.91
Public Member Functions | Private Member Functions | Private Attributes
IMNSMapConf Class Reference

#include <IMNSMapConf.hh>

Collaboration diagram for IMNSMapConf:
Collaboration graph
[legend]

List of all members.

Public Member Functions

bool load ()
IMNsMapStructget_nsmap_info (int *num_nsmap_entries)
 IMNSMapConf (const char *nsm_fname)
 ~IMNSMapConf ()

Private Member Functions

bool read_ns_map_config (char *buf, int fsize)
int get_line (char *buf, int fsize, char **curptr, char *line)
void print_core (IMNsMapStruct *nsm)

Private Attributes

string fname
int count
IMNsMapStructnsmp

Detailed Description

Definition at line 9 of file IMNSMapConf.hh.


Constructor & Destructor Documentation

IMNSMapConf::IMNSMapConf ( const char *  nsm_fname)

Definition at line 194 of file IMNSMapConf.cpp.

{
    fname = nsm_fname;
    nsmp = NULL;
    count = 0;
}

Definition at line 203 of file IMNSMapConf.cpp.

{
    int i;

    for (i=0; i<count; i++) {
        if (nsmp[i].if_name) free (nsmp[i].if_name);
        if (nsmp[i].src_entry) free (nsmp[i].src_entry);
        if (nsmp[i].dest_entry) free (nsmp[i].dest_entry);
        if (nsmp[i].location) free (nsmp[i].location);
    }
    free ((IMNsMapStruct *) nsmp);
}

Member Function Documentation

int IMNSMapConf::get_line ( char *  buf,
int  fsize,
char **  curptr,
char *  line 
) [private]

Definition at line 10 of file IMNSMapConf.cpp.

{
    int line_ptr, n;
    char line_buf[MAX_LINE_LEN];
    char *ptr;

    char *p = ((0 == *curptr)?*curptr=buf:*curptr);
    char *pp = p;

    line_ptr = 0;
    line[0] = '\0';

    n = *curptr - buf;
    if (n >= size) { /* No more data to read */
        return 0;
    }
    /* get line with no space */
    while(1) {
        if (*p == '\n' || *p == '\0') {
            *p++;
            continue;
        }

        /* chop one line */
        while (*p != '\n') p++ ;
        /* pp to p is one line, just as fgets returns */
        memcpy(line_buf, pp, p-pp);
        line_buf[p-pp]='\0';

        ptr = line_buf;

        /* skip preceding space keys */
        while(*ptr && isspace(*ptr)) ptr++;

        /* if is space line, get new line */
        if (*ptr == '\n' || *ptr == '\0')
            continue;

        while(*ptr != '\n' && *ptr != '\0' && line_ptr < MAX_LINE_LEN)
            line[line_ptr++] = *ptr++;

        /* trim right space */
        while (isspace(line[line_ptr-1])) line_ptr--;
        line[line_ptr] = '\0';

        /* if the line end with '\', then continue read the next line */
        if (line[line_ptr-1] == '\\') {
            line_ptr--;
            line[line_ptr] = '\0';
            continue;
        }
        break;
    }

    *curptr = p+1 ;

    if (line[0] == '\0') return 0;
    if (line[0] == COMMENT) return -1;
    return line_ptr;
}

Here is the caller graph for this function:

IMNsMapStruct* IMNSMapConf::get_nsmap_info ( int *  num_nsmap_entries) [inline]

Definition at line 20 of file IMNSMapConf.hh.

                                                          {
       *num_nsmap_entries = count;
       return nsmp;
    }

Here is the caller graph for this function:

Definition at line 167 of file IMNSMapConf.cpp.

{
    FILE *fp;
    int fd, size, nfread;
    struct stat stat_buf;
    char *file_buf;

    fp = fopen(fname.c_str(), "r");
    if (!fp)
       return false;

    fd = fileno((FILE *)fp);
    if (fstat(fd, &stat_buf) < 0) {
       return false;
    }
    size = stat_buf.st_size;
    file_buf = (char *)calloc(size, sizeof(char));
    nfread = fread(file_buf, size, 1, fp);

    if (!read_ns_map_config(file_buf, size))
       return false;

    fclose(fp);

    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void IMNSMapConf::print_core ( IMNsMapStruct nsm) [private]

Definition at line 77 of file IMNSMapConf.cpp.

{
    int i;

    for (i=0; i<count; i++) {
        LOG_DEBUG("if_name [%s] \n", nsm[i].if_name);
        LOG_DEBUG("default repository [%s] \n", nsm[i].src_entry);
        LOG_DEBUG("real repository [%s] \n", nsm[i].dest_entry);
        LOG_DEBUG("location [%s] \n", nsm[i].location);
        LOG_DEBUG(" =====================================\n");
    }
}
bool IMNSMapConf::read_ns_map_config ( char *  buf,
int  fsize 
) [private]

Definition at line 93 of file IMNSMapConf.cpp.

{
    char   line[MAX_LINE_LEN];
    char   *kptr, *ptr;
    int    len;
    char   *curr_ptr;

    curr_ptr = 0;
    do {
        len = get_line(buf, fsize, &curr_ptr, line);

        if (!len) break;
        if (len < 0) continue;

        if (!count){
           nsmp = (IMNsMapStruct *)calloc(1, sizeof(IMNsMapStruct));
        } else {
           nsmp = (IMNsMapStruct *) realloc((IMNsMapStruct *)nsmp,
                                             (count+1)*sizeof(IMNsMapStruct));
        }

        if (!nsmp)
           return false;

        kptr = 0;

        ptr = line;
        kptr = line;

        /* Get the if_name */
        while (*ptr && !isspace(*ptr)) ptr++;
        if (*ptr) {
            *ptr = '\0';
            ptr++;
        }
        nsmp[count].if_name = (char *)strdup(kptr);

        kptr = 0;
        /* Get the default repository */
        while (*ptr && isspace(*ptr)) ptr++;
        kptr = ptr;
        while (*ptr && !isspace(*ptr)) ptr++;
        if (*ptr) {
            *ptr = '\0';
            ptr++;
        }
        nsmp[count].src_entry = (char *)strdup(kptr);

        kptr = 0;
        /* Get the real repository */
        while (*ptr && isspace(*ptr)) ptr++;
        kptr = ptr;
        while (*ptr && !isspace(*ptr)) ptr++;
        if (*ptr) {
            *ptr = '\0';
            ptr++;
        }
        nsmp[count].dest_entry = (char *)strdup(kptr);

        while (*ptr && isspace(*ptr)) ptr++;
        nsmp[count].location = (char *)strdup(ptr);

        count++;
    } while(1);

    // print_core(nsmp);

    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

int IMNSMapConf::count [private]

Definition at line 12 of file IMNSMapConf.hh.

string IMNSMapConf::fname [private]

Definition at line 11 of file IMNSMapConf.hh.

Definition at line 13 of file IMNSMapConf.hh.


The documentation for this class was generated from the following files: