| 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 | struct pollfd pfd; |
| 16 | int fd, done; |
| 17 | struct dc_response *resp; |
| 18 | |
| 19 | dc_init(); |
| 20 | fd = dc_connect(NULL); |
| 21 | done = 0; |
| 22 | while(!done) |
| 23 | { |
| 24 | pfd.fd = fd; |
| 25 | pfd.events = POLLIN; |
| 26 | if(dc_wantwrite()) |
| 27 | pfd.events = POLLOUT; |
| 28 | if(poll(&pfd, 1, -1) < 0) |
| 29 | { |
| 30 | perror("poll"); |
| 31 | exit(1); |
| 32 | } |
| 33 | if((pfd.revents & POLLIN) && dc_handleread()) |
| 34 | done = 1; |
| 35 | if((pfd.revents & POLLOUT) && dc_handlewrite()) |
| 36 | done = 1; |
| 37 | while((resp = dc_getresp()) != NULL) |
| 38 | { |
| 39 | if(!wcscmp(resp->cmdname, L".connect")) |
| 40 | { |
| 41 | printf("Connected: %i\n", resp->code); |
| 42 | if(resp->code == 201) |
| 43 | dc_loginasync(NULL, 1, NULL, authcallback, NULL); |
| 44 | } |
| 45 | dc_freeresp(resp); |
| 46 | } |
| 47 | } |
| 48 | dc_cleanup(); |
| 49 | return(0); |
| 50 | } |