annotate mcabber/server.c @ 0:b3b2332715fb

Tailorization of /trunk Import of the upstream sources from Repository: file:///tmp/svn-mcabber Module: /trunk Revision: 15
author tailor@frmp8452
date Thu, 30 Jun 2005 21:39:31 +0000
parents
children 7eeda3a06b21
rev   line source
0
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
1 #include <arpa/inet.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
2 #include <netdb.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
3 #include <stdio.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
4 #include <stdlib.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
5 #include <string.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
6 #include <sys/poll.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
7
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
8 #include "list.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
9 #include "parsecfg.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
10 #include "screen.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
11 #include "socket.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
12 #include "utf8.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
13 #include "server.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
14 #include "harddefines.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
15 #include "utils.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
16 #include "buddies.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
17
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
18 #define JABBERPORT 5222
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
19
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
20
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
21 /* Desc: poll data from server
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
22 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
23 * In : socket
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
24 * Out : pending buffer (or NULL if no incoming data)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
25 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
26 * Note: it is up to the caller to free the returned string
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
27 */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
28 char *srv_poll(int sock)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
29 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
30 struct pollfd sock_p;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
31 sock_p.fd = sock;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
32 sock_p.events = POLLIN | POLLPRI;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
33 sock_p.revents = 0;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
34 poll(&sock_p, 1, 0);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
35
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
36 if (sock_p.revents) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
37 return sk_recv(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
38 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
39
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
40 return NULL;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
41 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
42
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
43
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
44 /* Desc: resolve host
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
45 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
46 * In : hostname
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
47 * Out : 32bit address (or 0 if error)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
48 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
49 * Note: -
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
50 */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
51 static u_long srv_resolve(const char *host)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
52 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
53 long i;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
54 struct hostent *he;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
55
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
56 if ((i = inet_addr(host)) == -1) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
57 if (!(he = gethostbyname(host)))
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
58 return 0;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
59 else
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
60 return (*(u_long *) he->h_addr);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
61 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
62
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
63 return i;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
64 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
65
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
66
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
67 /* Desc: connect to jabber server
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
68 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
69 * In : config
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
70 * Out : socket (or -1 on error)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
71 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
72 * Note: if port is -1, the default Jabber port will be used
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
73 */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
74 int srv_connect(const char *server, unsigned int port)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
75 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
76 struct sockaddr_in name;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
77 int sock;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
78
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
79 if (server == NULL) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
80 fprintf(stderr, "You must supply a server name\n\r");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
81 return -1;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
82 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
83
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
84 if (port == -1U) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
85 port = JABBERPORT;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
86 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
87
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
88 name.sin_family = AF_INET;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
89 name.sin_port = htons(port);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
90
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
91 if (!(name.sin_addr.s_addr = srv_resolve(server))) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
92 fprintf(stderr, "Cant resolve \"%s\"\n", server);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
93 return -1;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
94 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
95
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
96 if ((sock = sk_conn((struct sockaddr *) &name)) < 0) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
97 fprintf(stderr, "Cant connect to \"%s:%u\"\n", server, port);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
98 return -1;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
99 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
100
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
101 return sock;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
102 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
103
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
104
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
105 /* Desc: login into jabber server
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
106 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
107 * In : socket, servername, user, password, resource
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
108 * Out : idsession
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
109 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
110 * Note: it is up to the caller to free the returned string
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
111 */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
112 char *srv_login(int sock, const char *server, const char *user,
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
113 const char *pass, const char *resource)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
114 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
115 char *stringtosend = malloc(2048);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
116 char *response, *aux;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
117 char *idsession = malloc(128);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
118 int pos = 0;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
119
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
120 memset(stringtosend, 0, 2048);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
121 strcpy(stringtosend, "<?xml version='1.0' encoding='UTF-8' ?>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
122 strcat(stringtosend, "<stream:stream to='");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
123 strcat(stringtosend, server);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
124 strcat(stringtosend, "' xmlns='jabber:client' xmlns:stream='");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
125 strcat(stringtosend, "http://etherx.jabber.org/streams'>\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
126
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
127 if (!sk_send(sock, stringtosend)) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
128 perror("senddata (server.c:132)");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
129 return NULL;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
130 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
131 response = sk_recv(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
132 if (strstr(response, "error")) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
133 /* fprintf(stderr, "Response not valid:\n%s\n\n", response); */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
134 scr_CreatePopup("Error",
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
135 "El servidor no esta respondiendo correctamente",
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
136 60, 0, NULL);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
137 return NULL;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
138 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
139 aux = response;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
140 while (strncmp(aux, "id", 2))
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
141 aux++;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
142 pos = 0;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
143 aux += 4;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
144 while (strncmp(aux, "'", 1)) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
145 aux++;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
146 pos++;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
147 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
148 aux -= pos;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
149 strncpy(idsession, aux, pos);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
150
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
151 free(response);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
152
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
153 strcpy(stringtosend, "<iq type='set' id='1000'>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
154 strcat(stringtosend, "<query xmlns='jabber:iq:auth'>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
155 strcat(stringtosend, "<username>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
156 strcat(stringtosend, user);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
157 strcat(stringtosend, "</username><password>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
158 strcat(stringtosend, pass);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
159 strcat(stringtosend, "</password><resource>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
160 strcat(stringtosend, resource);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
161 strcat(stringtosend, "</resource></query></iq>\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
162 if (!sk_send(sock, stringtosend)) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
163 perror("senddata (server.c:167)");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
164 return NULL;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
165 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
166 response = sk_recv(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
167 if (strstr(response, "error")) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
168 /* fprintf(stderr, "Response not valid:\n%s\n\n", response);*/
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
169 scr_CreatePopup("Error",
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
170 "Cuenta no creada o contrase´┐Ża incorrecta", 60, 0,
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
171 NULL);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
172 scr_CreatePopup("Info", "Intentando crear la cuenta...", 60, 0, NULL);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
173
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
174
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
175 strcpy(stringtosend, "<iq type='set' id='reg' to='");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
176 strcat(stringtosend, server);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
177 strcat(stringtosend, "'>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
178 strcat(stringtosend, "<query xmlns='jabber:iq:register'>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
179 strcat(stringtosend, "<username>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
180 strcat(stringtosend, user);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
181 strcat(stringtosend, "</username><password>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
182 strcat(stringtosend, pass);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
183 strcat(stringtosend, "</password>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
184 strcat(stringtosend, "</query></iq>\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
185 if (!sk_send(sock, stringtosend)) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
186 perror("senddata (server.c:167)");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
187 return NULL;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
188 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
189
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
190 response = sk_recv(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
191 scr_TerminateCurses();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
192 printf("Reinicie cabber!\n\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
193 return NULL;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
194 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
195 free(response);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
196 free(stringtosend);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
197
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
198 return idsession;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
199 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
200
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
201
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
202 /* Desc: broadcast presence
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
203 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
204 * In : socket, presence string
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
205 * Out : ?
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
206 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
207 * Note: see `sk_send' for output values
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
208 */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
209 int srv_setpresence(int sock, const char *type)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
210 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
211 int rv;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
212 char *str = malloc(1024);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
213
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
214 sprintf(str, "<presence><status>%s</status></presence>", type);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
215 if (!(rv = sk_send(sock, str))) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
216 perror("senddata (server.c:199)");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
217 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
218 free(str);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
219
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
220 return rv;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
221 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
222
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
223
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
224 /* Desc: request roster
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
225 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
226 * In : socket
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
227 * Out : roster string
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
228 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
229 * Note: it is up to the caller to free the returned string
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
230 */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
231 char *srv_getroster(int sock)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
232 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
233 char *str = malloc(1024);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
234
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
235 strcpy(str, "<iq type='get' id='1001'><query xmlns='");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
236 strcat(str, "jabber:iq:roster'/></iq>\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
237 if (!sk_send(sock, str)) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
238 perror("senddata (server.c:222)");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
239 return NULL;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
240 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
241 free(str);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
242
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
243 return sk_recv(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
244 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
245
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
246
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
247 /* Desc: send text to buddy
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
248 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
249 * In : socket, destination jid, text, source jid
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
250 * Out : 0 = ok
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
251 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
252 * Note: -
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
253 */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
254 int
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
255 srv_sendtext(int sock, const char *to, const char *text, const char *from)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
256 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
257 char *stringtosend = malloc(2048);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
258 char *utf8inputline = utf8_encode(text);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
259
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
260 sprintf(stringtosend,
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
261 "<message from='%s' to='%s' type='chat'><body>%s</body></message>",
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
262 from, to, utf8inputline);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
263 if (!sk_send(sock, stringtosend)) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
264 perror("senddata (server.c:247)");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
265 return -1;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
266 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
267
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
268 free(stringtosend);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
269 free(utf8inputline);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
270 return 0;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
271 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
272
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
273 int check_io(int fd1, int fd2)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
274 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
275 int n = 0, i;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
276 fd_set fds;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
277 int io_pending = 0;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
278
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
279 i = fd1;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
280 if (fd2 > fd1)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
281 i = fd2;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
282
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
283 FD_ZERO(&fds);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
284 if (fd1 >= 0)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
285 FD_SET(fd1, &fds);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
286 else
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
287 fd1 = 0;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
288 if (fd2 >= 0)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
289 FD_SET(fd2, &fds);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
290 else
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
291 fd2 = 0;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
292
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
293 if (fd2 == 0 && io_pending)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
294 n = 2;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
295 else if (select(i + 1, &fds, NULL, NULL, NULL) > 0)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
296 n = 1 * (FD_ISSET(fd1, &fds) > 0) + 2 * (FD_ISSET(fd2, &fds) > 0);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
297
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
298 return (n);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
299 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
300
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
301 /* Desc: read data from server
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
302 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
303 * In : socket
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
304 * Out : ptr to newly allocated srv_msg struct
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
305 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
306 * Note: returns NULL if no input from server
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
307 */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
308 srv_msg *readserver(int sock)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
309 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
310 char *buffer = sk_recv(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
311
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
312 if (buffer != NULL) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
313 srv_msg *msg = calloc(1, sizeof(srv_msg));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
314 char *to = getattr(buffer, "to='");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
315 char *from = getattr(buffer, "from='");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
316 char *id = getattr(buffer, "id='");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
317 char *type = getattr(buffer, "type='");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
318 char *body = gettag(buffer, "body");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
319 char *status = gettag(buffer, "status");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
320 char *show = gettag(buffer, "show");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
321 char *line = (char *) malloc(1024);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
322 memset(line, 0, 1024);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
323
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
324 /* scan for buffer */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
325 if (!strncmp(buffer, "<message", 8)) { /* manage messages */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
326 msg->m = SM_MESSAGE;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
327 } else if (!strncmp(buffer, "<presence", 9)) { /* manage presences */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
328 msg->m = SM_PRESENCE;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
329 if (!strncmp(type, "UNK", 3)) { /* assume online */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
330 msg->connected = FLAG_BUDDY_CONNECTED;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
331 } else if (!strncmp(type, "unavailable", 11)) { /* offline */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
332 msg->connected = 0;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
333 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
334 } else {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
335 msg->m = SM_UNHANDLED;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
336 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
337
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
338 /* write the parsed buffer */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
339 switch (msg->m) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
340 case SM_MESSAGE:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
341 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
342 char *aux = strstr(from, "/");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
343 if (aux)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
344 *aux = '\0';
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
345 msg->from = from;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
346 msg->body = utf8_decode(body);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
347 ut_WriteLog("+OK [%s]\n", buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
348 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
349 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
350
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
351 case SM_PRESENCE:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
352 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
353 char *aux = strstr(from, "/");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
354 if (aux)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
355 *aux = '\0';
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
356 msg->from = from;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
357 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
358 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
359
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
360 case SM_UNHANDLED:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
361 ut_WriteLog("BAD [%s]\n", buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
362 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
363
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
364 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
365 free(line);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
366 if (strncmp(to, "UNK", 3))
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
367 free(to);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
368 if (strncmp(from, "UNK", 3) && (msg->m != SM_MESSAGE)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
369 && (msg->m != SM_PRESENCE))
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
370 free(from);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
371 if (strncmp(id, "UNK", 3))
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
372 free(id);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
373 if (strncmp(type, "UNK", 3))
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
374 free(type);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
375 if (strncmp(body, "UNK", 3))
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
376 free(body);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
377 if (strncmp(status, "UNK", 3))
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
378 free(status);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
379 if (strncmp(show, "UNK", 3))
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
380 free(show);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
381 free(buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
382
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
383 return msg;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
384 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
385
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
386 return NULL;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
387 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
388
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
389 void srv_AddBuddy(int sock, char *jidname)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
390 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
391 char *buffer = (char *) malloc(1024);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
392 char *p, *str;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
393 int i;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
394
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
395 memset(buffer, 0, 1024);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
396 strcpy(buffer, "<iq type='set'>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
397 strcat(buffer, " <query xmlns='jabber:iq:roster'>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
398 strcat(buffer, " <item");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
399 strcat(buffer, " jid='");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
400 strcat(buffer, jidname);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
401 strcat(buffer, "' name='");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
402
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
403 str = strdup(jidname);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
404 p = strstr(str, "@");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
405 if (p)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
406 *p = '\0';
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
407 strcat(buffer, str);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
408 strcat(buffer, "'/></query></iq>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
409 sk_send(sock, buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
410 free(buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
411
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
412 for (i = 0; i < 2; i++) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
413 buffer = sk_recv(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
414 ut_WriteLog("[Subscription]: %s\n", buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
415 free(buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
416 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
417
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
418 buffer = (char *) malloc(1024);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
419 memset(buffer, 0, 1024);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
420 strcpy(buffer, "<presence to='");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
421 strcat(buffer, jidname);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
422 strcat(buffer, "' type='subscribe'>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
423 strcat(buffer, "<status>I would like to add you!</status></presence>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
424 sk_send(sock, buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
425 free(buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
426
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
427 buffer = sk_recv(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
428 ut_WriteLog("[Subscription]: %s\n", buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
429 free(buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
430
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
431 buffer = (char *) malloc(1024);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
432 memset(buffer, 0, 1024);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
433 strcpy(buffer, "<presence to='");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
434 strcat(buffer, jidname);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
435 strcat(buffer, "' type='subscribed'/>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
436 sk_send(sock, buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
437 free(buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
438
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
439 buffer = sk_recv(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
440 ut_WriteLog("[Subscription]: %s\n", buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
441 free(buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
442 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
443
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
444 void srv_DelBuddy(int sock, char *jidname)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
445 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
446 char *buffer = (char *) malloc(1024);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
447
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
448 strcpy(buffer, "<iq type='set'><query xmlns='jabber:iq:roster'>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
449 strcat(buffer, "<item jid='");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
450 strcat(buffer, jidname);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
451 strcat(buffer, "' subscription='remove'/></query></iq>");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
452
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
453 sk_send(sock, buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
454 free(buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
455
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
456 buffer = sk_recv(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
457 ut_WriteLog("[SubscriptionRemove]: %s\n", buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
458 free(buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
459 }