Mercurial > pidgin
annotate src/protocols/msn/command.c @ 19800:da3f8f7ec3ce
[gaim-migrate @ 16737]
can send Message to Yahoo Messenger
can receive the Yahoo Message, Need to post it to the conversation
committed by Ma Yuan<mayuan2006@gmail.com>
committer: Ethan Blanton <elb@pidgin.im>
| author | Ma Yuan <mayuan2006@gmail.com> |
|---|---|
| date | Sun, 13 Aug 2006 16:01:52 +0000 |
| parents | 23258253c7a0 |
| children | 2315ee828b7c |
| 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")) || | |
| 19786 | 49 (!strcmp(str,"SG")) || |
| 19783 | 50 (!strcmp(str,"MSG")) || |
| 51 (!strcmp(str,"RML")) || | |
| 52 (!strcmp(str,"UBX")) || | |
| 53 (!strcmp(str,"UBN")) || | |
| 19800 | 54 (!strcmp(str,"UUM")) || |
| 55 (!strcmp(str,"UBM")) || | |
| 19783 | 56 (!strcmp(str,"UUN")) || |
| 57 (!strcmp(str,"UUX"))){ | |
| 58 return TRUE; | |
| 59 } | |
| 60 | |
| 61 return FALSE; | |
| 62 } | |
| 63 | |
| 64 /*get the payload positon*/ | |
| 19784 | 65 int msn_get_payload_position(char *str) |
| 19783 | 66 { |
| 67 /*because MSG has "MSG hotmail hotmail [payload length]"*/ | |
| 19786 | 68 if(!(strcmp(str,"MSG"))|| (!strcmp(str,"UBX")) ){ |
| 19783 | 69 return 2; |
| 70 } | |
| 19800 | 71 /*Yahoo User Message UBM |
| 72 * Format UBM email@yahoo.com 32 1 [payload length]*/ | |
| 73 if(!(strcmp(str,"UBM"))|| (!strcmp(str,"UUM")) ){ | |
| 74 return 3; | |
| 75 } | |
| 19786 | 76 |
| 19783 | 77 return 1; |
| 78 } | |
| 19786 | 79 |
| 19783 | 80 /* |
| 81 * set command Payload length | |
| 82 */ | |
| 83 int | |
| 19784 | 84 msn_set_payload_len(MsnCommand *cmd) |
| 19783 | 85 { |
| 86 char * param; | |
| 87 | |
| 19784 | 88 if(msn_check_payload_cmd(cmd->command)){ |
| 19786 | 89 param = cmd->params[msn_get_payload_position(cmd->command)]; |
| 90 #if 0 | |
| 19783 | 91 if(!(strcmp(cmd->command,"MSG"))){ |
| 92 param = cmd->params[2]; | |
| 93 }else{ | |
| 94 param = cmd->params[1]; | |
| 95 } | |
| 19786 | 96 #endif |
| 19783 | 97 cmd->payload_len = is_num(param) ? atoi(param) : 0; |
| 98 }else{ | |
| 99 cmd->payload_len = 0; | |
| 100 } | |
| 101 return 0; | |
| 102 } | |
| 103 | |
| 8810 | 104 MsnCommand * |
| 105 msn_command_from_string(const char *string) | |
| 106 { | |
| 107 MsnCommand *cmd; | |
| 108 char *tmp; | |
| 109 char *param_start; | |
| 19783 | 110 char *param; |
| 111 int c; | |
| 8810 | 112 |
| 113 g_return_val_if_fail(string != NULL, NULL); | |
| 114 | |
| 115 tmp = g_strdup(string); | |
| 116 param_start = strchr(tmp, ' '); | |
| 117 | |
| 118 cmd = g_new0(MsnCommand, 1); | |
| 119 cmd->command = tmp; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
120 |
| 19783 | 121 if (param_start){ |
| 8810 | 122 *param_start++ = '\0'; |
| 123 cmd->params = g_strsplit(param_start, " ", 0); | |
| 124 | |
| 125 for (c = 0; cmd->params[c]; c++); | |
| 126 cmd->param_count = c; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
127 |
| 8810 | 128 param = cmd->params[0]; |
| 129 | |
| 130 cmd->trId = is_num(param) ? atoi(param) : 0; | |
| 19783 | 131 }else{ |
| 132 cmd->trId = 0; | |
| 8810 | 133 } |
| 19783 | 134 |
| 135 /*add payload Length checking*/ | |
| 19784 | 136 msn_set_payload_len(cmd); |
| 19783 | 137 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
|
138 |
| 8810 | 139 msn_command_ref(cmd); |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
140 |
| 8810 | 141 return cmd; |
| 142 } | |
| 143 | |
| 144 void | |
| 145 msn_command_destroy(MsnCommand *cmd) | |
| 146 { | |
| 147 g_return_if_fail(cmd != NULL); | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
148 |
| 8810 | 149 if (cmd->ref_count > 0) |
| 150 { | |
| 151 msn_command_unref(cmd); | |
| 152 return; | |
| 153 } | |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
154 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
155 if (cmd->payload != NULL) |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
156 g_free(cmd->payload); |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
157 |
| 8810 | 158 g_free(cmd->command); |
| 159 g_strfreev(cmd->params); | |
| 160 g_free(cmd); | |
| 161 } | |
| 162 | |
| 163 MsnCommand * | |
| 164 msn_command_ref(MsnCommand *cmd) | |
| 165 { | |
| 166 g_return_val_if_fail(cmd != NULL, NULL); | |
| 167 | |
| 168 cmd->ref_count++; | |
| 169 return cmd; | |
| 170 } | |
| 171 | |
| 172 MsnCommand * | |
| 173 msn_command_unref(MsnCommand *cmd) | |
| 174 { | |
| 175 g_return_val_if_fail(cmd != NULL, NULL); | |
|
12250
5e2a365af01b
[gaim-migrate @ 14552]
Richard Laager <rlaager@wiktel.com>
parents:
11897
diff
changeset
|
176 g_return_val_if_fail(cmd->ref_count > 0, NULL); |
| 8810 | 177 |
| 178 cmd->ref_count--; | |
| 179 | |
| 180 if (cmd->ref_count == 0) | |
| 181 { | |
| 182 msn_command_destroy(cmd); | |
| 183 return NULL; | |
| 184 } | |
| 185 | |
| 186 return cmd; | |
| 187 } |
