# HG changeset patch # User andrew.victor@mxit.com # Date 1303161633 0 # Node ID 000aac6e42fe7c5b0b02e1de597cf689c2803aa9 # Parent 6b59dd656feedee5053b54fd52556624e030046d Start on Gaming & Table markup. diff -r 6b59dd656fee -r 000aac6e42fe libpurple/protocols/mxit/formcmds.c --- a/libpurple/protocols/mxit/formcmds.c Mon Apr 18 19:38:53 2011 +0000 +++ b/libpurple/protocols/mxit/formcmds.c Mon Apr 18 21:20:33 2011 +0000 @@ -54,6 +54,15 @@ MXIT_CMD_TABLE /* Table (tbl) */ } MXitCommandType; +/* Chat-screen behaviours (bhvr) */ +#define SCREEN_NO_HEADINGS 0x01 +#define SCREEN_FULLSCREEN 0x02 +#define SCREEN_AUTOCLEAR 0x04 +#define SCREEN_NO_AUDIO 0x08 +#define SCREEN_NO_MSGPREFIX 0x10 +#define SCREEN_NOTIFY 0x20 +#define SCREEN_PROGRESSBAR 0x40 + /* * object for an inline image request with an URL @@ -281,6 +290,7 @@ /*------------------------------------------------------------------------ * Process a PlatformRequest MXit command. + * [::op=cmd|type=platreq|selmsg=Upgrade MXit|dest=http%3a//m.mxit.com|id=12345:] * * @param hash The MXit command map * @param msg The message to display (as generated so far) @@ -369,6 +379,173 @@ /*------------------------------------------------------------------------ + * Process an Imagestrip MXit command. + * [::op=is|nm=status|dat=iVBORw0KGgoAAAA%3d%3d|v=63398792426788|fw=8|fh=8|layer=0:] + * + * @param from The sender of the message. + * @param hash The MXit command map + */ +static void command_imagestrip(struct MXitSession* session, const char* from, GHashTable* hash) +{ + const char* name; + const char* validator; + const char* tmp; + int width, height, layer; + + purple_debug_info(MXIT_PLUGIN_ID, "ImageStrip received from %s\n", from); + + /* image strip name */ + name = g_hash_table_lookup(hash, "nm"); + + /* validator */ + validator = g_hash_table_lookup(hash, "v"); + + /* image data */ + tmp = g_hash_table_lookup(hash, "dat"); + if (tmp) { + guchar* rawimg; + gsize rawimglen; + char* dir; + char* filename; + + /* base64 decode the image data */ + rawimg = purple_base64_decode(tmp, &rawimglen); + + /* save it to a file */ + dir = g_strdup_printf("%s/mxit/imagestrips", purple_user_dir()); + purple_build_dir(dir, S_IRUSR | S_IWUSR | S_IXUSR); /* ensure directory exists */ + + filename = g_strdup_printf("%s/%s-%s-%s.png", dir, from, name, validator); + purple_util_write_data_to_file_absolute(filename, (char*) rawimg, rawimglen); + + g_free(dir); + g_free(filename); + } + + tmp = g_hash_table_lookup(hash, "fw"); + width = atoi(tmp); + + tmp = g_hash_table_lookup(hash, "fh"); + height = atoi(tmp); + + tmp = g_hash_table_lookup(hash, "layer"); + layer = atoi(tmp); + + purple_debug_info(MXIT_PLUGIN_ID, "ImageStrip %s from %s: [w=%i h=%i l=%i validator=%s]\n", name, from, width, height, layer, validator); +} + + +/*------------------------------------------------------------------------ + * Process a Chat-Screen-Info MXit command. + * [::op=csi:] + * + * @param session The MXit session object + * @param from The sender of the message. + */ +static void command_screeninfo(struct MXitSession* session, const char* from) +{ + char* response; + + purple_debug_info(MXIT_PLUGIN_ID, "Chat Screen Info received from %s\n", from); + + // TODO: Determine width, height, colors of chat-screen. + + response = g_strdup_printf("::type=csi|res=bhvr,0;w,%i;h,%i;col,0.ffffffff,29.ff000000:", 300, 400); + + /* send response back to MXit */ + mxit_send_message( session, from, response, FALSE, TRUE ); + + g_free(response); +} + + +/*------------------------------------------------------------------------ + * Process a Chat-Screen-Configure MXit command. + * [::op=csc|bhvr=|menu=|col=:] + * where: + * menu ::= { ";" } + * menuitem ::= { type "," "," "," } + * colors ::= { ";" } + * color ::= "," + * + * @param session The MXit session object + * @param from The sender of the message. + * @param hash The MXit command map + */ +static void command_screenconfig(struct MXitSession* session, const char* from, GHashTable* hash) +{ + const char* tmp; + + purple_debug_info(MXIT_PLUGIN_ID, "Chat Screen Configure received from %s\n", from); + + /* Behaviour */ + tmp = g_hash_table_lookup(hash, "bhvr"); + if (tmp) { + purple_debug_info(MXIT_PLUGIN_ID, " behaviour = %s\n", tmp); + // TODO: Re-configure conversation screen. + } + + /* Menu */ + tmp = g_hash_table_lookup(hash, "menu"); + if (tmp) { + purple_debug_info(MXIT_PLUGIN_ID, " menu = %s\n", tmp); + // TODO: Implement conversation-specific sub-menu. + } + + /* Colours */ + tmp = g_hash_table_lookup(hash, "col"); + if (tmp) { + purple_debug_info(MXIT_PLUGIN_ID, " colours = %s\n", tmp); + // TODO: Re-configuration conversation colors. + } +} + + +/*------------------------------------------------------------------------ + * Process a Table Markup MXit command. + * + * @param mx The received message data object + * @param hash The MXit command map + */ +static void command_table(struct RXMsgData* mx, GHashTable* hash) +{ + const char* tmp; + const char* name; + int mode; + int nr_columns = 0, nr_rows = 0; + gchar** coldata; + int i, j; + + /* table name */ + name = g_hash_table_lookup(hash, "nm"); + + /* number of columns */ + tmp = g_hash_table_lookup(hash, "col"); + nr_columns = atoi(tmp); + + /* number of rows */ + tmp = g_hash_table_lookup(hash, "row"); + nr_rows = atoi(tmp); + + /* mode */ + tmp = g_hash_table_lookup(hash, "mode"); + mode = atoi(tmp); + + /* table data */ + tmp = g_hash_table_lookup(hash, "d"); + coldata = g_strsplit(tmp, "~", 0); /* split into entries for each row & column */ + + purple_debug_info(MXIT_PLUGIN_ID, "Table %s from %s: [cols=%i rows=%i mode=%i]\n", name, mx->from, nr_columns, nr_rows, mode); + + for (i = 0; i < nr_rows; i++) { + for (j = 0; j < nr_columns; j++) { + purple_debug_info(MXIT_PLUGIN_ID, " Row %i Column %i = %s\n", i, j, coldata[i*nr_columns + j]); + } + } +} + + +/*------------------------------------------------------------------------ * Process a received MXit Command message. * * @param mx The received message data object @@ -410,6 +587,18 @@ case MXIT_CMD_IMAGE : command_image(mx, hash, mx->msg); break; + case MXIT_CMD_SCREENCONFIG : + command_screenconfig(mx->session, mx->from, hash); + break; + case MXIT_CMD_SCREENINFO : + command_screeninfo(mx->session, mx->from); + break; + case MXIT_CMD_IMAGESTRIP : + command_imagestrip(mx->session, mx->from, hash); + break; + case MXIT_CMD_TABLE : + command_table(mx, hash); + break; default : /* command unknown, or not currently supported */ break;