Пример #1
0
// see http://support.apple.com/kb/TA26907:
// WebObjects 5.1: How to Improve Performance of IIS Adaptor on
// Microsoft Windows
static void req_appendHeader(const char *key, const char *val, String *headers) 
{
   int valLength = strlen(val);
   while (val[valLength - 1] == '\r' || val[valLength - 1] == '\n') 
   {
      valLength--;
   }
   str_append(headers, key);
   str_appendLiteral(headers, ": ");
   str_appendLength(headers, val, valLength);
   str_appendLiteral(headers, "\r\n");
}
Пример #2
0
static String *tr_uniqueID()
{
   String *uniqueID;
   char counter_str[9];
   int count;

   uniqueID = str_create(uniqueID_str, 25);

   WA_lock(tr_lock);
   count = uniqueID_counter++;
   WA_unlock(tr_lock);
   sprintf(counter_str, "%8.8x", count);
   str_appendLength(uniqueID, counter_str, 8);
   return uniqueID;
}
Пример #3
0
static String *recvline(net_fd s)
{
   int len;
   String *result;
   int gotCRLF = 0;
   
   if (s->status != TR_OK) {
       WOLog(WO_ERR, "Request failed with status %d", s->status);
       return NULL;
   }
   
   result = str_create(NULL, 0);
   if (!result)
   {
       WOLog(WO_ERR, "Error creating String");
       return NULL;
   }
   
   do
   {       
       if (s->count == 0)
       {
           fillbuf(s);
           if (s->status != TR_OK || s->count == 0)
           {
               WOLog(WO_ERR, "Request failed with status %d (fillbuf)", s->status);
               str_free(result);
               return NULL;
           }
       }

       for (len = 0; len < s->count; len++)
       {
           if (s->pos[len] == '\r' || s->pos[len] == '\n')
           {
               gotCRLF = 1;
               break;
           }
       }

       // if header length > 10240 drop header (see below)
       if (result->length < 10240)
       {
           if(str_appendLength(result, s->pos, len) != 0)
               WOLog(WO_ERR, "str_appendLength failed (%s, %s, %d)", result, s->pos, len);
       }

       s->count -= len;
       s->pos += len;

   } while (!gotCRLF);

   // consume CR/LF
   s->count -= 1;
   s->pos += 1;

   len = 0;
   
   if (s->pos[-1] == '\r')
   {
      /* saw a \r - need to look ahead 1 char for a \n */
      if (s->count == 0)
      {
         fillbuf(s);
         if (s->status != TR_OK || s->count == 0)
         {
             WOLog(WO_ERR, "Request failed with status %d (fillbuf lookahead)", s->status);
             str_free(result);
             return NULL;
         }
      }

       if (s->pos[len] == '\n')
         len++;
   }
   
   s->count -= len;
   s->pos += len;

   /* place an arbitrary limit on the length of a header line */
   if (result->length > 10240)
   {
       WOLog(WO_ERR, "Header length > 10240");
       str_free(result);
       return NULL;
   }

   return result;
}