Sun, 15 Apr 2007 04:29:56 +0000
merge of '92409c474659cace8004653f67cb9eba62ef7f93'
and '65485e2ed8a30d703847463db370ef7b61d30049'
| 8810 | 1 | /** |
| 2 | * @file command.c MSN command functions | |
| 3 | * | |
| 15884 | 4 | * purple |
| 8810 | 5 | * |
| 15884 | 6 | * Purple is the legal property of its developers, whose names are too numerous |
|
9198
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 | ||
| 13903 | 27 | /*local Function prototype*/ |
| 28 | int msn_get_payload_position(char *str); | |
| 29 | int msn_set_payload_len(MsnCommand *cmd); | |
| 30 | ||
|
11897
10853b830964
[gaim-migrate @ 14188]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9198
diff
changeset
|
31 | static gboolean |
| 8810 | 32 | is_num(char *str) |
| 33 | { | |
| 34 | char *c; | |
| 35 | for (c = str; *c; c++) { | |
| 36 | if (!(g_ascii_isdigit(*c))) | |
| 37 | return FALSE; | |
| 38 | } | |
| 39 | ||
| 40 | return TRUE; | |
| 41 | } | |
| 42 | ||
| 13853 | 43 | /* |
| 44 | * check the command is the command with payload content | |
| 45 | * if it is return TRUE | |
| 46 | * else return FALSE | |
| 47 | */ | |
| 48 | static gboolean | |
| 13854 | 49 | msn_check_payload_cmd(char *str) |
| 13853 | 50 | { |
| 51 | if( (!strcmp(str,"ADL")) || | |
| 52 | (!strcmp(str,"GCF")) || | |
| 13856 | 53 | (!strcmp(str,"SG")) || |
| 13853 | 54 | (!strcmp(str,"MSG")) || |
| 55 | (!strcmp(str,"RML")) || | |
| 56 | (!strcmp(str,"UBX")) || | |
| 57 | (!strcmp(str,"UBN")) || | |
| 13870 | 58 | (!strcmp(str,"UUM")) || |
| 59 | (!strcmp(str,"UBM")) || | |
| 13873 | 60 | (!strcmp(str,"FQY")) || |
| 13853 | 61 | (!strcmp(str,"UUN")) || |
| 62 | (!strcmp(str,"UUX"))){ | |
| 63 | return TRUE; | |
| 64 | } | |
| 65 | ||
| 66 | return FALSE; | |
| 67 | } | |
| 68 | ||
| 69 | /*get the payload positon*/ | |
| 13854 | 70 | int msn_get_payload_position(char *str) |
| 13853 | 71 | { |
| 72 | /*because MSG has "MSG hotmail hotmail [payload length]"*/ | |
| 13856 | 73 | if(!(strcmp(str,"MSG"))|| (!strcmp(str,"UBX")) ){ |
| 13853 | 74 | return 2; |
| 75 | } | |
| 13870 | 76 | /*Yahoo User Message UBM |
| 77 | * Format UBM email@yahoo.com 32 1 [payload length]*/ | |
| 78 | if(!(strcmp(str,"UBM"))|| (!strcmp(str,"UUM")) ){ | |
| 79 | return 3; | |
| 80 | } | |
| 13856 | 81 | |
| 13853 | 82 | return 1; |
| 83 | } | |
| 13856 | 84 | |
| 13853 | 85 | /* |
| 86 | * set command Payload length | |
| 87 | */ | |
| 88 | int | |
| 13854 | 89 | msn_set_payload_len(MsnCommand *cmd) |
| 13853 | 90 | { |
| 91 | char * param; | |
| 92 | ||
| 13854 | 93 | if(msn_check_payload_cmd(cmd->command)){ |
| 13856 | 94 | param = cmd->params[msn_get_payload_position(cmd->command)]; |
| 95 | #if 0 | |
| 13853 | 96 | if(!(strcmp(cmd->command,"MSG"))){ |
| 97 | param = cmd->params[2]; | |
| 98 | }else{ | |
| 99 | param = cmd->params[1]; | |
| 100 | } | |
| 13856 | 101 | #endif |
| 13853 | 102 | cmd->payload_len = is_num(param) ? atoi(param) : 0; |
| 103 | }else{ | |
| 104 | cmd->payload_len = 0; | |
| 105 | } | |
| 106 | return 0; | |
| 107 | } | |
| 108 | ||
| 8810 | 109 | MsnCommand * |
| 110 | msn_command_from_string(const char *string) | |
| 111 | { | |
| 112 | MsnCommand *cmd; | |
| 113 | char *tmp; | |
| 114 | char *param_start; | |
| 115 | ||
| 116 | g_return_val_if_fail(string != NULL, NULL); | |
| 117 | ||
| 118 | tmp = g_strdup(string); | |
| 119 | param_start = strchr(tmp, ' '); | |
| 120 | ||
| 121 | cmd = g_new0(MsnCommand, 1); | |
| 122 | cmd->command = tmp; | |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
123 | |
| 8810 | 124 | if (param_start) |
| 125 | { | |
|
14916
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
126 | *param_start++ = '\0'; |
|
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
127 | cmd->params = g_strsplit(param_start, " ", 0); |
|
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
128 | } |
|
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
129 | |
|
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
130 | if (cmd->params != NULL) |
|
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
131 | { |
| 8810 | 132 | char *param; |
| 133 | int c; | |
| 134 | ||
| 135 | for (c = 0; cmd->params[c]; c++); | |
| 136 | cmd->param_count = c; | |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
137 | |
| 8810 | 138 | param = cmd->params[0]; |
| 139 | ||
| 140 | cmd->trId = is_num(param) ? atoi(param) : 0; | |
|
20479
03c44889c50f
Revert some whitespace changes.
Richard Laager <rlaager@pidgin.im>
parents:
20473
diff
changeset
|
141 | } |
|
03c44889c50f
Revert some whitespace changes.
Richard Laager <rlaager@pidgin.im>
parents:
20473
diff
changeset
|
142 | else |
|
03c44889c50f
Revert some whitespace changes.
Richard Laager <rlaager@pidgin.im>
parents:
20473
diff
changeset
|
143 | { |
| 8810 | 144 | cmd->trId = 0; |
| 145 | } | |
|
20473
91e1b3a49d10
msn.tgz from SF Patch #1621854 from Ka-Hing Cheung
Ka-Hing Cheung <khc@pidgin.im>
parents:
20472
diff
changeset
|
146 | |
| 13853 | 147 | /*add payload Length checking*/ |
| 13854 | 148 | msn_set_payload_len(cmd); |
|
16183
92409c474659
Committing khc's msnp14 changes from Trac Ticket #148. --rlaager
Ka-Hing Cheung <khc@pidgin.im>
parents:
15884
diff
changeset
|
149 | purple_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
|
150 | |
| 8810 | 151 | msn_command_ref(cmd); |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
152 | |
| 8810 | 153 | return cmd; |
| 154 | } | |
| 155 | ||
| 156 | void | |
| 157 | msn_command_destroy(MsnCommand *cmd) | |
| 158 | { | |
| 159 | g_return_if_fail(cmd != NULL); | |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
160 | |
| 8810 | 161 | if (cmd->ref_count > 0) |
| 162 | { | |
| 163 | msn_command_unref(cmd); | |
| 164 | return; | |
| 165 | } | |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
166 | |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
167 | if (cmd->payload != NULL) |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
168 | g_free(cmd->payload); |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
169 | |
| 8810 | 170 | g_free(cmd->command); |
| 171 | g_strfreev(cmd->params); | |
| 172 | g_free(cmd); | |
| 173 | } | |
| 174 | ||
| 175 | MsnCommand * | |
| 176 | msn_command_ref(MsnCommand *cmd) | |
| 177 | { | |
| 178 | g_return_val_if_fail(cmd != NULL, NULL); | |
| 179 | ||
| 180 | cmd->ref_count++; | |
| 181 | return cmd; | |
| 182 | } | |
| 183 | ||
| 184 | MsnCommand * | |
| 185 | msn_command_unref(MsnCommand *cmd) | |
| 186 | { | |
| 187 | g_return_val_if_fail(cmd != NULL, NULL); | |
|
12250
5b14301dd1ec
[gaim-migrate @ 14552]
Richard Laager <rlaager@pidgin.im>
parents:
11897
diff
changeset
|
188 | g_return_val_if_fail(cmd->ref_count > 0, NULL); |
| 8810 | 189 | |
| 190 | cmd->ref_count--; | |
| 191 | ||
| 192 | if (cmd->ref_count == 0) | |
| 193 | { | |
| 194 | msn_command_destroy(cmd); | |
| 195 | return NULL; | |
| 196 | } | |
| 197 | ||
| 198 | return cmd; | |
| 199 | } |