Mercurial > pidgin.yaz
annotate plugins/yay/outgoing.c @ 1555:5e54c7a2a394
[gaim-migrate @ 1565]
hi
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sat, 10 Mar 2001 03:41:38 +0000 |
parents | c3afde736a8a |
children | 4a47a459cc98 |
rev | line source |
---|---|
1546 | 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 | |
1554
c3afde736a8a
[gaim-migrate @ 1564]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1546
diff
changeset
|
33 if (send(conn->socket, buf, len, 0) != len) { |
1546 | 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 CALLBACK(session, YAHOO_HANDLE_DISCONNECT); | |
39 return 0; | |
40 } | |
41 | |
42 return len; | |
43 } | |
44 | |
45 int yahoo_write_cmd(struct yahoo_session *session, struct yahoo_conn *conn, | |
46 int service, const char *active_id, void *buf, guint msgtype) | |
47 { | |
48 struct yahoo_packet *pkt; | |
49 int ret; | |
50 | |
51 if (!session || !conn) | |
52 return 0; | |
53 | |
54 if (!(pkt = g_new0(struct yahoo_packet, 1))) | |
55 return 0; | |
56 | |
57 strcpy(pkt->version, "YPNS2.0"); | |
58 yahoo_storeint(pkt->len, sizeof(struct yahoo_packet)); | |
59 yahoo_storeint(pkt->service, service); | |
60 | |
61 yahoo_storeint(pkt->magic_id, conn->magic_id); | |
62 yahoo_storeint(pkt->msgtype, msgtype); | |
63 | |
64 strcpy(pkt->nick1, session->name); | |
65 strcpy(pkt->nick2, active_id); | |
66 | |
67 strncpy(pkt->content, buf, 1024); | |
68 | |
69 ret = yahoo_write(session, conn, pkt, sizeof(struct yahoo_packet)); | |
70 g_free(pkt); | |
71 return ret; | |
72 } | |
73 | |
74 int yahoo_activate_id(struct yahoo_session *session, char *id) | |
75 { | |
76 struct yahoo_conn *conn; | |
77 | |
78 if (!session || !id) | |
79 return 0; | |
80 | |
81 if (!(conn = yahoo_getconn_type(session, YAHOO_CONN_TYPE_MAIN))) | |
82 return 0; | |
83 | |
84 return yahoo_write_cmd(session, conn, YAHOO_SERVICE_IDACT, id, id, 0); | |
85 } | |
86 | |
87 int yahoo_deactivate_id(struct yahoo_session *session, char *id) | |
88 { | |
89 struct yahoo_conn *conn; | |
90 | |
91 if (!session || !id) | |
92 return 0; | |
93 | |
94 if (!(conn = yahoo_getconn_type(session, YAHOO_CONN_TYPE_MAIN))) | |
95 return 0; | |
96 | |
97 return yahoo_write_cmd(session, conn, YAHOO_SERVICE_IDDEACT, id, id, 0); | |
98 } | |
99 | |
100 int yahoo_send_message(struct yahoo_session *session, const char *active_id, | |
101 const char *user, const char *msg) | |
102 { | |
103 struct yahoo_conn *conn; | |
104 char *buf; | |
105 int ret; | |
106 | |
107 if (!session || !user || !msg) | |
108 return 0; | |
109 | |
110 if (!(conn = yahoo_getconn_type(session, YAHOO_CONN_TYPE_MAIN))) | |
111 return 0; | |
112 | |
113 if (!(buf = g_strconcat(user, ",", msg, NULL))) | |
114 return 0; | |
115 | |
116 ret = yahoo_write_cmd(session, conn, YAHOO_SERVICE_MESSAGE, | |
117 active_id ? active_id : session->name, buf, 0); | |
118 g_free(buf); | |
119 | |
120 return ret; | |
121 } | |
122 | |
123 int yahoo_logoff(struct yahoo_session *session) | |
124 { | |
125 struct yahoo_conn *conn; | |
126 | |
127 if (!session) | |
128 return 0; | |
129 | |
130 if (!(conn = yahoo_getconn_type(session, YAHOO_CONN_TYPE_MAIN))) | |
131 return 0; | |
132 | |
133 return yahoo_write_cmd(session, conn, YAHOO_SERVICE_LOGOFF, session->name, session->name, 0); | |
134 } | |
135 | |
136 int yahoo_ping(struct yahoo_session *session) | |
137 { | |
138 struct yahoo_conn *conn; | |
139 | |
140 if (!session) | |
141 return 0; | |
142 | |
143 if (!(conn = yahoo_getconn_type(session, YAHOO_CONN_TYPE_MAIN))) | |
144 return 0; | |
145 | |
146 return yahoo_write_cmd(session, conn, YAHOO_SERVICE_PING, session->name, "", 0); | |
147 } | |
148 | |
149 int yahoo_away(struct yahoo_session *session, enum yahoo_status status, char *msg) | |
150 { | |
151 struct yahoo_conn *conn; | |
152 char buf[1024]; | |
153 | |
154 if (!session) | |
155 return 0; | |
156 | |
157 if (!(conn = yahoo_getconn_type(session, YAHOO_CONN_TYPE_MAIN))) | |
158 return 0; | |
159 | |
160 g_snprintf(buf, sizeof(buf), "%d%c%s", status, 1, msg ? msg : "---"); | |
161 | |
162 return yahoo_write_cmd(session, conn, YAHOO_SERVICE_ISAWAY, session->name, buf, 0); | |
163 } | |
164 | |
165 int yahoo_back(struct yahoo_session *session, enum yahoo_status status, char *msg) | |
166 { | |
167 struct yahoo_conn *conn; | |
168 char buf[1024]; | |
169 | |
170 if (!session) | |
171 return 0; | |
172 | |
173 if (!(conn = yahoo_getconn_type(session, YAHOO_CONN_TYPE_MAIN))) | |
174 return 0; | |
175 | |
176 g_snprintf(buf, sizeof(buf), "%d%c%s", status, 1, msg ? msg : "---"); | |
177 | |
178 return yahoo_write_cmd(session, conn, YAHOO_SERVICE_ISBACK, session->name, buf, 0); | |
179 } |