Mercurial > pidgin
annotate src/protocols/msn/command.c @ 19785:852b32710df0
[gaim-migrate @ 16507]
add the contact list retrieve and dump contact list to server
currently can do chanllenge successfully
But can't get the buddy list done
by MaYuan<mayuan2006@gmail.com>
committer: Ethan Blanton <elb@pidgin.im>
| author | Ma Yuan <mayuan2006@gmail.com> |
|---|---|
| date | Mon, 17 Jul 2006 12:22:37 +0000 |
| parents | bc30c6270d9f |
| children | 23258253c7a0 |
| rev | line source |
|---|---|
| 8810 | 1 /** |
| 2 * @file command.c MSN command functions | |
| 3 * | |
| 4 * gaim | |
| 5 * | |
|
9198
ab6636c5a136
[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 |
|
ab6636c5a136
[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 |
|
ab6636c5a136
[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 | 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 | |
| 19783 | 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 | |
| 19784 | 45 msn_check_payload_cmd(char *str) |
| 19783 | 46 { |
| 47 if( (!strcmp(str,"ADL")) || | |
| 48 (!strcmp(str,"GCF")) || | |
| 49 (!strcmp(str,"MSG")) || | |
| 50 (!strcmp(str,"RML")) || | |
| 51 (!strcmp(str,"UBX")) || | |
| 52 (!strcmp(str,"UBN")) || | |
| 53 (!strcmp(str,"UUN")) || | |
| 54 (!strcmp(str,"UUX"))){ | |
| 55 return TRUE; | |
| 56 } | |
| 57 | |
| 58 return FALSE; | |
| 59 } | |
| 60 | |
| 61 /*get the payload positon*/ | |
| 19784 | 62 int msn_get_payload_position(char *str) |
| 19783 | 63 { |
| 64 /*because MSG has "MSG hotmail hotmail [payload length]"*/ | |
| 65 if(!(strcmp(str,"MSG"))){ | |
| 66 return 2; | |
| 67 } | |
| 68 return 1; | |
| 69 } | |
| 70 /* | |
| 71 * set command Payload length | |
| 72 */ | |
| 73 int | |
| 19784 | 74 msn_set_payload_len(MsnCommand *cmd) |
| 19783 | 75 { |
| 76 char * param; | |
| 77 | |
| 19784 | 78 if(msn_check_payload_cmd(cmd->command)){ |
| 19783 | 79 if(!(strcmp(cmd->command,"MSG"))){ |
| 80 param = cmd->params[2]; | |
| 81 }else{ | |
| 82 param = cmd->params[1]; | |
| 83 } | |
| 84 cmd->payload_len = is_num(param) ? atoi(param) : 0; | |
| 85 }else{ | |
| 86 cmd->payload_len = 0; | |
| 87 } | |
| 88 return 0; | |
| 89 } | |
| 90 | |
| 8810 | 91 MsnCommand * |
| 92 msn_command_from_string(const char *string) | |
| 93 { | |
| 94 MsnCommand *cmd; | |
| 95 char *tmp; | |
| 96 char *param_start; | |
| 19783 | 97 char *param; |
| 98 int c; | |
| 8810 | 99 |
| 100 g_return_val_if_fail(string != NULL, NULL); | |
| 101 | |
| 102 tmp = g_strdup(string); | |
| 103 param_start = strchr(tmp, ' '); | |
| 104 | |
| 105 cmd = g_new0(MsnCommand, 1); | |
| 106 cmd->command = tmp; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
107 |
| 19783 | 108 if (param_start){ |
| 8810 | 109 *param_start++ = '\0'; |
| 110 cmd->params = g_strsplit(param_start, " ", 0); | |
| 111 | |
| 112 for (c = 0; cmd->params[c]; c++); | |
| 113 cmd->param_count = c; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
114 |
| 8810 | 115 param = cmd->params[0]; |
| 116 | |
| 117 cmd->trId = is_num(param) ? atoi(param) : 0; | |
| 19783 | 118 }else{ |
| 119 cmd->trId = 0; | |
| 8810 | 120 } |
| 19783 | 121 |
| 122 /*add payload Length checking*/ | |
| 19784 | 123 msn_set_payload_len(cmd); |
| 19783 | 124 gaim_debug_info("MaYuan","get payload len:%d\n",cmd->payload_len); |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
125 |
| 8810 | 126 msn_command_ref(cmd); |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
127 |
| 8810 | 128 return cmd; |
| 129 } | |
| 130 | |
| 131 void | |
| 132 msn_command_destroy(MsnCommand *cmd) | |
| 133 { | |
| 134 g_return_if_fail(cmd != NULL); | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
135 |
| 8810 | 136 if (cmd->ref_count > 0) |
| 137 { | |
| 138 msn_command_unref(cmd); | |
| 139 return; | |
| 140 } | |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
141 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
142 if (cmd->payload != NULL) |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
143 g_free(cmd->payload); |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
144 |
| 8810 | 145 g_free(cmd->command); |
| 146 g_strfreev(cmd->params); | |
| 147 g_free(cmd); | |
| 148 } | |
| 149 | |
| 150 MsnCommand * | |
| 151 msn_command_ref(MsnCommand *cmd) | |
| 152 { | |
| 153 g_return_val_if_fail(cmd != NULL, NULL); | |
| 154 | |
| 155 cmd->ref_count++; | |
| 156 return cmd; | |
| 157 } | |
| 158 | |
| 159 MsnCommand * | |
| 160 msn_command_unref(MsnCommand *cmd) | |
| 161 { | |
| 162 g_return_val_if_fail(cmd != NULL, NULL); | |
|
12250
5e2a365af01b
[gaim-migrate @ 14552]
Richard Laager <rlaager@wiktel.com>
parents:
11897
diff
changeset
|
163 g_return_val_if_fail(cmd->ref_count > 0, NULL); |
| 8810 | 164 |
| 165 cmd->ref_count--; | |
| 166 | |
| 167 if (cmd->ref_count == 0) | |
| 168 { | |
| 169 msn_command_destroy(cmd); | |
| 170 return NULL; | |
| 171 } | |
| 172 | |
| 173 return cmd; | |
| 174 } |
