Re: URL encoding feature




There was a bug with '\n' being transmitted as %a only
They should be %0D%0A

The updated flies are attached.
-- 
Ahmadster
www.BitBuilder.com
/* URL_ENCODE */

/* From RFC 2396 : ------------------------------------------------- /

 The query component is a string of information to be interpreted by
   the resource.

      query         = *uric

   Within a query component, the characters ";", "/", "?", ":", "@",
   "&", "=", "+", ",", and "$" are reserved.

--------------------------------------------------------------------*/

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>

#include <gnome.h>
#include "url_encode.h"

#define RESERVED_CHARS	"!\"'()*+-.<>[]\\^_`{}|~\t#;/?:@&=+,$% \r\n\v\x7f"


/*
   Not the most effecient way of doing this,
   If you can come up with something better
   let me know,
   Ahmad Baitalmal <ahmad bitbuilder com>
   											*/
gchar* url_encode( gchar* source ){
	gint length = strlen( source );
	gint i;
	gchar*	encoded;

	g_return_val_if_fail( source != NULL, source );
	encoded = g_strdup("");
	for( i=0; i<length; i++ ){
		encoded = append_char( encoded, source[i], (gboolean) strchr( RESERVED_CHARS, source[i] ) );
	}
	g_free( source );
	return encoded;
}

gchar* append_char( gchar* url_string, gchar char_to_append, gboolean convert_to_hex ){
	gchar* new_string;
	if( convert_to_hex ){
		switch( char_to_append ){
			case '\n':
				new_string = g_strdup_printf("%s%%0D%%%02X", url_string, char_to_append);
				break;
			default:
				new_string = g_strdup_printf("%s%%%02X", url_string, char_to_append);
		}
	}
	else
		new_string = g_strdup_printf("%s%c", url_string, char_to_append);
	g_free( url_string );
	return new_string;
}
/* URL_ENCODE_H */

gchar* url_encode( gchar* source );
gchar* append_char( gchar* url_string, gchar char_to_append, gboolean convert_to_hex );


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]