]> code.citadel.org Git - citadel.git/blob - citadel/client_icq.c
* Remove nulls appended to editor files during replace, edit, and print
[citadel.git] / citadel / client_icq.c
1 /*
2  * Citadel/UX
3  *
4  * client_icq.c  --  manage Citadel ICQ configuration
5  *                    (the "single process" version - no more fork() anymore)
6  *
7  * $Id$
8  *
9  */
10
11 #include "sysdep.h"
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <stdio.h>
15 #include <fcntl.h>
16 #include <ctype.h>
17 #include <string.h>
18 #include <signal.h>
19 #include <errno.h>
20 #include <sys/time.h>
21 #include <sys/types.h>
22 #include <stdarg.h>
23 #include "citadel.h"
24 #include "client_chat.h"
25 #include "commands.h"
26 #include "routines.h"
27 #include "ipc.h"
28 #include "citadel_decls.h"
29 #include "tools.h"
30 #ifndef HAVE_SNPRINTF
31 #include "snprintf.h"
32 #endif
33
34 extern struct CtdlServInfo serv_info;
35 extern char temp[];
36 void getline(char *, int);
37
38 struct icq_contact {
39         long uin;
40         char name[256];
41 };
42
43
44 /* 
45  * Do the Citadel ICQ client setup
46  */
47 void setup_icq(void) {
48         char uin[32];
49         char pass[32];
50         char buf[256];
51         int i;
52         
53         struct icq_contact *contacts = NULL;
54         int num_contacts = 0;   
55         
56
57         printf("Do you want to enter your ICQ uin and password? ");
58         if (yesno()) {
59                 newprompt("     Enter your ICQ UIN: ", uin, 31);
60                 newprompt("Enter your ICQ password: ", pass, -31); 
61                 if (atol(uin)<=0L) {
62                         printf("You must enter a UIN.  "
63                                 "Citadel ICQ configuration aborted.\n");
64                         return;
65                 }
66                 sprintf(buf, "CICQ login|%s|%s|", uin, pass);
67                 serv_puts(buf);
68                 serv_gets(buf);
69                 printf("%s\n", &buf[4]);
70                 if (buf[0] != '2') return;
71         }
72
73         printf("Do you want to edit your ICQ contact list? ");
74         if (yesno()) {
75                 serv_puts("CICQ getcl");
76                 serv_gets(buf);
77                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
78                         contacts = realloc(contacts,
79                                 (++num_contacts * sizeof(struct icq_contact)));
80                         contacts[num_contacts-1].uin =
81                                 extract_long(buf, 0);
82                         extract(contacts[num_contacts-1].name, buf, 1);
83                 }
84                 if (num_contacts) for (i=0; i<num_contacts; ++i) {
85                         color(BRIGHT_WHITE);
86                         printf("%10ld ", contacts[i].uin);
87                         color(DIM_WHITE);
88                         printf("(");
89                         color(BRIGHT_CYAN);
90                         printf("%32s", contacts[i].name);
91                         color(DIM_WHITE);
92                         printf(") ... ");
93                         color(BRIGHT_YELLOW);
94                         printf("Keep (yes/no) ? ");
95                         color(DIM_WHITE);
96                         if (!yesno()) contacts[i].uin = 0L;
97                 }
98
99                 printf("Enter the UIN's of any additional contacts you\n");
100                 printf("wish to add.  Enter a blank line when finished.\n");
101                 do {
102                         newprompt("> ", buf, 32);
103                         if (atol(buf) > 0L) {
104                                 contacts = realloc(contacts,
105                                         (++num_contacts * sizeof(struct icq_contact)));
106                                 contacts[num_contacts-1].uin = atoi(buf);
107                         }
108                 } while (strlen(buf) > 0);
109
110                 serv_puts("CICQ putcl");
111                 serv_gets(buf);
112                 if (buf[0]=='4') {
113                         if (num_contacts) for (i=0; i<num_contacts; ++i) {
114                                 sprintf(buf, "%ld", contacts[i].uin);
115                                 serv_puts(buf);
116                         }
117                         if (num_contacts) free(contacts);
118                         serv_puts("000");
119                 }
120         }
121 }