Mercurial > masqmail
comparison src/libident/ident.c @ 10:26e34ae9a3e3
changed indention and line wrapping to a more consistent style
author | meillo@marmaro.de |
---|---|
date | Mon, 27 Oct 2008 16:23:10 +0100 |
parents | 08114f7dcc23 |
children |
comparison
equal
deleted
inserted
replaced
9:31cc8a89cb74 | 10:26e34ae9a3e3 |
---|---|
1 /* | 1 /* |
2 ** ident.c High-level calls to the ident lib | 2 ** ident.c High-level calls to the ident lib |
3 ** | 3 ** |
4 ** Author: Pär Emanuelsson <pell@lysator.liu.se> | 4 ** Author: Pär Emanuelsson <pell@lysator.liu.se> |
5 ** Hacked by: Peter Eriksson <pen@lysator.liu.se> | 5 ** Hacked by: Peter Eriksson <pen@lysator.liu.se> |
6 */ | 6 */ |
7 | 7 |
29 | 29 |
30 | 30 |
31 | 31 |
32 /* Do a complete ident query and return result */ | 32 /* Do a complete ident query and return result */ |
33 | 33 |
34 IDENT *ident_lookup __P2(int, fd, | 34 IDENT* |
35 int, timeout) | 35 ident_lookup __P2(int, fd, int, timeout) |
36 { | 36 { |
37 struct sockaddr_in localaddr, remoteaddr; | 37 struct sockaddr_in localaddr, remoteaddr; |
38 int len; | 38 int len; |
39 | |
40 len = sizeof(remoteaddr); | |
41 if (getpeername(fd, (struct sockaddr*) &remoteaddr, &len) < 0) | |
42 return 0; | |
43 | |
44 len = sizeof(localaddr); | |
45 if (getsockname(fd, (struct sockaddr *) &localaddr, &len) < 0) | |
46 return 0; | |
47 | 39 |
48 return ident_query( &localaddr.sin_addr, &remoteaddr.sin_addr, | 40 len = sizeof(remoteaddr); |
49 ntohs(localaddr.sin_port), ntohs(remoteaddr.sin_port), | 41 if (getpeername(fd, (struct sockaddr *) &remoteaddr, &len) < 0) |
50 timeout); | 42 return 0; |
43 | |
44 len = sizeof(localaddr); | |
45 if (getsockname(fd, (struct sockaddr *) &localaddr, &len) < 0) | |
46 return 0; | |
47 | |
48 return ident_query(&localaddr.sin_addr, &remoteaddr.sin_addr, ntohs(localaddr.sin_port), ntohs(remoteaddr.sin_port), timeout); | |
51 } | 49 } |
52 | 50 |
53 | 51 |
54 IDENT *ident_query __P5(struct in_addr *, laddr, | 52 IDENT* |
55 struct in_addr *, raddr, | 53 ident_query __P5(struct in_addr *, laddr, struct in_addr *, raddr, int, lport, int, rport, int, timeout) |
56 int, lport, | |
57 int, rport, | |
58 int, timeout) | |
59 { | 54 { |
60 int res; | 55 int res; |
61 ident_t *id; | 56 ident_t *id; |
62 struct timeval timout; | 57 struct timeval timout; |
63 IDENT *ident=0; | 58 IDENT *ident = 0; |
64 | 59 |
65 | 60 |
66 timout.tv_sec = timeout; | 61 timout.tv_sec = timeout; |
67 timout.tv_usec = 0; | 62 timout.tv_usec = 0; |
68 | 63 |
69 if (timeout) | 64 if (timeout) |
70 id = id_open( laddr, raddr, &timout); | 65 id = id_open(laddr, raddr, &timout); |
71 else | 66 else |
72 id = id_open( laddr, raddr, (struct timeval *)0); | 67 id = id_open(laddr, raddr, (struct timeval *) 0); |
73 | 68 |
74 if (!id) | 69 if (!id) { |
75 { | 70 errno = EINVAL; |
76 errno = EINVAL; | 71 return 0; |
77 return 0; | 72 } |
78 } | 73 |
79 | 74 if (timeout) |
80 if (timeout) | 75 res = id_query(id, rport, lport, &timout); |
81 res = id_query(id, rport, lport, &timout); | 76 else |
82 else | 77 res = id_query(id, rport, lport, (struct timeval *) 0); |
83 res = id_query(id, rport, lport, (struct timeval *) 0); | 78 |
84 | 79 if (res < 0) { |
85 if (res < 0) | 80 id_close(id); |
86 { | 81 return 0; |
82 } | |
83 | |
84 ident = (IDENT *) malloc(sizeof(IDENT)); | |
85 if (!ident) { | |
86 id_close(id); | |
87 return 0; | |
88 } | |
89 | |
90 if (timeout) | |
91 res = id_parse(id, &timout, &ident->lport, &ident->fport, &ident->identifier, &ident->opsys, &ident->charset); | |
92 else | |
93 res = id_parse(id, (struct timeval *) 0, &ident->lport, &ident->fport, &ident->identifier, &ident->opsys, &ident->charset); | |
94 | |
95 if (res != 1) { | |
96 free(ident); | |
97 id_close(id); | |
98 return 0; | |
99 } | |
100 | |
87 id_close(id); | 101 id_close(id); |
88 return 0; | 102 return ident; /* At last! */ |
89 } | |
90 | |
91 ident = (IDENT *) malloc(sizeof(IDENT)); | |
92 if (!ident) { | |
93 id_close(id); | |
94 return 0; | |
95 } | |
96 | |
97 if (timeout) | |
98 res = id_parse(id, &timout, | |
99 &ident->lport, | |
100 &ident->fport, | |
101 &ident->identifier, | |
102 &ident->opsys, | |
103 &ident->charset); | |
104 else | |
105 res = id_parse(id, (struct timeval *) 0, | |
106 &ident->lport, | |
107 &ident->fport, | |
108 &ident->identifier, | |
109 &ident->opsys, | |
110 &ident->charset); | |
111 | |
112 if (res != 1) | |
113 { | |
114 free(ident); | |
115 id_close(id); | |
116 return 0; | |
117 } | |
118 | |
119 id_close(id); | |
120 return ident; /* At last! */ | |
121 } | 103 } |
122 | 104 |
123 | 105 |
124 char *ident_id __P2(int, fd, | 106 char* |
125 int, timeout) | 107 ident_id __P2(int, fd, int, timeout) |
126 { | 108 { |
127 IDENT *ident; | 109 IDENT *ident; |
128 char *id=0; | 110 char *id = 0; |
129 | |
130 ident = ident_lookup(fd, timeout); | |
131 if (ident && ident->identifier && *ident->identifier) | |
132 { | |
133 id = id_strdup(ident->identifier); | |
134 if (id == NULL) | |
135 return NULL; | |
136 } | |
137 | 111 |
138 ident_free(ident); | 112 ident = ident_lookup(fd, timeout); |
139 return id; | 113 if (ident && ident->identifier && *ident->identifier) { |
114 id = id_strdup(ident->identifier); | |
115 if (id == NULL) | |
116 return NULL; | |
117 } | |
118 | |
119 ident_free(ident); | |
120 return id; | |
140 } | 121 } |
141 | 122 |
142 | 123 |
143 void ident_free __P1(IDENT *, id) | 124 void |
125 ident_free __P1(IDENT *, id) | |
144 { | 126 { |
145 if (!id) | 127 if (!id) |
146 return; | 128 return; |
147 if (id->identifier) | 129 if (id->identifier) |
148 free(id->identifier); | 130 free(id->identifier); |
149 if (id->opsys) | 131 if (id->opsys) |
150 free(id->opsys); | 132 free(id->opsys); |
151 if (id->charset) | 133 if (id->charset) |
152 free(id->charset); | 134 free(id->charset); |
153 free(id); | 135 free(id); |
154 } | 136 } |
155 |