Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/dll/aim/toc/test/main.c
1074 views
1
#include <stdlib.h>
2
#include <stdio.h>
3
#include <time.h>
4
#include <stdarg.h>
5
#include <unistd.h>
6
#include "toc.h"
7
8
extern int state;
9
int sfd;
10
int (*cb)(int);
11
12
int toc_got_im(char **args) {
13
printf("msg: %s %s",args[0],args[1]);
14
return 1;
15
}
16
17
int toc_remove_input_stream(int fd) {
18
return 1;
19
}
20
21
int toc_add_input_stream(int fd,int (*func)(int)) {
22
sfd = fd;
23
cb = func;
24
printf("got input stream!\n");
25
return 1;
26
}
27
28
void statusput(char *buf) {
29
printf("%s\n",buf);
30
}
31
32
void statusprintf(char *fmt, ...)
33
{
34
char data[MAX_OUTPUT_MSG_LEN];
35
va_list ptr;
36
va_start(ptr, fmt);
37
vsnprintf(data, MAX_OUTPUT_MSG_LEN - 1 , fmt, ptr);
38
va_end(ptr);
39
statusput(data);
40
return;
41
}
42
43
int main(int argc, char **argv) {
44
fd_set set;
45
init_toc();
46
printf("state: %d\n",state);
47
toc_login(argv[1],argv[2]);
48
install_handler(TOC_IM_IN,&toc_got_im);
49
printf("back from toc login call!\n");
50
while ( 1 ) {
51
FD_SET(sfd,&set);
52
if ( select(sfd+1,&set,NULL,NULL,NULL) ) {
53
if ( FD_ISSET(sfd,&set) ) {
54
printf("data on sock!\n");
55
cb(sfd);
56
}
57
}
58
FD_ZERO(&set);
59
}
60
return 1;
61
}
62
63