Mercurial > pidgin.yaz
annotate src/protocols/yahoo/outgoing.c @ 2475:ba7ee4c1908c
[gaim-migrate @ 2488]
BMiller's fixes so gg compiles on solaris
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Wed, 10 Oct 2001 20:03:17 +0000 |
| parents | 50163c916f9d |
| children |
| rev | line source |
|---|---|
| 2086 | 1 /* |
| 2 * libyay | |
| 3 * | |
| 4 * Copyright (C) 2001 Eric Warmenhoven <warmenhoven@yahoo.com> | |
| 5 * | |
| 6 * This program is free software; you can redistribute it and/or modify | |
| 7 * it under the terms of the GNU General Public License as published by | |
| 8 * the Free Software Foundation; either version 2 of the License, or | |
| 9 * (at your option) any later version. | |
| 10 * | |
| 11 * This program is distributed in the hope that it will be useful, | |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 * GNU General Public License for more details. | |
| 15 * | |
| 16 * You should have received a copy of the GNU General Public License | |
| 17 * along with this program; if not, write to the Free Software | |
| 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 * | |
| 20 */ | |
| 21 | |
| 22 #include "internal.h" | |
| 23 #include <string.h> | |
| 24 | |
| 25 int yahoo_write(struct yahoo_session *session, struct yahoo_conn *conn, void *buf, int len) | |
| 26 { | |
| 27 if (!session || !conn) | |
| 28 return 0; | |
| 29 | |
| 30 if (!g_list_find(session->connlist, conn)) | |
| 31 return 0; | |
| 32 | |
| 33 if (send(conn->socket, buf, len, 0) != len) { | |
| 34 int type = conn->type; | |
| 35 yahoo_close(session, conn); | |
| 36 YAHOO_PRINT(session, YAHOO_LOG_CRITICAL, "error sending"); | |
| 37 if (type == YAHOO_CONN_TYPE_DUMB) | |
| 38 if (session->callbacks[YAHOO_HANDLE_DISCONNECT].function) | |
| 39 (*session->callbacks[YAHOO_HANDLE_DISCONNECT].function)(session); | |
| 40 return 0; | |
| 41 } | |
| 42 | |
| 43 return len; | |
| 44 } | |
| 45 | |
| 46 int yahoo_write_cmd(struct yahoo_session *session, struct yahoo_conn *conn, | |
| 47 int service, const char *active_id, void *buf, guint msgtype) | |
| 48 { | |
| 49 struct yahoo_packet *pkt; | |
| 50 int ret; | |
| 51 | |
|
2455
50163c916f9d
[gaim-migrate @ 2468]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
52 if (!session || !session->login || !conn || !active_id) |
| 2086 | 53 return 0; |
| 54 | |
| 55 if (!(pkt = g_new0(struct yahoo_packet, 1))) | |
| 56 return 0; | |
| 57 | |
| 58 strcpy(pkt->version, "YPNS2.0"); | |
| 59 yahoo_storeint(pkt->len, sizeof(struct yahoo_packet)); | |
| 60 yahoo_storeint(pkt->service, service); | |
| 61 | |
| 62 yahoo_storeint(pkt->magic_id, conn->magic_id); | |
| 63 yahoo_storeint(pkt->msgtype, msgtype); | |
| 64 | |
| 65 strcpy(pkt->nick1, session->login); | |
| 66 strcpy(pkt->nick2, active_id); | |
| 67 | |
| 68 strncpy(pkt->content, buf, 1024); | |
| 69 | |
| 70 ret = yahoo_write(session, conn, pkt, sizeof(struct yahoo_packet)); | |
| 71 g_free(pkt); | |
| 72 return ret; | |
| 73 } | |
| 74 | |
| 75 int yahoo_activate_id(struct yahoo_session *session, char *id) | |
| 76 { | |
| 77 struct yahoo_conn *conn; | |
| 78 | |
| 79 if (!session || !id) | |
| 80 return 0; | |
| 81 | |
| 82 if (!(conn = yahoo_getconn_type(session, YAHOO_CONN_TYPE_MAIN))) | |
| 83 return 0; | |
| 84 | |
| 85 return yahoo_write_cmd(session, conn, YAHOO_SERVICE_IDACT, id, id, 0); | |
| 86 } | |
| 87 | |
| 88 int yahoo_deactivate_id(struct yahoo_session *session, char *id) | |
| 89 { | |
| 90 struct yahoo_conn *conn; | |
| 91 | |
| 92 if (!session || !id) | |
| 93 return 0; | |
| 94 | |
| 95 if (!(conn = yahoo_getconn_type(session, YAHOO_CONN_TYPE_MAIN))) | |
| 96 return 0; | |
| 97 | |
| 98 return yahoo_write_cmd(session, conn, YAHOO_SERVICE_IDDEACT, id, id, 0); | |
| 99 } | |
| 100 | |
| 101 int yahoo_send_message(struct yahoo_session *session, const char *active_id, | |
| 102 const char *user, const char *msg) | |
| 103 { | |
| 104 struct yahoo_conn *conn; | |
| 105 char *buf; | |
| 106 int ret; | |
| 107 | |
| 108 if (!session || !user || !msg) | |
| 109 return 0; | |
| 110 | |
| 111 if (!(conn = yahoo_getconn_type(session, YAHOO_CONN_TYPE_MAIN))) | |
| 112 return 0; | |
| 113 | |
| 114 if (!(buf = g_strconcat(user, ",", msg, NULL))) | |
| 115 return 0; | |
| 116 | |
| 117 ret = yahoo_write_cmd(session, conn, YAHOO_SERVICE_MESSAGE, | |
| 118 active_id ? active_id : session->name, buf, 0); | |
| 119 g_free(buf); | |
| 120 | |
| 121 return ret; | |
| 122 } | |
| 123 | |
| 124 int yahoo_send_message_offline(struct yahoo_session *session, const char *active_id, | |
| 125 const char *user, const char *msg) | |
| 126 { | |
| 127 struct yahoo_conn *conn; | |
| 128 char *buf; | |
| 129 int ret; | |
| 130 | |
| 131 if (!session || !user || !msg) | |
| 132 return 0; | |
| 133 | |
| 134 if (!(conn = yahoo_getconn_type(session, YAHOO_CONN_TYPE_MAIN))) | |
| 135 return 0; | |
| 136 | |
| 137 if (!(buf = g_strconcat(user, ",", msg, NULL))) | |
| 138 return 0; | |
| 139 | |
| 140 ret = yahoo_write_cmd(session, conn, YAHOO_SERVICE_MESSAGE, | |
| 141 active_id ? active_id : session->name, buf, YAHOO_MESSAGE_SEND); | |
| 142 g_free(buf); | |
| 143 | |
| 144 return ret; | |
| 145 } | |
| 146 | |
| 147 int yahoo_logoff(struct yahoo_session *session) | |
| 148 { | |
| 149 struct yahoo_conn *conn; | |
| 150 | |
| 151 if (!session) | |
| 152 return 0; | |
| 153 | |
|
2455
50163c916f9d
[gaim-migrate @ 2468]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
154 if (!session->login) |
|
50163c916f9d
[gaim-migrate @ 2468]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
155 return 0; |
|
50163c916f9d
[gaim-migrate @ 2468]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
156 |
| 2086 | 157 if (!(conn = yahoo_getconn_type(session, YAHOO_CONN_TYPE_MAIN))) |
| 158 return 0; | |
| 159 | |
| 160 return yahoo_write_cmd(session, conn, YAHOO_SERVICE_LOGOFF, session->name, session->name, 0); | |
| 161 } | |
| 162 | |
| 163 int yahoo_ping(struct yahoo_session *session) | |
| 164 { | |
| 165 struct yahoo_conn *conn; | |
| 166 | |
| 167 if (!session) | |
| 168 return 0; | |
| 169 | |
| 170 if (!(conn = yahoo_getconn_type(session, YAHOO_CONN_TYPE_MAIN))) | |
| 171 return 0; | |
| 172 | |
| 173 return yahoo_write_cmd(session, conn, YAHOO_SERVICE_PING, session->name, "", 0); | |
| 174 } | |
| 175 | |
| 176 int yahoo_away(struct yahoo_session *session, enum yahoo_status status, char *msg) | |
| 177 { | |
| 178 struct yahoo_conn *conn; | |
| 179 char buf[1024]; | |
| 180 | |
| 181 if (!session) | |
| 182 return 0; | |
| 183 | |
| 184 if (!(conn = yahoo_getconn_type(session, YAHOO_CONN_TYPE_MAIN))) | |
| 185 return 0; | |
| 186 | |
| 187 g_snprintf(buf, sizeof(buf), "%d%c%s", status, 1, msg ? msg : "---"); | |
| 188 | |
| 189 return yahoo_write_cmd(session, conn, YAHOO_SERVICE_ISAWAY, session->name, buf, 0); | |
| 190 } | |
| 191 | |
| 192 int yahoo_back(struct yahoo_session *session, enum yahoo_status status, char *msg) | |
| 193 { | |
| 194 struct yahoo_conn *conn; | |
| 195 char buf[1024]; | |
| 196 | |
| 197 if (!session) | |
| 198 return 0; | |
| 199 | |
| 200 if (!(conn = yahoo_getconn_type(session, YAHOO_CONN_TYPE_MAIN))) | |
| 201 return 0; | |
| 202 | |
| 203 g_snprintf(buf, sizeof(buf), "%d%c%s", status, 1, msg ? msg : "---"); | |
| 204 | |
| 205 return yahoo_write_cmd(session, conn, YAHOO_SERVICE_ISBACK, session->name, buf, 0); | |
| 206 } |
