Sun, 10 Aug 2008 18:46:32 +0000
Reapplied changes that were overwritten by 91f0294f2377e3870982f3e573e0dfb4230d9c11.
applied changes from b53b1ff4bbd75647c953e5f02eaca17c85d2113e
through 586238415076c2a3a3079812de64aff5841cde39
applied changes from 918c72f0ff7f7e3c545d3baf6368ccbd2ba21427
through e8404ca19a538f5254f1a156feb894d0618588d2
applied changes from e8404ca19a538f5254f1a156feb894d0618588d2
through 398b1414aa67f63ae191264603994be045df42f5
applied changes from 398b1414aa67f63ae191264603994be045df42f5
through b53b1ff4bbd75647c953e5f02eaca17c85d2113e
| 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 |
|
20844
55f8b930a3f6
Sanity checking and minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents:
20597
diff
changeset
|
28 | is_num(const char *str) |
| 8810 | 29 | { |
|
20844
55f8b930a3f6
Sanity checking and minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents:
20597
diff
changeset
|
30 | const char *c; |
| 8810 | 31 | for (c = str; *c; c++) { |
| 32 | if (!(g_ascii_isdigit(*c))) | |
| 33 | return FALSE; | |
| 34 | } | |
| 35 | ||
| 36 | return TRUE; | |
| 37 | } | |
| 38 | ||
| 39 | MsnCommand * | |
| 40 | msn_command_from_string(const char *string) | |
| 41 | { | |
| 42 | MsnCommand *cmd; | |
| 43 | char *param_start; | |
| 44 | ||
| 45 | g_return_val_if_fail(string != NULL, NULL); | |
| 46 | ||
| 47 | cmd = g_new0(MsnCommand, 1); | |
|
20844
55f8b930a3f6
Sanity checking and minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents:
20597
diff
changeset
|
48 | cmd->command = g_strdup(string); |
|
55f8b930a3f6
Sanity checking and minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents:
20597
diff
changeset
|
49 | param_start = strchr(cmd->command, ' '); |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
50 | |
| 8810 | 51 | if (param_start) |
| 52 | { | |
|
14916
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
53 | *param_start++ = '\0'; |
|
23842
5d868d301756
Workaround a bug in MSN servers where it sends an extra space at the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23826
diff
changeset
|
54 | cmd->params = g_strsplit_set(param_start, " ", 0); |
|
14916
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
55 | } |
|
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
56 | |
|
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
57 | if (cmd->params != NULL) |
|
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
58 | { |
| 8810 | 59 | int c; |
| 60 | ||
|
23842
5d868d301756
Workaround a bug in MSN servers where it sends an extra space at the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23826
diff
changeset
|
61 | for (c = 0; cmd->params[c] && cmd->params[c][0]; c++); |
| 8810 | 62 | cmd->param_count = c; |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
63 | |
|
23806
ef4e97200434
Avoid a NULL reference in msn_command_from_string.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23778
diff
changeset
|
64 | if (cmd->param_count) { |
|
ef4e97200434
Avoid a NULL reference in msn_command_from_string.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23778
diff
changeset
|
65 | char *param = cmd->params[0]; |
|
ef4e97200434
Avoid a NULL reference in msn_command_from_string.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23778
diff
changeset
|
66 | cmd->trId = is_num(param) ? atoi(param) : 0; |
|
ef4e97200434
Avoid a NULL reference in msn_command_from_string.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23778
diff
changeset
|
67 | } else { |
|
ef4e97200434
Avoid a NULL reference in msn_command_from_string.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23778
diff
changeset
|
68 | cmd->trId = 0; |
|
ef4e97200434
Avoid a NULL reference in msn_command_from_string.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23778
diff
changeset
|
69 | } |
| 8810 | 70 | } |
| 71 | else | |
|
20479
03c44889c50f
Revert some whitespace changes.
Richard Laager <rlaager@pidgin.im>
parents:
20473
diff
changeset
|
72 | { |
| 8810 | 73 | cmd->trId = 0; |
| 74 | } | |
|
20473
91e1b3a49d10
msn.tgz from SF Patch #1621854 from Ka-Hing Cheung
Ka-Hing Cheung <khc@pidgin.im>
parents:
20472
diff
changeset
|
75 | |
| 8810 | 76 | msn_command_ref(cmd); |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
77 | |
| 8810 | 78 | return cmd; |
| 79 | } | |
| 80 | ||
| 81 | void | |
| 82 | msn_command_destroy(MsnCommand *cmd) | |
| 83 | { | |
| 84 | g_return_if_fail(cmd != NULL); | |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
85 | |
| 8810 | 86 | if (cmd->ref_count > 0) |
| 87 | { | |
| 88 | msn_command_unref(cmd); | |
| 89 | return; | |
| 90 | } | |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
91 | |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
92 | if (cmd->payload != NULL) |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
93 | g_free(cmd->payload); |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
94 | |
| 8810 | 95 | g_free(cmd->command); |
| 96 | g_strfreev(cmd->params); | |
| 97 | g_free(cmd); | |
| 98 | } | |
| 99 | ||
| 100 | MsnCommand * | |
| 101 | msn_command_ref(MsnCommand *cmd) | |
| 102 | { | |
| 103 | g_return_val_if_fail(cmd != NULL, NULL); | |
| 104 | ||
| 105 | cmd->ref_count++; | |
| 106 | return cmd; | |
| 107 | } | |
| 108 | ||
| 109 | MsnCommand * | |
| 110 | msn_command_unref(MsnCommand *cmd) | |
| 111 | { | |
| 112 | g_return_val_if_fail(cmd != NULL, NULL); | |
|
12250
5b14301dd1ec
[gaim-migrate @ 14552]
Richard Laager <rlaager@pidgin.im>
parents:
11897
diff
changeset
|
113 | g_return_val_if_fail(cmd->ref_count > 0, NULL); |
| 8810 | 114 | |
| 115 | cmd->ref_count--; | |
| 116 | ||
| 117 | if (cmd->ref_count == 0) | |
| 118 | { | |
| 119 | msn_command_destroy(cmd); | |
| 120 | return NULL; | |
| 121 | } | |
| 122 | ||
| 123 | return cmd; | |
| 124 | } |