# HG changeset patch # User Richard Laager # Date 1189965169 0 # Node ID 34abe3faeaab0a153695a68ca3f067ba328ca7ed # Parent 1553c95055e385d4a36ee3ee7c4bd7106ba59fe1 Various (untested) changes to the CurrentMedia parsing. This code is a little less pretty than what I wrote, but it also has the advantage of being less clever. It walks the string character-by-character, which may be easier to understand than mine which uses strchr(). diff -r 1553c95055e3 -r 34abe3faeaab libpurple/protocols/msn/state.c --- a/libpurple/protocols/msn/state.c Sat Sep 15 23:53:15 2007 +0000 +++ b/libpurple/protocols/msn/state.c Sun Sep 16 17:52:49 2007 +0000 @@ -46,7 +46,7 @@ * WLM media PSM info build prcedure * * Result can like: - * \0Music\01\0{0} - {1}\0 Song Title\0Song Artist\0Song Album\0\0\ + * \0Music\01\0{0} - {1}\0Song Title\0Song Artist\0Song Album\0\0\ * \0Games\01\0Playing {0}\0Game Name\0\ * \0Office\01\0Office Message\0Office App Name\0" */ @@ -87,9 +87,8 @@ msn_parse_currentmedia(const char *cmedia) { char **cmedia_array; - char *inptr, *tmpptr; GString *buffer = NULL; - int strings, tmp; + int strings; if ((cmedia == NULL) || (*cmedia == '\0')) { purple_debug_info("msn", "No currentmedia string\n"); @@ -101,26 +100,26 @@ cmedia_array = g_strsplit(cmedia, "\\0", 0); strings = 0; - while (strcmp(cmedia_array[++strings], "")); /* Yes, we want to skip the first empty string, apparently */ + /* Yes, we want to skip the first element here, as it is empty due to + * the cmedia string starting with \0 -- see the examples below. + while (cmedia_array[++strings] != NULL); - if ((strings > 3) && (!strcmp(cmedia_array[2], "1"))) { /* Check if enabled */ + /* The cmedia_array[2] field contains a 1 if enabled. */ + if ((strings > 3) && (!strcmp(cmedia_array[2], "1"))) { + char *inptr = cmedia_array[3]; + buffer = g_string_new(NULL); - inptr = cmedia_array[3]; -#if 0 - if(!strcmp(cmedia_array[1], "Music")) { - /* The music string seems to be of 'Title - Artist' form. */ - } else if(!strcmp(cmedia_array[1], "Games")) { - } else if(!strcmp(cmedia_array[1], "Office")) { - } -#endif + while (*inptr != '\0') { + if ((*inptr == '{') && ((*(inptr + 1) != '\0') && (*(inptr+2) == '}')) { + char *tmpptr; + int tmp; - while (*inptr!='\0') { - if ((*inptr == '{') && (strlen(inptr) > 2) && (*(inptr+2) == '}')) { errno = 0; - tmp = strtol(inptr+1,&tmpptr,10); - if(errno == 0 && tmpptr != inptr + 1 && - tmp + 4 < strings) { + tmp = strtol(inptr + 1, &tmpptr, 10); + + if (errno == 0 && tmpptr != inptr + 1 && + tmp + 4 < strings) { /* Replace {?} tag with appropriate text only when successful. * Skip otherwise. */ buffer = g_string_append(buffer, cmedia_array[tmp + 4]); @@ -131,9 +130,9 @@ } } purple_debug_info("msn", "Parsed currentmedia string, result: \"%s\"\n", - buffer); + buffer->str); } else { - purple_debug_info("msn", "Current media marked disabled, not parsing\n"); + purple_debug_info("msn", "Current media marked disabled, not parsing.\n"); } g_strfreev(cmedia_array);