Subversion Repositories svn1

Rev

Rev 61 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 61 Rev 68
Line 690... Line 690...
690
    va_end( ap );
690
    va_end( ap );
691
 
691
 
692
    return ( pp );
692
    return ( pp );
693
}
693
}
694
 
694
 
-
 
695
/*----------------------------------------------------------------------------
-
 
696
** FUNCTION           : to_hex
-
 
697
**
-
 
698
** DESCRIPTION        : Converts an integer value to its hex character
-
 
699
**
-
 
700
**
-
 
701
** INPUTS             : code        - Code to convert
-
 
702
**
-
 
703
** RETURNS            : Character representation
-
 
704
**
-
 
705
----------------------------------------------------------------------------*/
-
 
706
 
-
 
707
char to_hex(char code)
-
 
708
{
-
 
709
  static char hex[] = "0123456789abcdef";
-
 
710
  return hex[code & 0x0f];
-
 
711
}
-
 
712
 
-
 
713
/*----------------------------------------------------------------------------
-
 
714
** FUNCTION           : url_encode
-
 
715
**
-
 
716
** DESCRIPTION        : URL encoded version of a string
-
 
717
**
-
 
718
**
-
 
719
** INPUTS             : string to encode
-
 
720
**
-
 
721
** RETURNS            : Encoded string
-
 
722
**
-
 
723
** WARNING            : Uses a small circular pool of strings so that the
-
 
724
**                      user doesn't need to worry about string release
-
 
725
**
-
 
726
----------------------------------------------------------------------------*/
-
 
727
char *url_encode(char *str)
-
 
728
{
-
 
729
    static char tbuf[TBUF_COUNT][TBUF_LENGTH * 3];
-
 
730
    static int  index = 0;
-
 
731
    char       *pp;
-
 
732
 
-
 
733
    /*
-
 
734
    **  Get the next entry from the small store
-
 
735
    */
-
 
736
    index++;
-
 
737
    if( index >= TBUF_COUNT )
-
 
738
        index = 0;
-
 
739
    pp = tbuf[index];
-
 
740
    
-
 
741
    char *pstr = str;
-
 
742
    char *pbuf = pp;
-
 
743
 
-
 
744
    while (*pstr)
-
 
745
    {
-
 
746
        if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~')
-
 
747
            *pbuf++ = *pstr;
-
 
748
        else if (*pstr == ' ')
-
 
749
            *pbuf++ = '+';
-
 
750
        else
-
 
751
        {
-
 
752
            *pbuf++ = '%';
-
 
753
            *pbuf++ = to_hex(*pstr >> 4);
-
 
754
            *pbuf++ = to_hex(*pstr & 15);
-
 
755
        }
-
 
756
        pstr++;
-
 
757
    }
-
 
758
    *pbuf = '\0';
-
 
759
  return pp;
-
 
760
}
-
 
761
 
695
/********************************* EOF ***********************************/
762
/********************************* EOF ***********************************/