Logo Search packages:      
Sourcecode: wireshark version File versions  Download package

gboolean uri_str_to_bytes ( const char *  uri_str,
GByteArray *  bytes 
)

Turn an RFC 3986 percent-encoded string into a byte array.

Parameters:
uri_str The string of hex digits.
bytes The GByteArray that will receive the bytes. This must be initialized by the caller.
Returns:
True if the string was converted successfully
See also:
format_uri()

Definition at line 552 of file strutil.c.

                                                         {
      guint8            val;
      const guchar      *p;
      guchar            hex_digit[HEX_DIGIT_BUF_LEN];

      g_byte_array_set_size(bytes, 0);
      if (! uri_str) {
            return FALSE;
      }

      p = (const guchar *)uri_str;

      while (*p) {
            if (! isascii(*p) || ! isprint(*p))
                  return FALSE;
            if (*p == '%') {
                  p++;
                  if (*p == '\0') return FALSE;
                  hex_digit[0] = *p;
                  p++;
                  if (*p == '\0') return FALSE;
                  hex_digit[1] = *p;
                  hex_digit[2] = '\0';
                  if (! isxdigit(hex_digit[0]) || ! isxdigit(hex_digit[1]))
                        return FALSE;
                  val = (guint8) strtoul((char *)hex_digit, NULL, 16);
                  g_byte_array_append(bytes, &val, 1);
            } else {
                  g_byte_array_append(bytes, (guint8 *) p, 1);
            }
            p++;

      }
      return TRUE;
}


Generated by  Doxygen 1.6.0   Back to index