Esempio n. 1
0
void plainconf::loadDirectory(const char *pPath, const char *pPattern)
{
    DIR *pDir = opendir(pPath);

    if (!pDir)
    {
        logToMem(LOG_LEVEL_ERR, "Failed to open directory [%s].", pPath);
        return ;
    }

    struct dirent *dir_ent;

    char str[4096] = {0};
    strcpy(str, pPath);
    strcatchr(str, '/', 4096);
    int offset = strlen(str);
    StringList AllEntries;

    while ((dir_ent = readdir(pDir)))
    {
        const char *pName = dir_ent->d_name;

        if ((strcmp(pName, ".") == 0) ||
            (strcmp(pName, "..") == 0) ||
            (*(pName + strlen(pName) - 1) == '~'))
            continue;

        if (pPattern)
        {
            //Beside the unmatch, also must exclude *,v which was created by rcs
            if(fnmatch(pPattern, pName, FNM_PATHNAME) != 0
                || fnmatch("*,v", pName, FNM_PATHNAME) == 0)
                continue;
        }

        strcpy(str + offset, pName);
        struct stat st;
        if (stat(str, &st) == 0)
        {
            if (S_ISDIR(st.st_mode)
                || pPattern
                || fnmatch("*.conf", pName, FNM_PATHNAME) == 0)
                AllEntries.add(str);
        }
    }
    closedir(pDir);
    AllEntries.sort();

    StringList::iterator iter;
    for (iter = AllEntries.begin(); iter != AllEntries.end(); ++iter)
    {
        const char *pName = (*iter)->c_str();
        logToMem(LOG_LEVEL_INFO, "Processing config file: %s", pName);
        loadConfFile(pName);
    }
}
Esempio n. 2
0
void plainconf::loadDirectory(const char *pPath, const char *pPattern)
{
    DIR *pDir = opendir(pPath);

    if (!pDir)
    {
        logToMem(LOG_LEVEL_ERR, "Failed to open directory [%s].", pPath);
        return ;
    }

    struct dirent *dir_ent;

    StringList AllEntries;

    while ((dir_ent = readdir(pDir)))
    {
        const char *pName = dir_ent->d_name;

        if ((strcmp(pName, ".") == 0) ||
            (strcmp(pName, "..") == 0) ||
            (*(pName + strlen(pName) - 1) == '~'))
            continue;

        if (pPattern)
        {
            if (fnmatch(pPattern, pName, FNM_PATHNAME))
                continue;
        }

        char str[4096] = {0};
        strcpy(str, pPath);
        strcatchr(str, '/', 4096);
        strcat(str, pName);
        AllEntries.add(str);
    }

    closedir(pDir);

    //Sort the filename order
    AllEntries.sort();
    StringList::iterator iter;

    for (iter = AllEntries.begin(); iter != AllEntries.end(); ++iter)
    {
        const char *p = (*iter)->c_str();
        logToMem(LOG_LEVEL_INFO, "Processing config file: %s", p);
        loadConfFile(p);
    }
}
Esempio n. 3
0
int FARMail::MakeDescription( char *buf, char *format, char *from, char *subj, char *date, int buflen )
{
 char * ptr = buf;
 char slashes[MAX_PATH];

 memset(slashes,32,MAX_PATH);

 while ( *format ) {

    if ( *format == '%' ) {

       if ( !FSF.LStrnicmp( format, X_FROM, lstrlen( X_FROM )-1 ) ) {

          char *ptr = from;
          int  fl   = -1;
          format += lstrlen( X_FROM )-1;

          if ( *format == '%' ) format++;
          else if ( *format == ':' ) {
             fl = FSF.atoi( format+1);
             while ( *format && *format != '%' ) format++;
             if ( *format ) format++;
          }

          while ( *ptr && fl ) {

             *buf = *ptr;
             ptr++;
             buf++;
             buflen--;
             fl--;

             if ( buflen <= 0  ) break;

          }
          if ( buflen <= 0  ) break;

       } else if ( !FSF.LStrnicmp( format, X_SUBJ, lstrlen( X_SUBJ )-1 ) ) {

          char *ptr = subj;
          int  fl   = -1;
          format += lstrlen( X_SUBJ )-1;

          if ( *format == '%' ) format++;
          else if ( *format == ':' ) {
             fl = FSF.atoi( format+1);
             while ( *format && *format != '%' ) format++;
             if ( *format ) format++;
          }

          while ( *ptr && fl ) {

             *buf = *ptr;
             ptr++;
             buf++;
             buflen--;
             fl--;

             if ( buflen <= 0  ) break;

          }
          if ( buflen <= 0  ) break;

       } else if ( !FSF.LStrnicmp( format, X_DATE, lstrlen( X_DATE )-1 ) ) {

          char *ptr = date;
          int  fl   = -1;
          format += lstrlen( X_DATE )-1;

          if ( *format == '%' ) format++;
          else if ( *format == ':' ) {
             fl = FSF.atoi( format+1);
             while ( *format && *format != '%' ) format++;
             if ( *format ) format++;
          }

          while ( *ptr && fl ) {

             *buf = *ptr;
             ptr++;
             buf++;
             buflen--;
             fl--;

             if ( buflen <= 0  ) break;

          }
          if ( buflen <= 0  ) break;

       } else if ( !FSF.LStrnicmp( format, X_CURDATE, lstrlen( X_CURDATE )-1 ) ) {

          char curdate[51];
          *curdate = 0;
          char *ptr=curdate;
          SYSTEMTIME st;
          GetLocalTime(&st);
          char year[5], syear[3], month[3], day[3];
          FSF.sprintf(year,"%04d",st.wYear);
          FSF.sprintf(syear,"%02d",st.wYear%1000);
          FSF.sprintf(month,"%02d",st.wMonth);
          FSF.sprintf(day,"%02d",st.wDay);
          format += lstrlen( X_CURDATE )-1;

          if ( *format == '%' )
          {
             lstrcpy(curdate,year);
             lstrcat(curdate,month);
             lstrcat(curdate,day);
             format++;
          }
          else if ( *format == ':' ) {
             format++;
             while ( *format && *format != '%' )
             {
               switch (*format)
               {
                 case 'd':
                 case 'D':
                   lstrcat(curdate,day);
                   break;
                 case 'm':
                 case 'M':
                   lstrcat(curdate,month);
                   break;
                 case 'y':
                 case 'Y':
                   lstrcat(curdate,year);
                   break;
                 case 's':
                 case 'S':
                   lstrcat(curdate,syear);
                   break;
                 default:
                   strcatchr(curdate,*format);
               }
               format++;
             }
             if ( *format ) format++;
          }

          while ( *ptr) {

             *buf = *ptr;
             ptr++;
             buf++;
             buflen--;

             if ( buflen <= 0  ) break;

          }
          if ( buflen <= 0  ) break;

       } else {

          *buf = *format;
          if (*format == '\\' || *format == '/')
            *buf = slashes[buf-ptr] = '\\';
          format++;
          buf++;
          buflen--;

          if ( buflen <= 0  ) break;

       }
    } else {

       *buf = *format;
       if (*format == '\\' || *format == '/')
         *buf = slashes[buf-ptr] = '\\';
       format++;
       buf++;
       buflen--;

       if ( buflen <= 0  ) break;
    }

 }
 *buf = 0;

 char *org = ptr;
 while ( *ptr )
 {

    const char *zz;
    if ( (slashes[ptr-org] != '\\') && (( zz = strchr( ILLEGAL_SYMB, *ptr ) ) != NULL) )
       *ptr = ILLEGAL_REPL[zz-ILLEGAL_SYMB];

    if ( *ptr < 32 || *ptr == 127 ) *ptr = 32;

    ptr++;
 }
 return 0;
}
Esempio n. 4
0
void plainconf::parseLine(const char *fileName, int lineNumber,
                          const char *sLine)
{
    const int MAX_NAME_LENGTH = 4096;
    char name[MAX_NAME_LENGTH] = {0};
    char value[MAX_NAME_LENGTH] = {0};
    const char *attr = NULL;

    XmlNode *pNode = NULL;
    XmlNode *pCurNode = (XmlNode *)gModuleList.back();
    const char *p = sLine;
    const char *pEnd = sLine + strlen(sLine);

    bool bNameSet = false;

    for (; p < pEnd; ++p)
    {
        //"{" is a beginning of a block only if it is the last char of a line
        if (*p == '{' && pEnd - p == 1)
        {
            if (strlen(name) > 0)
            {
                const char *pRealname = getRealName(name);

                if (pRealname)
                {
                    pNode = new XmlNode;
                    pNode->init(pRealname, &attr);

                    //Remove space in the end of the value such as "module cache  {", value will be "cache"
                    removeSpace(value, 1);

                    if (strlen(value) > 0)
                        pNode->setValue(value, strlen(value));

                    pCurNode->addChild(pNode->getName(), pNode);
                    gModuleList.push_back(pNode);
                    pCurNode = pNode;
                    clearNameAndValue(name, value);
                    break;
                }
                else
                {
                    logToMem(LOG_LEVEL_ERR,
                             "parseline find block name [%s] is NOT keyword in %s:%d", name, fileName,
                             lineNumber);
                    break;
                }
            }
            else
            {
                logToMem(LOG_LEVEL_ERR,
                         "parseline found '{' without a block name in %s:%d", fileName, lineNumber);
                break;
            }
        }

        else if (*p == '}' && p == sLine)
        {
            if (gModuleList.size() > 1)
            {
                gModuleList.pop_back();
                clearNameAndValue(name, value);

                if (*(p + 1))
                {
                    ++p;
                    trimWhiteSpace(&p);
                    parseLine(fileName, lineNumber, p);
                    break;
                }
            }
            else
            {
                logToMem(LOG_LEVEL_ERR, "parseline found more '}' in %s:%d", fileName,
                         lineNumber);
                clearNameAndValue(name, value);
                break;
            }
        }
        else if ((*p == ' ' || *p == '\t') && value[0] == 0)
        {
            bNameSet = true;
            continue;
        }
        else
        {
            if (!bNameSet)
                strcatchr(name, *p, MAX_NAME_LENGTH);
            else
                strcatchr(value, *p, MAX_NAME_LENGTH);
        }
    }

    if (name[0] != 0)
    {
        const char *pRealname = getRealName(name);

        if (pRealname)
        {
            assert(pNode == NULL);
            pNode = new XmlNode;
            pNode->init(pRealname, &attr);

            if (strlen(value) > 0)
                pNode->setValue(value, strlen(value));

            pCurNode->addChild(pNode->getName(), pNode);
        }
        else
        {
            //There is no special case in server level
            //if (memcmp(pCurNode->getName(), SERVER_ROOT_XML_NAME, sizeof(SERVER_ROOT_XML_NAME) - 1) != 0)
            saveUnknownItems(fileName, lineNumber, pCurNode, name, value);
            //else
            //    logToMem(LOG_LEVEL_ERR, "%s Server level find unknown keyword [%s], ignored.", SERVER_ROOT_XML_NAME, name );
        }
    }
}