Make the test client quit when it has authenticated.
[doldaconnect.git] / clients / test.c
CommitLineData
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
cb972e81
FT
8int done;
9
d3372da9 10void authcallback(int err, wchar_t *reason, void *data)
11{
12 printf("Logged in: %i\n", err);
cb972e81 13 dc_queuecmd(NULL, NULL, L"quit", NULL);
d3372da9 14}
15
16int main(int argc, char **argv)
17{
d3372da9 18 struct pollfd pfd;
cb972e81 19 int fd;
d3372da9 20 struct dc_response *resp;
d3372da9 21
22 dc_init();
65bf229b 23 fd = dc_connect(NULL);
d3372da9 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 {
bf46d8f1 42 if(!wcscmp(resp->cmdname, L".connect"))
d3372da9 43 {
1157d12b 44 printf("Connected: %i\n", resp->code);
e5c8b0ca 45 if(resp->code == 201)
1157d12b 46 dc_loginasync(NULL, 1, NULL, authcallback, NULL);
d3372da9 47 }
48 dc_freeresp(resp);
49 }
50 }
51 dc_cleanup();
52 return(0);
53}