Changeset 11 for trunk/src/sh_tools.c


Ignore:
Timestamp:
Jan 2, 2006, 12:03:25 AM (19 years ago)
Author:
rainer
Message:

Minor optimisations for server

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_tools.c

    r1 r11  
    7878#endif
    7979
     80#define SH_REAL_SET
     81
    8082#include "samhain.h"
    8183#include "sh_mem.h"
     
    121123char * sh_tools_safe_name (const char * instr, int flag)
    122124{
     125  static   char ctest = ~('\\'|'&'|'='|'\'');
    123126  unsigned char c;
    124127  const  char * p;
    125128  char   tmp[4];
    126129  char * outstr;
    127   int    len;
     130  int    len = 1;
    128131  int    i = 0;
    129132  unsigned char   val_octal = '\0';
     
    133136  if (instr)
    134137    len = (3 * strlen(instr)) + 4;
    135   else
    136     len = 1;
    137138
    138139  outstr = SH_ALLOC(len);
     
    143144  p = instr;
    144145
    145   while (p && *p)
     146#if !defined(SH_USE_XML)
     147  (void) flag; /* fix compiler warning */
     148#endif
     149
     150  if (!p)
     151    goto end;
     152
     153  while (*p)
    146154    {
    147155      c = *p;
     
    154162
    155163#ifdef SH_USE_XML
    156       if (flag == 1 && (*p) == '"')
    157         {
    158           sprintf(&outstr[i], "=%02x", c);   i+=3; ++p;  /* known to fit  */
    159           continue;
    160         }
    161       else if (flag == 1 && (*p) == '&')
    162         {
    163           sprintf(&outstr[i], "=%02x", c);   i+=3; ++p;  /* known to fit  */
    164           continue;
    165         }
    166       else if (flag == 1 && (*p) == '<')
    167         {     /* left angle       */
    168           sprintf(&outstr[i], "=%02x", c);   i+=3; ++p;  /* known to fit  */
    169           continue;
    170         }
    171       else if (flag == 1 && (*p) == '>')
    172         {     /* right angle      */
    173           sprintf(&outstr[i], "=%02x", c);   i+=3; ++p;  /* known to fit  */
    174           continue;
     164      if (flag == 1)
     165        {
     166          if ((*p) == '"')
     167            {
     168              sprintf(&outstr[i], "=%02x", c);i+=3; ++p; /* known to fit  */
     169              continue;
     170            }
     171          else if ((*p) == '&')
     172            {
     173              sprintf(&outstr[i], "=%02x", c);i+=3; ++p; /* known to fit  */
     174              continue;
     175            }
     176          else if ((*p) == '<')
     177            {     /* left angle       */
     178              sprintf(&outstr[i], "=%02x", c);i+=3; ++p; /* known to fit  */
     179              continue;
     180            }
     181          else if ((*p) == '>')
     182            {     /* right angle      */
     183              sprintf(&outstr[i], "=%02x", c);i+=3; ++p; /* known to fit  */
     184              continue;
     185            }
    175186        }
    176 #else
    177       (void) flag; /* fix compiler warning */
    178 #endif
    179 
    180       if ( (*p) != '\\' && (*p) != '&' && (*p) != '='  && (*p) != '\'')
     187#endif
     188
     189      /* if ( (*p) != '\\' && (*p) != '&' && (*p) != '='  && (*p) != '\'') */
     190      if (((*p) & ctest) != 0)
    181191        {
     192          outstr[i] = *p; ++i;
     193          ++p;
     194             
    182195          if (c < 31 || c > 126)
    183196            {
    184               sprintf(&outstr[i], "=%02x", c); i+=3; ++p;/* known to fit  */
     197              --i;
     198              sprintf(&outstr[i], "=%02x", c);          /* known to fit  */
    185199            }
    186           else
    187             {
    188               outstr[i] = *p;
    189               ++i; ++p;
    190             }
     200
    191201          continue;
    192202        }
     
    272282          }
    273283        }
    274       else /* *p == '&' */
     284      else if (*p == '&')
    275285        {
    276286          ++p;
     
    303313              outstr[i] = '&'; ++i;
    304314            }
    305         }     
     315        }
     316      else
     317        {
     318          outstr[i] = *p; ++i;
     319          ++p;
     320        }
    306321    } /* while (p && *p) */
     322
     323 end:
    307324 
    308325  outstr[i] = '\0';
Note: See TracChangeset for help on using the changeset viewer.