File: register.c

package info (click to toggle)
libgadu 1:1.9.0-2+squeeze2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,828 kB
  • ctags: 735
  • sloc: ansic: 10,507; sh: 10,195; perl: 320; makefile: 161
file content (100 lines) | stat: -rw-r--r-- 1,987 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* $Id: register.c 299 2002-02-06 21:40:00Z wojtekka $ */

#include <stdio.h>
#include <string.h>
#include "libgadu.h"

#ifdef ASYNC

#include <sys/select.h>
#include <sys/wait.h>
#include <signal.h>
#include <errno.h>

void sigchld(int sig)
{
	wait(NULL);
	signal(SIGCHLD, sigchld);
}

#endif

int main(int argc, char **argv)
{
	struct gg_http *h;
	struct gg_pubdir *p;
	const char *email;
	const char *password;
	const char *tokenid;
	const char *tokenval;

	if (argc < 5) {
		printf("Użycie: %s <e-mail> <hasło> <id-tokenu> <wartość-tokenu>\n", argv[0]);
		return 1;
	}

	email = argv[1];
	password = argv[2];
	tokenid = argv[3];
	tokenval = argv[4];

	gg_debug_level = 255;
	
#ifndef ASYNC
	if (!(h = gg_register3(email, password, tokenid, tokenval, 0))) {
		printf("Błąd rejestracji.\n");
		return 1;
	}

#else

	signal(SIGCHLD, sigchld);

	if (!(h = gg_register3(email, password, tokenid, tokenval, 1)))
		return 1;

        while (1) {
                fd_set rd, wr, ex;

                FD_ZERO(&rd);
                FD_ZERO(&wr);
                FD_ZERO(&ex);

                if ((h->check & GG_CHECK_READ))
                        FD_SET(h->fd, &rd);
                if ((h->check & GG_CHECK_WRITE))
                        FD_SET(h->fd, &wr);
                FD_SET(h->fd, &ex);

                if (select(h->fd + 1, &rd, &wr, &ex, NULL) == -1 || FD_ISSET(h->fd, &ex)) {
			if (errno == EINTR)
				continue;
			gg_free_register(h);
			perror("select");
			return 1;
		}

                if (FD_ISSET(h->fd, &rd) || FD_ISSET(h->fd, &wr)) {
			if (gg_register_watch_fd(h) == -1) {
				gg_free_register(h);
				fprintf(stderr, "Błąd połączenia.\n");
				return 1;
			}
			if (h->state == GG_STATE_ERROR) {
				gg_free_register(h);
				fprintf(stderr, "Błąd rejestracji.\n");
				return 1;
			}
			if (h->state == GG_STATE_DONE)
				break;
		}
        }
#endif

	p = h->data;
	printf("success=%d\nuin=%d\n", p->success, p->uin);
	gg_free_register(h);

	return 0;
}