Changeset 9829


Ignore:
Timestamp:
07/01/08 18:18:28 (5 years ago)
Author:
BrainSlayer
Message:

takes less memory

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/router/httpd/ej.c

    r9812 r9829  
    107107 
    108108 
     109void 
     110do_ej_file (FILE *fp,int filelen, webs_t stream)        // jimmy, https, 8/4/2003 
     111{ 
     112  void *handle = NULL; 
     113  int c; 
     114  char *pattern, *asp = NULL, *func = NULL, *end = NULL; 
     115  int len = 0; 
     116  int filecount = 0; 
     117 
     118  pattern = (char *) malloc (PATTERN_BUFFER + 1); 
     119  while (((c = getc(fp)) != EOF) && filecount<filelen) 
     120    { 
     121      filecount++; 
     122      /* Add to pattern space */ 
     123      pattern[len++] = c; 
     124      pattern[len] = '\0'; 
     125      if (len == (PATTERN_BUFFER - 1)) 
     126        goto release; 
     127 
     128 
     129      /* Look for <% ... */ 
     130//      LOG("look start"); 
     131 
     132      if (!asp && pattern[0] == '{') 
     133        { 
     134 
     135          if (!strncmp (pattern, "{i}", len)) 
     136            { 
     137              if (len == 3) 
     138                { 
     139                  websWrite (stream, "<input type="); 
     140                  len = 0; 
     141                } 
     142              continue; 
     143            } 
     144          if (!strncmp (pattern, "{c}", len)) 
     145            { 
     146              if (len == 3) 
     147                { 
     148                  websWrite (stream, "<input class="); 
     149                  len = 0; 
     150                } 
     151              continue; 
     152            } 
     153          if (!strncmp (pattern, "{d}", len)) 
     154            { 
     155              if (len == 3) 
     156                { 
     157                  websWrite (stream, "<input id="); 
     158                  len = 0; 
     159                } 
     160              continue; 
     161            } 
     162          if (!strncmp (pattern, "{e}", len)) 
     163            { 
     164              if (len == 3) 
     165                { 
     166                  websWrite (stream, "<div class="); 
     167                  len = 0; 
     168                } 
     169              continue; 
     170            } 
     171          if (!strncmp (pattern, "{n}", len)) 
     172            { 
     173              if (len == 3) 
     174                { 
     175                  websWrite (stream, "<div id="); 
     176                  len = 0; 
     177                } 
     178              continue; 
     179            } 
     180          if (!strncmp (pattern, "{j}", len)) 
     181            { 
     182              if (len == 3) 
     183                { 
     184                  websWrite (stream, "<a href=\""); 
     185                  len = 0; 
     186                } 
     187              continue; 
     188            } 
     189          if (!strncmp (pattern, "{o}", len)) 
     190            { 
     191              if (len == 3) 
     192                { 
     193                  websWrite (stream, "<option value="); 
     194                  len = 0; 
     195                } 
     196              continue; 
     197            } 
     198          if (!strncmp (pattern, "{s}", len)) 
     199            { 
     200              if (len == 3) 
     201                { 
     202                  websWrite (stream, "<select name="); 
     203                  len = 0; 
     204                } 
     205              continue; 
     206            } 
     207          if (!strncmp (pattern, "{u}", len)) 
     208            { 
     209              if (len == 3) 
     210                { 
     211                  websWrite (stream, "<span class="); 
     212                  len = 0; 
     213                } 
     214              continue; 
     215            } 
     216          if (!strncmp (pattern, "{z}", len)) 
     217            { 
     218              if (len == 3) 
     219                { 
     220                  websWrite (stream, "<input name="); 
     221                  len = 0; 
     222                } 
     223              continue; 
     224            } 
     225          if (!strncmp (pattern, "{x}", len)) 
     226            { 
     227              if (len == 3) 
     228                { 
     229                  websWrite (stream, "document.write(\""); 
     230                  len = 0; 
     231                } 
     232              continue; 
     233            } 
     234          if (!strncmp (pattern, "{y}", len)) 
     235            { 
     236              if (len == 3) 
     237                { 
     238                  websWrite (stream, "<document."); 
     239                  len = 0; 
     240                } 
     241              continue; 
     242            } 
     243          if (!strncmp (pattern, "{m}", len)) 
     244            { 
     245              if (len == 3) 
     246                { 
     247                  websWrite (stream, "<script type=\"text/javascript\">"); 
     248                  len = 0; 
     249                } 
     250              continue; 
     251            } 
     252        } 
     253      if (!asp && !strncmp (pattern, "<%", len)) 
     254        { 
     255          if (len == 2) 
     256            asp = pattern + 2; 
     257          continue; 
     258        } 
     259 
     260      /* Look for ... %> */ 
     261//      LOG("look end"); 
     262      if (asp) 
     263        { 
     264          if (unqstrstr (asp, "%>")) 
     265            { 
     266              for (func = asp; func < &pattern[len]; func = end) 
     267                { 
     268                  /* Skip initial whitespace */ 
     269                  for (; isspace ((int) *func); func++); 
     270                  if (!(end = uqstrchr (func, ';'))) 
     271                    break; 
     272                  *end++ = '\0'; 
     273 
     274                  /* Call function */ 
     275                  handle = call (handle, func, stream); 
     276                } 
     277              asp = NULL; 
     278              len = 0; 
     279            } 
     280          continue; 
     281        } 
     282 
     283    release: 
     284      /* Release pattern space */ 
     285      //fputs(pattern, stream); 
     286      wfputs (pattern, stream); //jimmy, https, 8/4/2003 
     287      len = 0; 
     288    } 
     289  free (pattern); 
     290  if (handle) 
     291    dlclose (handle); 
     292} 
     293 
    109294 
    110295void 
     
    384569  return len; 
    385570} 
     571 
    386572 
    387573void 
     
    402588#endif 
    403589 
    404 #ifdef HAVE_VFS 
    405   e = vfsopen (path, "rb"); 
    406   if (e == NULL) 
    407     { 
    408 #endif 
    409590      i = 0; 
    410591      len = 0; 
     
    421602          i++; 
    422603        } 
    423       int le = 0; 
    424604      if (fp == NULL) 
    425605        { 
    426           le = 1; 
    427           FILE *in = fopen (path, "rb"); 
    428           if (in == NULL) 
     606          fp = fopen (path, "rb"); 
     607          if (fp == NULL) 
    429608            return; 
    430           fseek (in, 0, SEEK_END); 
    431           len = ftell (in); 
    432           rewind (in); 
    433           buffer = (char *) malloc (len + 1); 
    434           fread (buffer, 1, len, in); 
    435           buffer[len] = 0; 
    436           fclose (in); 
     609          fseek (fp, 0, SEEK_END); 
     610          len = ftell (fp); 
     611          rewind (fp); 
     612          do_ej_file(fp,len,stream); 
    437613        } 
    438614      else 
    439615        { 
    440           le = 1; 
    441           buffer = (char *) malloc (len + 1); 
    442           fread (buffer, 1, len, fp); 
    443           buffer[len] = 0; 
    444           fclose (fp); 
    445         } 
    446       /*if (x) 
    447          { 
    448          for (i = 0;i<len;i++) 
    449          buffer[i]^='d'; 
    450          char b; 
    451          for (i = 0;i<len/2;i++) 
    452          { 
    453          b = buffer[i]; 
    454          buffer[i]=buffer[(len-1)-i]; 
    455          buffer[(len-1)-i]=b; 
    456          } 
    457          } */ 
    458  
    459  
    460 #ifdef HAVE_VFS 
    461     } 
    462   else 
    463     { 
    464  
    465       len = e->filelen; 
    466       buffer = (char *) malloc (len + 1 + PATTERN_BUFFER); 
    467       vfsread (buffer, 1, len, e); 
    468       for (i = len; i < len + PATTERN_BUFFER; i++) 
    469         buffer[i] = 0; 
    470       vfsclose (e); 
    471  
    472     } 
    473 #endif 
    474  
    475   do_ej_buffer (buffer, stream); 
    476   if (le) 
    477     free (buffer); 
     616          do_ej_file(fp,len,stream); 
     617        } 
     618fclose (fp); 
     619 
     620 
     621 
    478622} 
    479623 
Note: See TracChangeset for help on using the changeset viewer.