Mercurial > pidgin.yaz
comparison libpurple/protocols/msn/state.c @ 20506:42365ba802c0
Improve the current-media parsing a little bit.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 15 Sep 2007 11:34:39 +0000 |
parents | 7f5564ebde7f |
children | 1553c95055e3 |
comparison
equal
deleted
inserted
replaced
20505:909af554e239 | 20506:42365ba802c0 |
---|---|
85 /* parse CurrentMedia string */ | 85 /* parse CurrentMedia string */ |
86 char * | 86 char * |
87 msn_parse_currentmedia(const char *cmedia) | 87 msn_parse_currentmedia(const char *cmedia) |
88 { | 88 { |
89 char **cmedia_array; | 89 char **cmedia_array; |
90 char *buffer=NULL, *inptr, *outptr, *tmpptr; | 90 char *inptr, *tmpptr; |
91 int length, strings, tmp; | 91 GString *buffer; |
92 | 92 int strings, tmp; |
93 if((cmedia == NULL) || (*cmedia == '\0')) { | 93 |
94 if ((cmedia == NULL) || (*cmedia == '\0')) { | |
94 purple_debug_info("msn", "No currentmedia string\n"); | 95 purple_debug_info("msn", "No currentmedia string\n"); |
95 return NULL; | 96 return NULL; |
96 } | 97 } |
97 | 98 |
98 purple_debug_info("msn", "Parsing currentmedia string: \"%s\"\n", cmedia); | 99 purple_debug_info("msn", "Parsing currentmedia string: \"%s\"\n", cmedia); |
99 | 100 |
100 cmedia_array=g_strsplit(cmedia, "\\0", 0); | 101 cmedia_array = g_strsplit(cmedia, "\\0", 0); |
101 | 102 |
102 strings=1; /* Skip first empty string */ | 103 strings = 0; |
103 length=5; /* Space for '\0' (1 byte) and prefix (4 bytes) */ | 104 while (strcmp(cmedia_array[++strings], "")); /* Yes, we want to skip the first empty string, apparently */ |
104 while(strcmp(cmedia_array[strings], "")) { | 105 |
105 length+= strlen(cmedia_array[strings]); | 106 buffer = g_string_new(NULL); |
106 strings++; | 107 |
107 } | 108 if ((strings > 3) && (!strcmp(cmedia_array[2], "1"))) { /* Check if enabled */ |
108 | 109 inptr = cmedia_array[3]; |
109 if((strings>3) && (!strcmp(cmedia_array[2], "1"))) { /* Check if enabled */ | 110 |
110 | 111 #if 0 |
111 buffer=g_malloc(length); | |
112 | |
113 inptr=cmedia_array[3]; | |
114 outptr=buffer; | |
115 | |
116 if(!strcmp(cmedia_array[1], "Music")) { | 112 if(!strcmp(cmedia_array[1], "Music")) { |
117 strcpy(outptr, "np. "); | 113 /* The music string seems to be of 'Title - Artist' form. */ |
118 outptr+=4; | 114 } else if(!strcmp(cmedia_array[1], "Games")) { |
119 }/* else if(!strcmp(cmedia_array[1], "Games")) { | |
120 } else if(!strcmp(cmedia_array[1], "Office")) { | 115 } else if(!strcmp(cmedia_array[1], "Office")) { |
121 }*/ | 116 } |
122 | 117 #endif |
123 while(*inptr!='\0') { | 118 |
124 if((*inptr == '{') && (strlen(inptr) > 2) && (*(inptr+2) == '}') ) { | 119 while (*inptr!='\0') { |
120 if ((*inptr == '{') && (strlen(inptr) > 2) && (*(inptr+2) == '}')) { | |
125 errno = 0; | 121 errno = 0; |
126 tmp = strtol(inptr+1,&tmpptr,10); | 122 tmp = strtol(inptr+1,&tmpptr,10); |
127 if( (errno!=0) || (tmpptr == (inptr+1)) || | 123 if(errno == 0 && tmpptr != inptr + 1 && |
128 ((tmp+5)>(strings)) ) { | 124 tmp + 4 < strings) { |
129 *outptr = *inptr; /* Conversion not successful */ | 125 /* Replace {?} tag with appropriate text only when successful. |
130 outptr++; | 126 * Skip otherwise. */ |
131 } else { | 127 buffer = g_string_append(buffer, cmedia_array[tmp + 4]); |
132 /* Replace {?} tag with appropriate text */ | |
133 strcpy(outptr, cmedia_array[tmp+4]); | |
134 outptr+=strlen(cmedia_array[tmp+4]); | |
135 inptr+=2; | |
136 } | 128 } |
129 inptr += 3; /* Skip to the next char after '}' */ | |
137 } else { | 130 } else { |
138 *outptr = *inptr; | 131 buffer = g_string_append_c(buffer, *inptr++); |
139 outptr++; | |
140 } | 132 } |
141 inptr++; | |
142 } | 133 } |
143 *outptr='\0'; | |
144 purple_debug_info("msn", "Parsed currentmedia string, result: \"%s\"\n", | 134 purple_debug_info("msn", "Parsed currentmedia string, result: \"%s\"\n", |
145 buffer); | 135 buffer); |
146 } else { | 136 } else { |
147 purple_debug_info("msn", "Current media marked disabled, not parsing\n"); | 137 purple_debug_info("msn", "Current media marked disabled, not parsing\n"); |
148 } | 138 } |
149 | 139 |
150 g_strfreev(cmedia_array); | 140 g_strfreev(cmedia_array); |
151 return buffer; | 141 return g_string_free(buffer, FALSE); |
152 } | 142 } |
153 | 143 |
154 /* get the CurrentMedia info from the XML string */ | 144 /* get the CurrentMedia info from the XML string */ |
155 char * | 145 char * |
156 msn_get_currentmedia(char *xml_str, gsize len) | 146 msn_get_currentmedia(char *xml_str, gsize len) |