Make the test client quit when it has authenticated.
[doldaconnect.git] / clients / test.c
... / ...
CommitLineData
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
8int done;
9
10void authcallback(int err, wchar_t *reason, void *data)
11{
12 printf("Logged in: %i\n", err);
13 dc_queuecmd(NULL, NULL, L"quit", NULL);
14}
15
16int main(int argc, char **argv)
17{
18 struct pollfd pfd;
19 int fd;
20 struct dc_response *resp;
21
22 dc_init();
23 fd = dc_connect(NULL);
24 done = 0;
25 while(!done)
26 {
27 pfd.fd = fd;
28 pfd.events = POLLIN;
29 if(dc_wantwrite())
30 pfd.events = POLLOUT;
31 if(poll(&pfd, 1, -1) < 0)
32 {
33 perror("poll");
34 exit(1);
35 }
36 if((pfd.revents & POLLIN) && dc_handleread())
37 done = 1;
38 if((pfd.revents & POLLOUT) && dc_handlewrite())
39 done = 1;
40 while((resp = dc_getresp()) != NULL)
41 {
42 if(!wcscmp(resp->cmdname, L".connect"))
43 {
44 printf("Connected: %i\n", resp->code);
45 if(resp->code == 201)
46 dc_loginasync(NULL, 1, NULL, authcallback, NULL);
47 }
48 dc_freeresp(resp);
49 }
50 }
51 dc_cleanup();
52 return(0);
53}