Fix compilation problems under Windows. In the GTK code, convert SSIDs

to GByteArrays.  Add format_uri() to strutil, which formats a byte string
with percent-escapes.  Fixup whitespace and indentation.

svn path=/trunk/; revision=20397
This commit is contained in:
Gerald Combs 2007-01-11 22:12:33 +00:00
parent 2b15cb0156
commit def1f435fc
6 changed files with 667 additions and 576 deletions

View File

@ -1551,9 +1551,6 @@ parse_key_string(gchar* input_string)
return NULL;
}
/*
* XXX - Maybe we need some check on the characters? I'm not sure if only standard ASCII are ok...
*/
if(ssid_ba->len > WPA_SSID_MAX_CHAR_SIZE)
{
g_string_free(key_string, TRUE);
@ -1575,8 +1572,7 @@ parse_key_string(gchar* input_string)
dk->type = AIRPDCAP_KEY_TYPE_WPA_PWD;
dk->key = g_string_new(key);
dk->bits = 256; /* This is the lenght of the array pf bytes that will be generated using key+ssid ...*/
if(ssid != NULL)
dk->ssid = byte_array_dup(ssid_ba);
dk->ssid = byte_array_dup(ssid_ba); /* NULL if ssid_ba is NULL */
g_string_free(key_string, TRUE);
if (ssid_ba != NULL)
@ -1595,7 +1591,11 @@ parse_key_string(gchar* input_string)
g_free(type);
g_free(key);
if(ssid != NULL) g_free(ssid); /* It is not always present */
if(ssid != NULL)
g_free(ssid); /* It is not always present */
if (ssid_ba != NULL)
g_byte_array_free(ssid_ba, TRUE);
/* Free the array of strings */
g_strfreev(tokens);

View File

@ -12,7 +12,7 @@ extern "C" {
#endif
void print_debug_line(CHAR *function, CHAR *msg, INT level) {
if (level<=AIRPDCAP_DEBUG_USED_LEVEL)
printf("dbg(%d)|(%s) %s\n", level, function, msg);
g_warning("dbg(%d)|(%s) %s", level, function, msg);
}
#ifdef __cplusplus
}

View File

@ -277,6 +277,7 @@ find_val_for_string
flags_set_truth DATA
follow_tcp_stats
format_text
format_uri
fragment_add
fragment_add_check
fragment_add_multiple_ok
@ -774,6 +775,7 @@ tvb_strsize
tvb_uncompress
UnregRejectReason_vals DATA
UnregRequestReason_vals DATA
uri_str_to_bytes
utf_8to16
utf_16to8
vals_pdu_type DATA

View File

@ -39,6 +39,9 @@
#include <wchar.h>
#endif
static const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
/*
* Given a pointer into a data buffer, and to the end of the buffer,
* find the end of the (putative) line at that position in the data
@ -387,8 +390,6 @@ bytes_to_str_punct(const guint8 *bd, int bd_len, gchar punct) {
gchar *cur;
gchar *p;
int len;
static const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
cur=ep_alloc(MAX_BYTE_STR_LEN+3+1);
p = cur;
@ -542,10 +543,80 @@ uri_str_to_bytes(const char *uri_str, GByteArray *bytes) {
p++;
}
g_warning("ba %s len: %d", format_text(bytes->data, bytes->len), bytes->len);
return TRUE;
}
/*
* Given a GByteArray, generate a string from it that shows non-printable
* characters as percent-style escapes, and return a pointer to it.
*/
gchar *
format_uri(const GByteArray *bytes, const gchar *reserved_chars)
{
static gchar *fmtbuf[3];
static guint fmtbuf_len[3];
static guint idx;
const gchar *reserved_def = ":/?#[]@!$&'()*+,;= ";
const gchar *reserved = reserved_def;
guint8 c;
guint column, i;
gboolean is_reserved = FALSE;
if (! bytes)
return "";
idx = (idx + 1) % 3;
if (reserved_chars)
reserved = reserved_chars;
/*
* Allocate the buffer if it's not already allocated.
*/
if (fmtbuf[idx] == NULL) {
fmtbuf[idx] = g_malloc(INITIAL_FMTBUF_SIZE);
fmtbuf_len[idx] = INITIAL_FMTBUF_SIZE;
}
for (column = 0; column < bytes->len; column++) {
/*
* Is there enough room for this character, if it expands to
* a percent plus 2 hex digits (which is the most it can
* expand to), and also enough room for a terminating '\0'?
*/
if (column+2+1 >= fmtbuf_len[idx]) {
/*
* Double the buffer's size if it's not big enough.
* The size of the buffer starts at 128, so doubling its size
* adds at least another 128 bytes, which is more than enough
* for one more character plus a terminating '\0'.
*/
fmtbuf_len[idx] = fmtbuf_len[idx] * 2;
fmtbuf[idx] = g_realloc(fmtbuf[idx], fmtbuf_len[idx]);
}
c = bytes->data[column];
if (!isascii(c) || !isprint(c) || c == '%') {
is_reserved = TRUE;
}
for (i = 0; i < strlen(reserved); i++) {
if (c == reserved[i])
is_reserved = TRUE;
}
if (!is_reserved) {
fmtbuf[idx][column] = c;
} else {
fmtbuf[idx][column] = '%';
column++;
fmtbuf[idx][column] = hex[c >> 4];
column++;
fmtbuf[idx][column] = hex[c & 0xF];
}
}
fmtbuf[idx][column] = '\0';
return fmtbuf[idx];
}
/**
* Create a copy of a GByteArray
*

View File

@ -107,10 +107,26 @@ gboolean hex_str_to_bytes(const char *hex_str, GByteArray *bytes,
* @param bytes The GByteArray that will receive the bytes. This
* must be initialized by the caller.
* @return True if the string was converted successfully
* @see format_uri()
*/
gboolean uri_str_to_bytes(const char *uri_str, GByteArray *bytes);
/** Turn a OID string representation (dot notaion) into a byte array.
/** Turn a byte array into an RFC 3986 percent-encoded string.
*
* @param bytes The GByteArray that will receive the bytes. This
* must be initialized by the caller.
* @param reserved_chars Normally the "gen-delims" and "sub-delims"
* from RFC 3986 (":/?#[]@" and "!$&'()*+,;=" respectively)
* plus space (hex value 20) are treated as reserved characters.
* If this variable is non-NULL, its contents will be used
* instead.
* @note Any non-printing character determined by isprint(), along
* with the % character itself are always reserved.
* @see uri_str_to_bytes(), format_text(), isprint()
*/
gchar* format_uri(const GByteArray *bytes, const gchar *reserved_chars);
/** Turn a OID string representation (dot notation) into a byte array.
*
* @param oid_str The OID string (dot notaion).
* @param bytes The GByteArray that will receive the bytes. This

File diff suppressed because it is too large Load Diff