"Fossies" - the Fresh Open Source Software Archive

Member "httperf-0.9.0/src/gen/misc.c" (7 Apr 2007, 3975 Bytes) of package /linux/www/old/httperf-0.9.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "misc.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2     httperf -- a tool for measuring web server performance
    3     Copyright 2000-2007 Hewlett-Packard Company and Contributors listed in
    4     AUTHORS file. Originally contributed by David Mosberger-Tang
    5 
    6     This file is part of httperf, a web server performance measurment
    7     tool.
    8 
    9     This program is free software; you can redistribute it and/or
   10     modify it under the terms of the GNU General Public License as
   11     published by the Free Software Foundation; either version 2 of the
   12     License, or (at your option) any later version.
   13     
   14     In addition, as a special exception, the copyright holders give
   15     permission to link the code of this work with the OpenSSL project's
   16     "OpenSSL" library (or with modified versions of it that use the same
   17     license as the "OpenSSL" library), and distribute linked combinations
   18     including the two.  You must obey the GNU General Public License in
   19     all respects for all of the code used other than "OpenSSL".  If you
   20     modify this file, you may extend this exception to your version of the
   21     file, but you are not obligated to do so.  If you do not wish to do
   22     so, delete this exception statement from your version.
   23 
   24     This program is distributed in the hope that it will be useful,
   25     but WITHOUT ANY WARRANTY; without even the implied warranty of
   26     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   27     General Public License for more details.
   28 
   29     You should have received a copy of the GNU General Public License
   30     along with this program; if not, write to the Free Software
   31     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
   32     02110-1301, USA
   33 */
   34 
   35 /* Implements miscellaneous command-line specified operations.  So
   36    far, the following options are implemented here:
   37    
   38     --add-header    Adds one or more command-line specified header(s)
   39             to each call request.
   40 
   41     --method    Sets the method to be used when performing a
   42             call.  */
   43 
   44 #include <assert.h>
   45 #include <ctype.h>
   46 #include <errno.h>
   47 #include <stdio.h>
   48 #include <stdlib.h>
   49 #include <string.h>
   50 
   51 #include <httperf.h>
   52 #include <call.h>
   53 #include <event.h>
   54 
   55 static const char *extra;
   56 static size_t extra_len;
   57 
   58 static size_t method_len;
   59 
   60 /* A simple module that collects cookies from the server responses and
   61    includes them in future calls to the server.  */
   62 
   63 static const char *
   64 unescape (const char *str, size_t *len)
   65 {
   66   char *dp, *dst = strdup (str);
   67   const char *cp;
   68   int ch;
   69 
   70   if (!dst)
   71     panic ("%s: strdup() failed: %s\n", prog_name, strerror (errno));
   72 
   73   for (cp = str, dp = dst; (ch = *cp++); )
   74     {
   75       if (ch == '\\')
   76     {
   77       ch = *cp++;
   78       switch (ch)
   79         {
   80         case '\\':  /* \\ -> \ */
   81           break;
   82 
   83         case 'a':   /* \a -> LF */
   84           ch = 10;
   85           break;
   86 
   87         case 'r':   /* \r -> CR */
   88           ch = 13;
   89           break;
   90 
   91         case 'n':   /* \n -> CR/LF */
   92           *dp++ = 13;
   93           ch = 10;
   94           break;
   95 
   96         case '0': case '1': case '2': case '3': case '4':
   97         case '5': case '6': case '7': case '8': case '9':
   98           ch = strtol (cp - 1, (char **) &cp, 8);
   99           break;
  100 
  101         default:
  102           fprintf (stderr, "%s: ignoring unknown escape sequence "
  103                "`\\%c' in --add-header\n", prog_name, ch);
  104           break;
  105         }
  106     }
  107       *dp++ = ch;
  108     }
  109   *len = dp - dst;
  110   return dst;
  111 }
  112 
  113 static void
  114 call_created (Event_Type et, Object *obj, Any_Type reg_arg, Any_Type arg)
  115 {
  116   Call *c = (Call *) obj;
  117 
  118   assert (et == EV_CALL_NEW && object_is_call (obj));
  119 
  120   if (method_len > 0)
  121     call_set_method (c, param.method, method_len);
  122 
  123   if (extra_len > 0)
  124     call_append_request_header (c, extra, extra_len);
  125 }
  126 
  127 
  128 static void
  129 init (void)
  130 {
  131   Any_Type arg;
  132 
  133   if (param.additional_header)
  134     extra = unescape (param.additional_header, &extra_len);
  135 
  136   if (param.method)
  137     method_len = strlen (param.method);
  138 
  139   arg.l = 0;
  140   event_register_handler (EV_CALL_NEW, call_created, arg);
  141 }
  142 
  143 Load_Generator misc =
  144   {
  145     "Miscellaneous command line options",
  146     init,
  147     no_op,
  148     no_op
  149   };