Sun, 06 Aug 2006 16:20:39 +0000
[gaim-migrate @ 16654]
can show the Photo info sucessfully!
committed by MaYuan<mayuan2006@gmail.com>
committer: Ethan Blanton <elb@pidgin.im>
| 8810 | 1 | /** |
| 2 | * @file command.c MSN command functions | |
| 3 | * | |
| 4 | * gaim | |
| 5 | * | |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
6 | * Gaim is the legal property of its developers, whose names are too numerous |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
7 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
8 | * source distribution. |
| 8810 | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify | |
| 11 | * it under the terms of the GNU General Public License as published by | |
| 12 | * the Free Software Foundation; either version 2 of the License, or | |
| 13 | * (at your option) any later version. | |
| 14 | * | |
| 15 | * This program is distributed in the hope that it will be useful, | |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 | * GNU General Public License for more details. | |
| 19 | * | |
| 20 | * You should have received a copy of the GNU General Public License | |
| 21 | * along with this program; if not, write to the Free Software | |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 23 | */ | |
| 24 | #include "msn.h" | |
| 25 | #include "command.h" | |
| 26 | ||
|
11897
10853b830964
[gaim-migrate @ 14188]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9198
diff
changeset
|
27 | static gboolean |
| 8810 | 28 | is_num(char *str) |
| 29 | { | |
| 30 | char *c; | |
| 31 | for (c = str; *c; c++) { | |
| 32 | if (!(g_ascii_isdigit(*c))) | |
| 33 | return FALSE; | |
| 34 | } | |
| 35 | ||
| 36 | return TRUE; | |
| 37 | } | |
| 38 | ||
| 13853 | 39 | /* |
| 40 | * check the command is the command with payload content | |
| 41 | * if it is return TRUE | |
| 42 | * else return FALSE | |
| 43 | */ | |
| 44 | static gboolean | |
| 13854 | 45 | msn_check_payload_cmd(char *str) |
| 13853 | 46 | { |
| 47 | if( (!strcmp(str,"ADL")) || | |
| 48 | (!strcmp(str,"GCF")) || | |
| 13856 | 49 | (!strcmp(str,"SG")) || |
| 13853 | 50 | (!strcmp(str,"MSG")) || |
| 51 | (!strcmp(str,"RML")) || | |
| 52 | (!strcmp(str,"UBX")) || | |
| 53 | (!strcmp(str,"UBN")) || | |
| 54 | (!strcmp(str,"UUN")) || | |
| 55 | (!strcmp(str,"UUX"))){ | |
| 56 | return TRUE; | |
| 57 | } | |
| 58 | ||
| 59 | return FALSE; | |
| 60 | } | |
| 61 | ||
| 62 | /*get the payload positon*/ | |
| 13854 | 63 | int msn_get_payload_position(char *str) |
| 13853 | 64 | { |
| 65 | /*because MSG has "MSG hotmail hotmail [payload length]"*/ | |
| 13856 | 66 | if(!(strcmp(str,"MSG"))|| (!strcmp(str,"UBX")) ){ |
| 13853 | 67 | return 2; |
| 68 | } | |
| 13856 | 69 | |
| 13853 | 70 | return 1; |
| 71 | } | |
| 13856 | 72 | |
| 13853 | 73 | /* |
| 74 | * set command Payload length | |
| 75 | */ | |
| 76 | int | |
| 13854 | 77 | msn_set_payload_len(MsnCommand *cmd) |
| 13853 | 78 | { |
| 79 | char * param; | |
| 80 | ||
| 13854 | 81 | if(msn_check_payload_cmd(cmd->command)){ |
| 13856 | 82 | param = cmd->params[msn_get_payload_position(cmd->command)]; |
| 83 | #if 0 | |
| 13853 | 84 | if(!(strcmp(cmd->command,"MSG"))){ |
| 85 | param = cmd->params[2]; | |
| 86 | }else{ | |
| 87 | param = cmd->params[1]; | |
| 88 | } | |
| 13856 | 89 | #endif |
| 13853 | 90 | cmd->payload_len = is_num(param) ? atoi(param) : 0; |
| 91 | }else{ | |
| 92 | cmd->payload_len = 0; | |
| 93 | } | |
| 94 | return 0; | |
| 95 | } | |
| 96 | ||
| 8810 | 97 | MsnCommand * |
| 98 | msn_command_from_string(const char *string) | |
| 99 | { | |
| 100 | MsnCommand *cmd; | |
| 101 | char *tmp; | |
| 102 | char *param_start; | |
| 13853 | 103 | char *param; |
| 104 | int c; | |
| 8810 | 105 | |
| 106 | g_return_val_if_fail(string != NULL, NULL); | |
| 107 | ||
| 108 | tmp = g_strdup(string); | |
| 109 | param_start = strchr(tmp, ' '); | |
| 110 | ||
| 111 | cmd = g_new0(MsnCommand, 1); | |
| 112 | cmd->command = tmp; | |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
113 | |
| 13853 | 114 | if (param_start){ |
| 8810 | 115 | *param_start++ = '\0'; |
| 116 | cmd->params = g_strsplit(param_start, " ", 0); | |
| 117 | ||
| 118 | for (c = 0; cmd->params[c]; c++); | |
| 119 | cmd->param_count = c; | |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
120 | |
| 8810 | 121 | param = cmd->params[0]; |
| 122 | ||
| 123 | cmd->trId = is_num(param) ? atoi(param) : 0; | |
| 13853 | 124 | }else{ |
| 125 | cmd->trId = 0; | |
| 8810 | 126 | } |
| 13853 | 127 | |
| 128 | /*add payload Length checking*/ | |
| 13854 | 129 | msn_set_payload_len(cmd); |
| 13853 | 130 | gaim_debug_info("MaYuan","get payload len:%d\n",cmd->payload_len); |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
131 | |
| 8810 | 132 | msn_command_ref(cmd); |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
133 | |
| 8810 | 134 | return cmd; |
| 135 | } | |
| 136 | ||
| 137 | void | |
| 138 | msn_command_destroy(MsnCommand *cmd) | |
| 139 | { | |
| 140 | g_return_if_fail(cmd != NULL); | |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
141 | |
| 8810 | 142 | if (cmd->ref_count > 0) |
| 143 | { | |
| 144 | msn_command_unref(cmd); | |
| 145 | return; | |
| 146 | } | |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
147 | |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
148 | if (cmd->payload != NULL) |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
149 | g_free(cmd->payload); |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
150 | |
| 8810 | 151 | g_free(cmd->command); |
| 152 | g_strfreev(cmd->params); | |
| 153 | g_free(cmd); | |
| 154 | } | |
| 155 | ||
| 156 | MsnCommand * | |
| 157 | msn_command_ref(MsnCommand *cmd) | |
| 158 | { | |
| 159 | g_return_val_if_fail(cmd != NULL, NULL); | |
| 160 | ||
| 161 | cmd->ref_count++; | |
| 162 | return cmd; | |
| 163 | } | |
| 164 | ||
| 165 | MsnCommand * | |
| 166 | msn_command_unref(MsnCommand *cmd) | |
| 167 | { | |
| 168 | g_return_val_if_fail(cmd != NULL, NULL); | |
|
12250
5b14301dd1ec
[gaim-migrate @ 14552]
Richard Laager <rlaager@pidgin.im>
parents:
11897
diff
changeset
|
169 | g_return_val_if_fail(cmd->ref_count > 0, NULL); |
| 8810 | 170 | |
| 171 | cmd->ref_count--; | |
| 172 | ||
| 173 | if (cmd->ref_count == 0) | |
| 174 | { | |
| 175 | msn_command_destroy(cmd); | |
| 176 | return NULL; | |
| 177 | } | |
| 178 | ||
| 179 | return cmd; | |
| 180 | } |