Sun, 16 Sep 2007 18:03:53 +0000
explicit merge of '71d37b57eff2574031b2bbf1a2388ae1446db2da'
and '506f2256bc5e147c89cabba15e2865b28fe4ea9e'
| 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 | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
15884
diff
changeset
|
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 8810 | 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")) || | |
| 13870 | 54 | (!strcmp(str,"UUM")) || |
| 55 | (!strcmp(str,"UBM")) || | |
| 13873 | 56 | (!strcmp(str,"FQY")) || |
| 13853 | 57 | (!strcmp(str,"UUN")) || |
|
20522
177cad886d4c
A bunch of MSNP14 stuff:
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
20521
diff
changeset
|
58 | (!strcmp(str,"UUX")) || |
|
177cad886d4c
A bunch of MSNP14 stuff:
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
20521
diff
changeset
|
59 | (is_num(str))){ |
| 13853 | 60 | return TRUE; |
| 61 | } | |
| 62 | ||
| 63 | return FALSE; | |
| 64 | } | |
| 65 | ||
| 66 | /* | |
| 67 | * set command Payload length | |
| 68 | */ | |
|
20522
177cad886d4c
A bunch of MSNP14 stuff:
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
20521
diff
changeset
|
69 | static void |
| 13854 | 70 | msn_set_payload_len(MsnCommand *cmd) |
| 13853 | 71 | { |
|
20522
177cad886d4c
A bunch of MSNP14 stuff:
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
20521
diff
changeset
|
72 | char *param; |
|
177cad886d4c
A bunch of MSNP14 stuff:
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
20521
diff
changeset
|
73 | int len = 0; |
| 13853 | 74 | |
|
20522
177cad886d4c
A bunch of MSNP14 stuff:
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
20521
diff
changeset
|
75 | if (msn_check_payload_cmd(cmd->command) && (cmd->param_count > 0)){ |
|
177cad886d4c
A bunch of MSNP14 stuff:
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
20521
diff
changeset
|
76 | param = cmd->params[cmd->param_count - 1]; |
|
177cad886d4c
A bunch of MSNP14 stuff:
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
20521
diff
changeset
|
77 | len = is_num(param) ? atoi(param) : 0; |
| 13853 | 78 | } |
|
20522
177cad886d4c
A bunch of MSNP14 stuff:
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
20521
diff
changeset
|
79 | |
|
177cad886d4c
A bunch of MSNP14 stuff:
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
20521
diff
changeset
|
80 | cmd->payload_len = len; |
| 13853 | 81 | } |
| 82 | ||
| 8810 | 83 | MsnCommand * |
| 84 | msn_command_from_string(const char *string) | |
| 85 | { | |
| 86 | MsnCommand *cmd; | |
| 87 | char *tmp; | |
| 88 | char *param_start; | |
| 89 | ||
| 90 | g_return_val_if_fail(string != NULL, NULL); | |
| 91 | ||
| 92 | tmp = g_strdup(string); | |
| 93 | param_start = strchr(tmp, ' '); | |
| 94 | ||
| 95 | cmd = g_new0(MsnCommand, 1); | |
| 96 | cmd->command = tmp; | |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
97 | |
| 8810 | 98 | if (param_start) |
| 99 | { | |
|
14916
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
100 | *param_start++ = '\0'; |
|
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
101 | cmd->params = g_strsplit(param_start, " ", 0); |
|
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
102 | } |
|
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
103 | |
|
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
104 | if (cmd->params != NULL) |
|
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
105 | { |
| 8810 | 106 | char *param; |
| 107 | int c; | |
| 108 | ||
| 109 | for (c = 0; cmd->params[c]; c++); | |
| 110 | cmd->param_count = c; | |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
111 | |
| 8810 | 112 | param = cmd->params[0]; |
| 113 | ||
| 114 | cmd->trId = is_num(param) ? atoi(param) : 0; | |
| 115 | } | |
| 116 | else | |
|
20479
03c44889c50f
Revert some whitespace changes.
Richard Laager <rlaager@pidgin.im>
parents:
20473
diff
changeset
|
117 | { |
| 8810 | 118 | cmd->trId = 0; |
| 119 | } | |
|
20473
91e1b3a49d10
msn.tgz from SF Patch #1621854 from Ka-Hing Cheung
Ka-Hing Cheung <khc@pidgin.im>
parents:
20472
diff
changeset
|
120 | |
| 13853 | 121 | /*add payload Length checking*/ |
| 13854 | 122 | msn_set_payload_len(cmd); |
|
20550
af5abde0d99f
Misc cleanups, better error handling, and print the Address Book received from the server in a human readable way.
Carlos Silva <typ0@pidgin.im>
parents:
20522
diff
changeset
|
123 | purple_debug_info("MSNP14","get payload len:%d\n",cmd->payload_len); |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
124 | |
| 8810 | 125 | msn_command_ref(cmd); |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
126 | |
| 8810 | 127 | return cmd; |
| 128 | } | |
| 129 | ||
| 130 | void | |
| 131 | msn_command_destroy(MsnCommand *cmd) | |
| 132 | { | |
| 133 | g_return_if_fail(cmd != NULL); | |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
134 | |
| 8810 | 135 | if (cmd->ref_count > 0) |
| 136 | { | |
| 137 | msn_command_unref(cmd); | |
| 138 | return; | |
| 139 | } | |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
140 | |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
141 | if (cmd->payload != NULL) |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
142 | g_free(cmd->payload); |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
143 | |
| 8810 | 144 | g_free(cmd->command); |
| 145 | g_strfreev(cmd->params); | |
| 146 | g_free(cmd); | |
| 147 | } | |
| 148 | ||
| 149 | MsnCommand * | |
| 150 | msn_command_ref(MsnCommand *cmd) | |
| 151 | { | |
| 152 | g_return_val_if_fail(cmd != NULL, NULL); | |
| 153 | ||
| 154 | cmd->ref_count++; | |
| 155 | return cmd; | |
| 156 | } | |
| 157 | ||
| 158 | MsnCommand * | |
| 159 | msn_command_unref(MsnCommand *cmd) | |
| 160 | { | |
| 161 | g_return_val_if_fail(cmd != NULL, NULL); | |
|
12250
5b14301dd1ec
[gaim-migrate @ 14552]
Richard Laager <rlaager@pidgin.im>
parents:
11897
diff
changeset
|
162 | g_return_val_if_fail(cmd->ref_count > 0, NULL); |
| 8810 | 163 | |
| 164 | cmd->ref_count--; | |
| 165 | ||
| 166 | if (cmd->ref_count == 0) | |
| 167 | { | |
| 168 | msn_command_destroy(cmd); | |
| 169 | return NULL; | |
| 170 | } | |
| 171 | ||
| 172 | return cmd; | |
| 173 | } |