| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

http_escape_hex

#include "sflhttp.h"
char *
http_escape_hex (
    const char *string,
    char  *result,
    size_t outmax)

Synopsis

Works as http escape(), but converts spaces to %20 instead of '+'. This encoding is standard for filenames and URL requests.

Source Code - (sflhttp.c)

{
    char
        *target;                        /*  Where we store the result        */
    size_t
        length;                         /*  of escaped character             */

    ASSERT (string);
    if (outmax == 0)                    /*  If no fixed length, get total len*/
        outmax = http escape size (string);

    if (result == NULL)
        if ((result = mem_alloc (outmax)) == NULL)
            return (NULL);              /*  Could not allocate a block       */

    if (outmax > 1)
        outmax -= 1;                    /*  Leave space for NULL terminator  */
    else
    if (outmax == 1)                    /*  Only room for terminator         */
      {
        *result = '\0';
        return (result);
      }
    target = result;
    while (*string)
      {
        length = http_escape_char (*string, target, outmax, TRUE);
        if (length == 0)
            break;

        target += length;
        outmax -= length;
        if (*string == '\n' || *string == '\r')
          {
            if ((string [1] == '\n' || string [1] == '\r')
            &&  (string [1] != *string))
                string++;
          }
        string++;
      }
    *target = '\0';                     /*  Terminate target string          */
    return (result);
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation