]>
Commit | Line | Data |
---|---|---|
d3372da9 | 1 | #include <stdio.h> |
2 | #include <stdlib.h> | |
3 | #include <sys/poll.h> | |
4 | ||
5 | #include <doldaconnect/uilib.h> | |
6 | #include <doldaconnect/uimisc.h> | |
7 | ||
8 | void authcallback(int err, wchar_t *reason, void *data) | |
9 | { | |
10 | printf("Logged in: %i\n", err); | |
11 | } | |
12 | ||
13 | int main(int argc, char **argv) | |
14 | { | |
15 | int i; | |
16 | struct pollfd pfd; | |
17 | int fd, done; | |
18 | struct dc_response *resp; | |
19 | struct dc_intresp *ires; | |
20 | ||
21 | dc_init(); | |
65bf229b | 22 | fd = dc_connect(NULL); |
d3372da9 | 23 | done = 0; |
24 | while(!done) | |
25 | { | |
26 | pfd.fd = fd; | |
27 | pfd.events = POLLIN; | |
28 | if(dc_wantwrite()) | |
29 | pfd.events = POLLOUT; | |
30 | if(poll(&pfd, 1, -1) < 0) | |
31 | { | |
32 | perror("poll"); | |
33 | exit(1); | |
34 | } | |
35 | if((pfd.revents & POLLIN) && dc_handleread()) | |
36 | done = 1; | |
37 | if((pfd.revents & POLLOUT) && dc_handlewrite()) | |
38 | done = 1; | |
39 | while((resp = dc_getresp()) != NULL) | |
40 | { | |
bf46d8f1 | 41 | if(!wcscmp(resp->cmdname, L".connect")) |
d3372da9 | 42 | { |
1157d12b | 43 | printf("Connected: %i\n", resp->code); |
44 | if(resp->code == 200) | |
45 | dc_loginasync(NULL, 1, NULL, authcallback, NULL); | |
d3372da9 | 46 | } |
47 | dc_freeresp(resp); | |
48 | } | |
49 | } | |
50 | dc_cleanup(); | |
51 | return(0); | |
52 | } |