Branch: Tag:

2005-10-27

2005-10-27 16:49:54 by Henrik Grubbström (Grubba) <grubba@grubba.org>

make_http_headers() now has an option to skip adding the terminating CRLF.

Rev: src/modules/_Roxen/roxen.c:1.46

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: roxen.c,v 1.45 2005/05/06 00:46:06 nilsson Exp $ + || $Id: roxen.c,v 1.46 2005/10/27 16:49:54 grubba Exp $   */      #define NO_PIKE_SHORTHAND
248:      static void f_make_http_headers( INT32 args )   /*! @decl string @ -  *! make_http_headers(mapping(string:string|array(string)) headers) +  *! make_http_headers(mapping(string:string|array(string)) headers, @ +  *! int(0..1)|void no_terminator)    */   {    int total_len = 0, e;
256:    struct mapping *m;    struct keypair *k;    struct pike_string *res; -  if( Pike_sp[-1].type != PIKE_T_MAPPING ) +  int terminator = 2; +  +  if( Pike_sp[-args].type != PIKE_T_MAPPING )    Pike_error("Wrong argument type to make_http_headers(mapping heads)\n"); -  +  m = Pike_sp[-args].u.mapping;    -  m = Pike_sp[-1].u.mapping; +  if (args > 1) { +  if (Pike_sp[1-args].type != PIKE_T_INT) +  Pike_error("Bad argument 2 to make_http_headers(). Expected int.\n"); +  if (Pike_sp[1-args].u.integer) +  terminator = 0; +  } +     /* loop to check len */    NEW_MAPPING_LOOP( m->data )    {
284:    "mapping(string(8bit):string(8bit)|"    "array(string(8bit))) heads)\n");    } -  total_len += 2; +  total_len += terminator;       res = begin_shared_string( total_len );    pnt = STR0(res);
312:    }    }    } +  if (terminator) {    *(pnt++) = '\r';    *(pnt++) = '\n'; -  +  }       pop_n_elems( args );    push_string( end_shared_string( res ) );
544:   PIKE_MODULE_INIT   {    ADD_FUNCTION("make_http_headers", f_make_http_headers, -  tFunc(tMap(tStr,tOr(tStr,tArr(tStr))),tStr), 0 ); +  tFunc(tMap(tStr,tOr(tStr,tArr(tStr))) tOr(tInt01,tVoid), tStr), +  0);       ADD_FUNCTION("http_decode_string", f_http_decode_string,    tFunc(tStr,tStr), 0 );