Tue, 22 Jun 2010 22:44:28 +0000
Destroy Parts when the SlpMessage is destroyed.
| 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 | */ |
|
30961
885064b16c54
Include internal.h on each c file to avoid windows breakage as recommended by Daniel.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30945
diff
changeset
|
24 | #include "internal.h" |
|
885064b16c54
Include internal.h on each c file to avoid windows breakage as recommended by Daniel.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30945
diff
changeset
|
25 | |
| 8810 | 26 | #include "command.h" |
| 27 | ||
|
11897
10853b830964
[gaim-migrate @ 14188]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9198
diff
changeset
|
28 | static gboolean |
|
20844
55f8b930a3f6
Sanity checking and minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents:
20597
diff
changeset
|
29 | is_num(const char *str) |
| 8810 | 30 | { |
|
20844
55f8b930a3f6
Sanity checking and minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents:
20597
diff
changeset
|
31 | const char *c; |
| 8810 | 32 | for (c = str; *c; c++) { |
| 33 | if (!(g_ascii_isdigit(*c))) | |
| 34 | return FALSE; | |
| 35 | } | |
| 36 | ||
| 37 | return TRUE; | |
| 38 | } | |
| 39 | ||
| 40 | MsnCommand * | |
| 41 | msn_command_from_string(const char *string) | |
| 42 | { | |
| 43 | MsnCommand *cmd; | |
| 44 | char *param_start; | |
| 45 | ||
| 46 | g_return_val_if_fail(string != NULL, NULL); | |
| 47 | ||
| 48 | cmd = g_new0(MsnCommand, 1); | |
|
20844
55f8b930a3f6
Sanity checking and minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents:
20597
diff
changeset
|
49 | cmd->command = g_strdup(string); |
|
55f8b930a3f6
Sanity checking and minor cleanup.
Daniel Atallah <datallah@pidgin.im>
parents:
20597
diff
changeset
|
50 | param_start = strchr(cmd->command, ' '); |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
51 | |
| 8810 | 52 | if (param_start) |
| 53 | { | |
|
14916
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
54 | *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
|
55 | cmd->params = g_strsplit_set(param_start, " ", 0); |
|
14916
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 | |
|
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
58 | if (cmd->params != NULL) |
|
76caac9890c5
[gaim-migrate @ 17623]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
59 | { |
| 8810 | 60 | int c; |
| 61 | ||
|
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
|
62 | for (c = 0; cmd->params[c] && cmd->params[c][0]; c++); |
| 8810 | 63 | cmd->param_count = c; |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
64 | |
|
23806
ef4e97200434
Avoid a NULL reference in msn_command_from_string.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23778
diff
changeset
|
65 | 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
|
66 | 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
|
67 | 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
|
68 | } else { |
|
ef4e97200434
Avoid a NULL reference in msn_command_from_string.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23778
diff
changeset
|
69 | cmd->trId = 0; |
|
ef4e97200434
Avoid a NULL reference in msn_command_from_string.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23778
diff
changeset
|
70 | } |
| 8810 | 71 | } |
| 72 | else | |
|
20479
03c44889c50f
Revert some whitespace changes.
Richard Laager <rlaager@pidgin.im>
parents:
20473
diff
changeset
|
73 | { |
| 8810 | 74 | cmd->trId = 0; |
| 75 | } | |
|
20473
91e1b3a49d10
msn.tgz from SF Patch #1621854 from Ka-Hing Cheung
Ka-Hing Cheung <khc@pidgin.im>
parents:
20472
diff
changeset
|
76 | |
| 8810 | 77 | msn_command_ref(cmd); |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
78 | |
| 8810 | 79 | return cmd; |
| 80 | } | |
| 81 | ||
| 82 | void | |
| 83 | msn_command_destroy(MsnCommand *cmd) | |
| 84 | { | |
| 85 | g_return_if_fail(cmd != NULL); | |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
86 | |
| 8810 | 87 | if (cmd->ref_count > 0) |
| 88 | { | |
| 89 | msn_command_unref(cmd); | |
| 90 | return; | |
| 91 | } | |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
92 | |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
93 | if (cmd->payload != NULL) |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
94 | g_free(cmd->payload); |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
95 | |
| 8810 | 96 | g_free(cmd->command); |
| 97 | g_strfreev(cmd->params); | |
| 98 | g_free(cmd); | |
| 99 | } | |
| 100 | ||
| 101 | MsnCommand * | |
| 102 | msn_command_ref(MsnCommand *cmd) | |
| 103 | { | |
| 104 | g_return_val_if_fail(cmd != NULL, NULL); | |
| 105 | ||
| 106 | cmd->ref_count++; | |
| 107 | return cmd; | |
| 108 | } | |
| 109 | ||
| 110 | MsnCommand * | |
| 111 | msn_command_unref(MsnCommand *cmd) | |
| 112 | { | |
| 113 | g_return_val_if_fail(cmd != NULL, NULL); | |
|
12250
5b14301dd1ec
[gaim-migrate @ 14552]
Richard Laager <rlaager@pidgin.im>
parents:
11897
diff
changeset
|
114 | g_return_val_if_fail(cmd->ref_count > 0, NULL); |
| 8810 | 115 | |
| 116 | cmd->ref_count--; | |
| 117 | ||
| 118 | if (cmd->ref_count == 0) | |
| 119 | { | |
| 120 | msn_command_destroy(cmd); | |
| 121 | return NULL; | |
| 122 | } | |
| 123 | ||
| 124 | return cmd; | |
| 125 | } |