annotate mcabber/main.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 da1fb510081e
rev   line source
0
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
1 #include <stdio.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
2 #include <stdlib.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
3 #include <unistd.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
4 #include <string.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
5 #include <signal.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
6 #include <termios.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
7
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
8 #include "utils.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
9 #include "screen.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
10 #include "buddies.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
11 #include "parsecfg.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
12 #include "lang.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 "socket.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
16
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
17 int sock;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
18
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
19 void sig_handler(int signum)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
20 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
21 switch (signum) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
22 case SIGALRM:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
23 sk_send(sock, " ");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
24 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
25
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
26 case SIGTERM:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
27 bud_TerminateBuddies();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
28 scr_TerminateCurses();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
29 srv_setpresence(sock, "unavailable");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
30 close(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
31 printf("Killed by SIGTERM\nBye!\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
32 exit(EXIT_SUCCESS);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
33 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
34
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
35 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
36 signal(SIGALRM, sig_handler);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
37 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
38
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
39 ssize_t my_getpass (char **passstr, size_t *n)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
40 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
41 struct termios orig, new;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
42 int nread;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
43
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
44 /* Turn echoing off and fail if we can't. */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
45 if (tcgetattr(fileno (stdin), &orig) != 0)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
46 return -1;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
47 new = orig;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
48 new.c_lflag &= ~ECHO;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
49 if (tcsetattr(fileno (stdin), TCSAFLUSH, &new) != 0)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
50 return -1;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
51
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
52 /* Read the password. */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
53 nread = getline(passstr, n, stdin);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
54
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
55 /* Restore terminal. */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
56 (void) tcsetattr(fileno (stdin), TCSAFLUSH, &orig);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
57
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
58 return nread;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
59 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
60
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
61 void credits(void)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
62 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
63 printf(VERSION "\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
64 printf(EMAIL "\n");
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 int main(int argc, char **argv)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
68 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
69 int i;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
70 char configFile[4096];
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
71 char *buffer;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
72 char *secbuffer;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
73 char *username, *password, *resource;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
74 char *servername;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
75 char *idsession;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
76 char *portstring;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
77 int key;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
78 unsigned int port;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
79 unsigned int ping;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
80
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
81
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
82 credits();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
83
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
84 /* SET THIS >0 TO ENABLE LOG */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
85 ut_InitDebug(1);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
86
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
87 lng_InitLanguage();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
88
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
89 ut_WriteLog("Setting signals handlers...\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
90 signal(SIGTERM, sig_handler);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
91 signal(SIGALRM, sig_handler);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
92
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
93
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
94 sprintf(configFile, "%s/.mcabberrc", getenv("HOME"));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
95
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
96 /* Proceso opciones de usuario */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
97 while (1) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
98 int c = getopt(argc, argv, "hf:");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
99 if (c == -1) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
100 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
101 } else
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
102 switch (c) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
103 case 'h':
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
104 printf("Usage: %s [-f mcabberrc_file]\n\n", argv[0]);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
105 printf("Thanks to AjMacias for cabber!\n\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
106 return 0;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
107 case 'f':
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
108 strncpy(configFile, optarg, 1024);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
109 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
110 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
111 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
112
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
113 ut_WriteLog("Setting config file: %s\n", configFile);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
114
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
115
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
116 /* Parsing config file... */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
117 ut_WriteLog("Parsing config file...\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
118 cfg_file(configFile);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
119
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
120 servername = cfg_read("server");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
121 username = cfg_read("username");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
122 password = cfg_read("password");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
123 resource = cfg_read("resource");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
124
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
125 if (!servername) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
126 printf("Server name has not been specified in the config file!\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
127 return -1;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
128 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
129 if (!username) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
130 printf("User name has not been specified in the config file!\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
131 return -1;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
132 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
133 if (!password) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
134 char *p;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
135 size_t passsize = 64;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
136 printf("Please enter password: ");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
137 my_getpass(&password, &passsize);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
138 printf("\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
139 for (p = password; *p; p++);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
140 for ( ; p > password ; p--)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
141 if (*p == '\n' || *p == '\r') *p = 0;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
142 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
143
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
144 /* Initialize N-Curses */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
145 ut_WriteLog("Initializing N-Curses...\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
146 scr_InitCurses();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
147
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
148 /* Connect to server */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
149 portstring = cfg_read("port");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
150 port = (portstring != NULL) ? atoi(portstring) : -1;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
151
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
152 ut_WriteLog("Connecting to server: %s:%d\n", servername, port);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
153 if ((sock = srv_connect(servername, port)) < 0) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
154 ut_WriteLog("\terror!!!\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
155 fprintf(stderr, "Error connecting to (%s)\n", servername);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
156 scr_TerminateCurses();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
157 return -2;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
158 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
159
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
160 ut_WriteLog("Sending login string...\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
161 if ((idsession = srv_login(sock, servername, username, password,
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
162 resource)) == NULL) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
163
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
164 ut_WriteLog("\terror!!!\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
165 fprintf(stderr, "Error sending login string...\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
166 scr_TerminateCurses();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
167 return -3;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
168 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
169 ut_WriteLog("Connected to %s: %s\n", servername, idsession);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
170 free(idsession);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
171
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
172 ut_WriteLog("Requesting roster...\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
173 bud_InitBuddies(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
174
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
175 ut_WriteLog("Sending presence...\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
176 srv_setpresence(sock, "Online!");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
177
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
178
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
179 ut_WriteLog("Drawing main window...\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
180 scr_DrawMainWindow();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
181
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
182 ping = 15;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
183 if (cfg_read("pinginterval"))
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
184 ping = atoi(cfg_read("pinginterval"));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
185
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
186 ut_WriteLog("Ping interval stablished: %d secs\n", ping);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
187
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
188 ut_WriteLog("Entering into main loop...\n\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
189 ut_WriteLog("Ready to send/receive messages...\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
190 key = 0;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
191 while (key != 'x') {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
192 int x;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
193 alarm(ping);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
194 x = check_io(sock, 0);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
195 if ((x & 1) == 1) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
196 srv_msg *incoming = readserver(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
197
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
198 switch (incoming->m) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
199 case SM_PRESENCE:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
200 bud_SetBuddyStatus(incoming->from, incoming->connected);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
201 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
202
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
203 case SM_MESSAGE:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
204 scr_WriteIncomingMessage(incoming->from, incoming->body);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
205 free(incoming->body);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
206 free(incoming->from);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
207 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
208
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
209 case SM_UNHANDLED:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
210 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
211 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
212 free(incoming);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
213 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
214 if ((x & 2) == 2) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
215 keypad(scr_GetRosterWindow(), TRUE);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
216 key = scr_Getch();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
217 switch (key) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
218 case KEY_IC:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
219 bud_AddBuddy(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
220 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
221 case KEY_DC:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
222 bud_DeleteBuddy(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
223 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
224 case KEY_DOWN:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
225 bud_RosterDown();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
226 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
227 case KEY_UP:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
228 bud_RosterUp();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
229 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
230
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
231 case 0x19a:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
232 endwin();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
233 printf("\nRedimensionado no implementado\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
234 printf("Reinicie Cabber.\n\n\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
235 exit(EXIT_FAILURE);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
236 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
237
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
238 case KEY_NPAGE:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
239 for (i = 0; i < 10; i++)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
240 bud_RosterDown();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
241 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
242
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
243 case KEY_PPAGE:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
244 for (i = 0; i < 10; i++)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
245 bud_RosterUp();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
246 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
247
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
248 case 'z':
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
249 case KEY_F(1):
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
250 buffer = (char *) calloc(1, 4096);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
251 secbuffer = (char *) calloc(1, 4096);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
252
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
253 sprintf(secbuffer, "INS = %s ", i18n("Add contact"));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
254 i = strlen(secbuffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
255 strcpy(buffer, secbuffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
256 sprintf(secbuffer, "DEL = %s ", i18n("Delete contact"));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
257 strcat(buffer, secbuffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
258 sprintf(secbuffer, "SPACE = %s ", i18n("View buddy window"));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
259 strcat(buffer, secbuffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
260 sprintf(secbuffer, "INTRO = %s ", i18n("Send message"));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
261 strcat(buffer, secbuffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
262 sprintf(secbuffer, "ESC = %s ", i18n("Exit"));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
263 strcat(buffer, secbuffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
264
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
265 scr_CreatePopup(i18n("help"), buffer, i, 0, NULL);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
266 free(buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
267 free(secbuffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
268 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
269
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
270 case '\n':
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
271 scr_WriteMessage(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
272 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
273
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
274 case ' ':
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
275 scr_ShowBuddyWindow();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
276 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
277 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
278 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
279 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
280
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
281 bud_TerminateBuddies();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
282 scr_TerminateCurses();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
283
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
284 srv_setpresence(sock, "unavailable");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
285
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
286 close(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
287
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
288 printf("\n\nHave a nice day!\nBye!\n");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
289
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
290 return 0;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
291 }