changeset 17343:58b4d103a5b8

Use symbolic constants for persist messages.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sat, 02 Jun 2007 04:45:59 +0000
parents 4f54e8c41086
children 5f96fcbd627a
files libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/myspace.h libpurple/protocols/myspace/persist.h
diffstat 3 files changed, 96 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/myspace.c	Sat Jun 02 03:26:06 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Sat Jun 02 04:45:59 2007 +0000
@@ -34,6 +34,7 @@
 #define PURPLE_PLUGIN
 
 #include "message.h"
+#include "persist.h"
 #include "myspace.h"
 
 /** 
@@ -886,7 +887,8 @@
         username = g_hash_table_lookup(body, "UserName");
         if (username)
         {
-			/* TODO: permanently associated with blist item, if in buddy in blist */
+			/* TODO: permanently associated with blist item, if in buddy in blist,
+			 * See purple_blist_node_set_int(). */
             g_hash_table_insert(session->user_lookup_cache, g_strdup(username), body);
         } else {
             purple_debug_info("msim", 
@@ -1409,22 +1411,21 @@
 
     /* Send request */
 
-    cmd = 1;
+    cmd = MSIM_CMD_GET;
 
     if (msim_is_userid(user))
     {
-        /* TODO: document cmd,dsn,lid */
         field_name = "UserID";
-        dsn = 4;
-        lid = 3;
+        dsn = MG_MYSPACE_INFO_BY_ID_DSN; 
+        lid = MG_MYSPACE_INFO_BY_ID_LID; 
     } else if (msim_is_email(user)) {
         field_name = "Email";
-        dsn = 5;
-        lid = 7;
+        dsn = MG_MYSPACE_INFO_BY_STRING_DSN;
+        lid = MG_MYSPACE_INFO_BY_STRING_LID;
     } else {
         field_name = "UserName";
-        dsn = 5;
-        lid = 7;
+        dsn = MG_MYSPACE_INFO_BY_STRING_DSN;
+        lid = MG_MYSPACE_INFO_BY_STRING_LID;
     }
 
 
--- a/libpurple/protocols/myspace/myspace.h	Sat Jun 02 03:26:06 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.h	Sat Jun 02 04:45:59 2007 +0000
@@ -1,6 +1,4 @@
-/* MySpaceIM Protocol Plugin, headr file
- *
- * \author Jeff Connelly
+/* MySpaceIM Protocol Plugin, header file
  *
  * Copyright (C) 2007, Jeff Connelly <jeff2@homing.pidgin.im>
  *
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/protocols/myspace/persist.h	Sat Jun 02 04:45:59 2007 +0000
@@ -0,0 +1,85 @@
+/* MySpaceIM Protocol Plugin, persist commands
+ *
+ * Copyright (C) 2007, Jeff Connelly <jeff2@homing.pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _MYSPACE_PERSIST_H
+#define _MYSPACE_PERSIST_H
+
+/** Command codes */
+#define MSIM_CMD_GET			1
+#define MSIM_CMD_PUT			2
+#define MSIM_CMD_DELETE			3
+
+/** Command bit fields */
+#define MSIM_CMD_BIT_CODE		255			/*< Bits specifying command code */
+#define MSIM_CMD_BIT_REPLY		256			/**< 1=reply, 0=request */
+#define MSIM_CMD_BIT_ACTION		512			/**< 1=action, 0=information */
+#define MSIM_CMD_BIT_ERROR		1024		/**< 1=error, 0=normal */
+
+/** Macros to read cmd bitfield. */
+#define MSIM_CMD_GET_CODE(x)	 (x & MSIM_CMD_BIT_CODE)
+#define MSIM_CMD_IS_REPLY(x)	 (x & MSIM_CMD_BIT_REPLY)
+#define MSIM_CMD_IS_REQUEST(x)	!(x & MSIM_CMD_BIT_REPLY)
+#define MSIM_CMD_IS_ACTION(x)	 (x & MSIM_CMD_BIT_ACTION)
+#define MSIM_CMD_IS_INFO(x)		!(x & MSIM_CMD_BIT_ACTION)
+#define MSIM_CMD_IS_ERROR(x)	 (x & MSIM_CMD_BIT_ERROR)
+#define MSIM_CMD_IS_NORMAL(x)	!(x & MSIM_CMD_BIT_ERROR)
+
+/** Define a set of _DSN and _LID constants for a persistance request. */
+#define MSIM_PERSIST_DSN_LID(name,dsn,lid) 			\
+	const int name##_DSN = dsn;						\
+	const int name##_LID = lid;						
+
+/* Can't do this, errors:
+ * 	persist.h:51:3: error: '#' is not followed by a macro parameter
+ *  In file included from myspace.c:37:
+ *  persist.h:56: error: expected ')' before numeric constant
+ * So instead, I define const ints above.
+#define MSIM_PERSIST_DSN_LID(name,dsn,lid) 			\
+	#define name##_DSN		dsn						\
+	#define name##_LID		lid
+#endif
+*/
+
+/** Messages to Get information */
+MSIM_PERSIST_DSN_LID(MG_LIST_ALL_CONTACTS, 		0, 1)
+MSIM_PERSIST_DSN_LID(MG_USER_INFO_BY_ID, 		0, 2)
+MSIM_PERSIST_DSN_LID(MG_IM_INFO_BY_ID, 			1, 17)
+MSIM_PERSIST_DSN_LID(MG_LIST_ALL_GROUPS,		2, 6)
+MSIM_PERSIST_DSN_LID(MG_MYSPACE_INFO_BY_ID, 	4, 3)
+MSIM_PERSIST_DSN_LID(MG_YOUR_MYSPACE_INFO,  	4, 5)
+MSIM_PERSIST_DSN_LID(MG_MYSPACE_INFO_BY_STRING, 5, 7)
+MSIM_PERSIST_DSN_LID(MG_CHECK_MAIL,				7, 18)
+MSIM_PERSIST_DSN_LID(MG_WEB_CHALLENGE,			17, 26)
+MSIM_PERSIST_DSN_LID(MG_USER_SONG,				21, 28)
+MSIM_PERSIST_DSN_LID(MG_SERVER_INFO,			101, 20)
+
+/** Messages to Change/send information */
+MSIM_PERSIST_DSN_LID(MC_USER_PREFERENCES,		1, 10)
+MSIM_PERSIST_DSN_LID(MC_CONTACT_INFO,			0, 9)
+MSIM_PERSIST_DSN_LID(MC_INVITE,					16, 25)
+
+/** Error codes */
+#define MERR_PARSE					1
+#define MERR_NOT_LOGGED_IN			2
+#define MERR_ANOTHER_LOGIN			6
+#define MERR_BAD_EMAIL				259
+#define MERR_BAD_PASSWORD			260
+#define MERR_BAD_UID_IN_PERSISTR	4352
+
+#endif /* !_MYSPACE_PERSIST_H */