changeset 17326:f057837085b0

Change to use const gchar * where appropriate.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Thu, 14 Jun 2007 08:18:59 +0000
parents 1a26b36889dc
children 320b0b450c7b
files libpurple/protocols/myspace/message.c libpurple/protocols/myspace/message.h libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/myspace.h
diffstat 4 files changed, 74 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/message.c	Thu Jun 14 06:06:56 2007 +0000
+++ b/libpurple/protocols/myspace/message.c	Thu Jun 14 08:18:59 2007 +0000
@@ -24,9 +24,9 @@
 
 static void msim_msg_free_element(gpointer data, gpointer user_data);
 static void msim_msg_debug_string_element(gpointer data, gpointer user_data);
-static gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, gchar *sep, gchar *begin, gchar *end);
+static gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, const gchar *sep, const gchar *begin, const gchar *end);
 static gchar *msim_msg_pack_element_data(MsimMessageElement *elem);
-static GList *msim_msg_get_node(MsimMessage *msg, gchar *name);
+static GList *msim_msg_get_node(MsimMessage *msg, const gchar *name);
 static MsimMessage *msim_msg_new_v(va_list argp);
 
 /** Create a new MsimMessage. 
@@ -287,7 +287,7 @@
  *
  * For internal use; users probably want msim_msg_append() or msim_msg_insert_before(). 
  */
-static MsimMessageElement *msim_msg_element_new(gchar *name, MsimMessageType type, gpointer data)
+static MsimMessageElement *msim_msg_element_new(const gchar *name, MsimMessageType type, gpointer data)
 {
 	MsimMessageElement *elem;
 
@@ -328,7 +328,7 @@
  * * MSIM_TYPE_LIST: TODO
  *
  * */
-MsimMessage *msim_msg_append(MsimMessage *msg, gchar *name, MsimMessageType type, gpointer data)
+MsimMessage *msim_msg_append(MsimMessage *msg, const gchar *name, MsimMessageType type, gpointer data)
 {
 	return g_list_append(msg, msim_msg_element_new(name, type, data));
 }
@@ -340,7 +340,7 @@
  *
  * See msim_msg_append() for usage of other parameters, and an important note about return value.
  */
-MsimMessage *msim_msg_insert_before(MsimMessage *msg, gchar *name_before, gchar *name, MsimMessageType type, gpointer data)
+MsimMessage *msim_msg_insert_before(MsimMessage *msg, const gchar *name_before, const gchar *name, MsimMessageType type, gpointer data)
 {
 	MsimMessageElement *new_elem;
 	GList *node_before;
@@ -355,7 +355,7 @@
 /** Pack a string using the given GFunc and seperator.
  * Used by msim_msg_dump() and msim_msg_pack().
  */
-static gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, gchar *sep, gchar *begin, gchar *end)
+gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, const gchar *sep, const gchar *begin, const gchar *end)
 {
 	gchar **strings;
 	gchar **strings_tmp;
@@ -450,7 +450,7 @@
  *
  * @param fmt_string A static string, in which '%s' will be replaced.
  */
-void msim_msg_dump(gchar *fmt_string, MsimMessage *msg)
+void msim_msg_dump(const gchar *fmt_string, MsimMessage *msg)
 {
 	gchar *debug_str;
 
@@ -469,7 +469,7 @@
 
 /** Return a message element data as a new string for a raw protocol message, converting from other types (integer, etc.) if necessary.
  *
- * @return gchar * The data as a string, or NULL. Caller must g_free().
+ * @return const gchar * The data as a string, or NULL. Caller must g_free().
  *
  * Returns a string suitable for inclusion in a raw protocol message, not necessarily
  * optimal for human consumption. For example, strings are escaped. Use 
@@ -484,7 +484,7 @@
 
 		case MSIM_TYPE_RAW:
 			/* Not un-escaped - this is a raw element, already escaped if necessary. */
-			return g_strdup((gchar *)elem->data);
+			return (gchar *)g_strdup((gchar *)elem->data);
 
 		case MSIM_TYPE_STRING:
 			/* Strings get escaped. msim_escape() creates a new string. */
@@ -735,7 +735,7 @@
  * access the MsimMessageElement *, instead of the GList * container.
  *
  */
-static GList *msim_msg_get_node(MsimMessage *msg, gchar *name)
+static GList *msim_msg_get_node(MsimMessage *msg, const gchar *name)
 {
 	GList *i;
 
@@ -770,7 +770,7 @@
  * you can access directly. But it is often more convenient to use
  * another msim_msg_get_* that converts the data to what type you want.
  */
-MsimMessageElement *msim_msg_get(MsimMessage *msg, gchar *name)
+MsimMessageElement *msim_msg_get(MsimMessage *msg, const gchar *name)
 {
 	GList *node;
 
@@ -791,7 +791,7 @@
  * for inclusion into a raw protocol string (escaped and everything).
  * This function unescapes the string for you, if needed.
  */
-gchar *msim_msg_get_string(MsimMessage *msg, gchar *name)
+gchar *msim_msg_get_string(MsimMessage *msg, const gchar *name)
 {
 	MsimMessageElement *elem;
 
@@ -830,7 +830,7 @@
  * even if it is not stored as an MSIM_TYPE_INTEGER. MSIM_TYPE_STRING will
  * be converted handled correctly, for example.
  */
-guint msim_msg_get_integer(MsimMessage *msg, gchar *name)
+guint msim_msg_get_integer(MsimMessage *msg, const gchar *name)
 {
 	MsimMessageElement *elem;
 
@@ -859,7 +859,7 @@
  *
  * @return TRUE if successful, FALSE if not.
  */
-gboolean msim_msg_get_binary(MsimMessage *msg, gchar *name, gchar **binary_data, gsize *binary_length)
+gboolean msim_msg_get_binary(MsimMessage *msg, const gchar *name, gchar **binary_data, gsize *binary_length)
 {
 	MsimMessageElement *elem;
 
--- a/libpurple/protocols/myspace/message.h	Thu Jun 14 06:06:56 2007 +0000
+++ b/libpurple/protocols/myspace/message.h	Thu Jun 14 08:18:59 2007 +0000
@@ -28,7 +28,7 @@
 #define MsimMessage GList		/* #define instead of typedef to avoid casting */
 typedef struct _MsimMessageElement
 {
-	gchar *name;					/**< Textual name of element. */
+	const gchar *name;				/**< Textual name of element. */
 	guint type;						/**< MSIM_TYPE_* code. */
 	gpointer data;					/**< Pointer to data, or GUINT_TO_POINTER for int/bool. */
 } MsimMessageElement;
@@ -49,9 +49,9 @@
 
 MsimMessage *msim_msg_clone(MsimMessage *old);
 void msim_msg_free(MsimMessage *msg);
-MsimMessage *msim_msg_append(MsimMessage *msg, gchar *name, MsimMessageType type, gpointer data);
-MsimMessage *msim_msg_insert_before(MsimMessage *msg, gchar *name_before, gchar *name, MsimMessageType type, gpointer data);
-void msim_msg_dump(char *fmt_string, MsimMessage *msg);
+MsimMessage *msim_msg_append(MsimMessage *msg, const gchar *name, MsimMessageType type, gpointer data);
+MsimMessage *msim_msg_insert_before(MsimMessage *msg, const gchar *name_before, const gchar *name, MsimMessageType type, gpointer data);
+void msim_msg_dump(const char *fmt_string, MsimMessage *msg);
 gchar *msim_msg_pack(MsimMessage *msg);
 
 /* Defined in myspace.h */
@@ -70,9 +70,9 @@
 MsimMessage *msim_parse(gchar *raw);
 GHashTable *msim_parse_body(const gchar *body_str);
 
-MsimMessageElement *msim_msg_get(MsimMessage *msg, gchar *name);
-gchar *msim_msg_get_string(MsimMessage *msg, gchar *name);
-guint msim_msg_get_integer(MsimMessage *msg, gchar *name);
-gboolean msim_msg_get_binary(MsimMessage *msg, gchar *name, gchar **binary_data, gsize *binary_length);
+MsimMessageElement *msim_msg_get(MsimMessage *msg, const gchar *name);
+gchar *msim_msg_get_string(MsimMessage *msg, const gchar *name);
+guint msim_msg_get_integer(MsimMessage *msg, const gchar *name);
+gboolean msim_msg_get_binary(MsimMessage *msg, const gchar *name, gchar **binary_data, gsize *binary_length);
 
 #endif /* _MYSPACE_MESSAGE_H */
--- a/libpurple/protocols/myspace/myspace.c	Thu Jun 14 06:06:56 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Thu Jun 14 08:18:59 2007 +0000
@@ -107,7 +107,7 @@
  */
 const gchar *msim_list_icon(PurpleAccount *acct, PurpleBuddy *buddy)
 {
-    /* Use a MySpace icon submitted by hbons submitted one at
+    /* Use a MySpace icon submitted by hbons at
      * http://developer.pidgin.im/wiki/MySpaceIM. */
     return "myspace";
 }
@@ -161,8 +161,8 @@
  */
 gchar *str_replace(const gchar *str, const gchar *old, const gchar *new)
 {
-	char **items;
-	char *ret;
+	gchar **items;
+	gchar *ret;
 
 	items = g_strsplit(str, old, -1);
 	ret = g_strjoinv(new, items);
@@ -176,7 +176,7 @@
 #ifdef MSIM_DEBUG_MSG
 void print_hash_item(gpointer key, gpointer value, gpointer user_data)
 {
-    purple_debug_info("msim", "%s=%s\n", (char *)key, (char *)value);
+    purple_debug_info("msim", "%s=%s\n", (gchar *)key, (gchar *)value);
 }
 #endif
 
@@ -229,7 +229,7 @@
 void msim_login(PurpleAccount *acct)
 {
     PurpleConnection *gc;
-    const char *host;
+    const gchar *host;
     int port;
 
     g_return_if_fail(acct != NULL);
@@ -272,7 +272,7 @@
 gboolean msim_login_challenge(MsimSession *session, MsimMessage *msg) 
 {
     PurpleAccount *account;
-    gchar *response;
+    const gchar *response;
 	guint response_len;
 	gchar *nc;
 	gsize nc_len;
@@ -360,23 +360,23 @@
 */
 
 void crypt_rc4_init(rc4_state_struct *rc4_state, 
-		    const unsigned char *key, int key_len)
+		    const guchar *key, int key_len)
 {
   int ind;
-  unsigned char j = 0;
-  unsigned char *s_box;
+  unsigned gchar j = 0;
+  unsigned gchar *s_box;
 
   memset(rc4_state, 0, sizeof(rc4_state_struct));
   s_box = rc4_state->s_box;
   
   for (ind = 0; ind < 256; ind++)
   {
-    s_box[ind] = (unsigned char)ind;
+    s_box[ind] = (guchar)ind;
   }
 
   for( ind = 0; ind < 256; ind++)
   {
-     unsigned char tc;
+     guchar tc;
 
      j += (s_box[ind] + key[ind%key_len]);
 
@@ -387,11 +387,11 @@
 
 }
 
-void crypt_rc4(rc4_state_struct *rc4_state, unsigned char *data, int data_len)
+void crypt_rc4(rc4_state_struct *rc4_state, guchar *data, int data_len)
 {
-  unsigned char *s_box;
-  unsigned char index_i;
-  unsigned char index_j;
+  guchar *s_box;
+  guchar index_i;
+  guchar index_j;
   int ind;
 
   /* retrieve current state from the state struct (so we can resume where
@@ -402,8 +402,8 @@
 
   for( ind = 0; ind < data_len; ind++)
   {
-    unsigned char tc;
-    unsigned char t;
+    guchar tc;
+    guchar t;
 
     index_i++;
     index_j += s_box[index_i];
@@ -435,8 +435,8 @@
  * @return Binary login challenge response, ready to send to the server. Must be g_free()'d
  *         when finished.
  */
-gchar *msim_compute_login_response(gchar nonce[2 * NONCE_SIZE], 
-		gchar *email, gchar *password, guint *response_len)
+const gchar *msim_compute_login_response(const gchar nonce[2 * NONCE_SIZE], 
+		const gchar *email, const gchar *password, guint *response_len)
 {
     PurpleCipherContext *key_context;
     PurpleCipher *sha1;
@@ -551,7 +551,7 @@
 
 	*response_len = data_out_len;
 
-    return (gchar *)data_out;
+    return (const gchar *)data_out;
 }
 
 /**
@@ -568,8 +568,8 @@
  * a username or email address is given, the userid must be looked up.
  * This function does that by calling msim_postprocess_outgoing().
  */
-int msim_send_im(PurpleConnection *gc, const char *who,
-                            const char *message, PurpleMessageFlags flags)
+int msim_send_im(PurpleConnection *gc, const gchar *who,
+                            const gchar *message, PurpleMessageFlags flags)
 {
     MsimSession *session;
     
@@ -581,8 +581,7 @@
 
 	session = gc->proto_data;
 
-	/* TODO: const-correctness */
-	if (msim_send_bm(session, (char *)who, (char *)message, MSIM_BM_INSTANT))
+	if (msim_send_bm(session, who, message, MSIM_BM_INSTANT))
 	{
 		/* Return 1 to have Purple show this IM as being sent, 0 to not. I always
 		 * return 1 even if the message could not be sent, since I don't know if
@@ -616,11 +615,13 @@
  *
  * Buddy messages ('bm') include instant messages, action messages, status messages, etc.
  */
-gboolean msim_send_bm(MsimSession *session, gchar *who, gchar *text, int type)
+gboolean msim_send_bm(MsimSession *session, const gchar *who, const gchar *text, int type)
 {
 	gboolean rc;
 	MsimMessage *msg;
-    const char *from_username = session->account->username;
+    const gchar *from_username;
+   
+	from_username = session->account->username;
 
     purple_debug_info("msim", "sending %d message from %s to %s: %s\n",
                   type, from_username, who, text);
@@ -633,7 +634,7 @@
 			"msg", MSIM_TYPE_STRING, g_strdup(text),
 			NULL);
 
-	rc = msim_postprocess_outgoing(session, msg, (char *)who, "t", "cv");
+	rc = msim_postprocess_outgoing(session, msg, who, "t", "cv");
 
 	msim_msg_free(msg);
 
@@ -714,9 +715,9 @@
  * @param state PURPLE_TYPING, PURPLE_TYPED, PURPLE_NOT_TYPING
  *
  */
-unsigned int msim_send_typing(PurpleConnection *gc, const char *name, PurpleTypingState state)
+unsigned int msim_send_typing(PurpleConnection *gc, const gchar *name, PurpleTypingState state)
 {
-	char *typing_str;
+	const gchar *typing_str;
 	MsimSession *session;
 
 	session = (MsimSession *)gc->proto_data;
@@ -735,12 +736,12 @@
 	}
 
 	purple_debug_info("msim", "msim_send_typing(%s): %d (%s)\n", name, state, typing_str);
-	msim_send_bm(session, (gchar *)name, typing_str, MSIM_BM_ACTION);
+	msim_send_bm(session, name, typing_str, MSIM_BM_ACTION);
 	return 0;
 }
 
 /** Retrieve a user's profile. */
-void msim_get_info(PurpleConnection *gc, const char *name)
+void msim_get_info(PurpleConnection *gc, const gchar *name)
 {
 	PurpleNotifyUserInfo *user_info;
 	PurpleBuddy *buddy;
@@ -1383,7 +1384,7 @@
  *
  * Does not handle sending, or scheduling userid lookup. For that, see msim_postprocess_outgoing().
  */ 
-MsimMessage *msim_do_postprocessing(MsimMessage *msg, gchar *uid_before, gchar *uid_field_name, guint uid)
+MsimMessage *msim_do_postprocessing(MsimMessage *msg, const gchar *uid_before, const gchar *uid_field_name, guint uid)
 {	
 	purple_debug_info("msim", "msim_do_postprocessing called with ufn=%s, ub=%s, uid=%d\n",
 			uid_field_name, uid_before, uid);
@@ -1485,8 +1486,8 @@
  *
  * @return Postprocessed message.
  */
-gboolean msim_postprocess_outgoing(MsimSession *session, MsimMessage *msg, gchar *username, 
-	gchar *uid_field_name, gchar *uid_before)
+gboolean msim_postprocess_outgoing(MsimSession *session, MsimMessage *msg, const gchar *username, 
+	const gchar *uid_field_name, const gchar *uid_before)
 {
     PurpleBuddy *buddy;
 	guint uid;
@@ -1984,13 +1985,13 @@
  *
  * @param buddy The buddy to obtain status text for.
  *
- * @return Status text, or NULL if error.
+ * @return Status text, or NULL if error. Caller g_free()'s.
  *
  */
 char *msim_status_text(PurpleBuddy *buddy)
 {
     MsimSession *session;
-	gchar *display_name;
+	const gchar *display_name;
 
     g_return_val_if_fail(buddy != NULL, NULL);
 
@@ -1999,7 +2000,7 @@
 
 	/* TODO: const correctness */
 	/* TODO: show Headline, or DisplayName, or selectable, or both? */
-	display_name = (gchar *)purple_blist_node_get_string(&buddy->node, "DisplayName");
+	display_name = purple_blist_node_get_string(&buddy->node, "DisplayName");
 
 	if (display_name)
 	{
--- a/libpurple/protocols/myspace/myspace.h	Thu Jun 14 06:06:56 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.h	Thu Jun 14 08:18:59 2007 +0000
@@ -150,20 +150,20 @@
 
 void msim_login(PurpleAccount *acct);
 gboolean msim_login_challenge(MsimSession *session, MsimMessage *msg);
-gchar *msim_compute_login_response(gchar nonce[2 * NONCE_SIZE],
-		        gchar *email, gchar *password, guint *response_len);
+const gchar *msim_compute_login_response(const gchar nonce[2 * NONCE_SIZE],
+		        const gchar *email, const gchar *password, guint *response_len);
 
 
-int msim_send_im(PurpleConnection *gc, const char *who, const char *message, 
+int msim_send_im(PurpleConnection *gc, const gchar *who, const gchar *message, 
 	PurpleMessageFlags flags);
-gboolean msim_send_bm(MsimSession *session, gchar *who, gchar *text, int type);
+gboolean msim_send_bm(MsimSession *session, const gchar *who, const gchar *text, int type);
 void msim_send_im_cb(MsimSession *session, MsimMessage *userinfo, gpointer data);
 
 int msim_incoming_im(MsimSession *session, MsimMessage *msg);
 int msim_incoming_action(MsimSession *session, MsimMessage *msg);
 
-unsigned int msim_send_typing(PurpleConnection *gc, const char *name, PurpleTypingState state);
-void msim_get_info(PurpleConnection *gc, const char *name);
+unsigned int msim_send_typing(PurpleConnection *gc, const gchar *name, PurpleTypingState state);
+void msim_get_info(PurpleConnection *gc, const gchar *name);
 
 void msim_store_buddy_info_each(gpointer key, gpointer value, gpointer user_data);
 gboolean msim_store_buddy_info(MsimSession *session, MsimMessage *msg);
@@ -173,10 +173,10 @@
 
 gboolean msim_process(MsimSession *session, MsimMessage *msg);
 
-MsimMessage *msim_do_postprocessing(MsimMessage *msg, gchar *uid_field_name, gchar *uid_before, guint uid);
+MsimMessage *msim_do_postprocessing(MsimMessage *msg, const gchar *uid_field_name, const gchar *uid_before, guint uid);
 void msim_postprocess_outgoing_cb(MsimSession *session, MsimMessage *userinfo, gpointer data);
-gboolean msim_postprocess_outgoing(MsimSession *session, MsimMessage *msg, gchar *username, 
-	gchar *uid_field_name, gchar *uid_before);
+gboolean msim_postprocess_outgoing(MsimSession *session, MsimMessage *msg, const gchar *username, 
+	const gchar *uid_field_name, const gchar *uid_before);
 
 
 gboolean msim_error(MsimSession *session, MsimMessage *msg);
@@ -239,15 +239,15 @@
 */
 
 typedef struct _rc4_state_struct {
-  unsigned char s_box[256];
-  unsigned char index_i;
-  unsigned char index_j;
+  guchar s_box[256];
+  guchar index_i;
+  guchar index_j;
 } rc4_state_struct;
 
 void crypt_rc4_init(rc4_state_struct *rc4_state,
-            const unsigned char *key, int key_len);
+            const guchar *key, int key_len);
 
-void crypt_rc4(rc4_state_struct *rc4_state, unsigned char *data, int data_len);
+void crypt_rc4(rc4_state_struct *rc4_state, guchar *data, int data_len);
 #endif	/* !MSIM_USE_PURPLE_RC4 */
 
 #endif /* !_MYSPACE_MYSPACE_H */