masqmail

diff 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
line diff
     1.1 --- a/src/libident/ident.c	Mon Oct 27 16:21:27 2008 +0100
     1.2 +++ b/src/libident/ident.c	Mon Oct 27 16:23:10 2008 +0100
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 -** ident.c	High-level calls to the ident lib
     1.6 +** ident.c  High-level calls to the ident lib
     1.7  **
     1.8  ** Author: Pär Emanuelsson <pell@lysator.liu.se>
     1.9  ** Hacked by: Peter Eriksson <pen@lysator.liu.se>
    1.10 @@ -31,125 +31,106 @@
    1.11  
    1.12  /* Do a complete ident query and return result */
    1.13  
    1.14 -IDENT *ident_lookup __P2(int, fd,
    1.15 -			 int, timeout)
    1.16 +IDENT*
    1.17 +ident_lookup __P2(int, fd, int, timeout)
    1.18  {
    1.19 -    struct sockaddr_in localaddr, remoteaddr;
    1.20 -    int len;
    1.21 -    
    1.22 -    len = sizeof(remoteaddr);
    1.23 -    if (getpeername(fd, (struct sockaddr*) &remoteaddr, &len) < 0)
    1.24 -	return 0;
    1.25 -    
    1.26 -    len = sizeof(localaddr);
    1.27 -    if (getsockname(fd, (struct sockaddr *) &localaddr, &len) < 0)
    1.28 -	return 0;
    1.29 +	struct sockaddr_in localaddr, remoteaddr;
    1.30 +	int len;
    1.31  
    1.32 -    return ident_query( &localaddr.sin_addr, &remoteaddr.sin_addr,
    1.33 -		       ntohs(localaddr.sin_port), ntohs(remoteaddr.sin_port),
    1.34 -		       timeout);
    1.35 +	len = sizeof(remoteaddr);
    1.36 +	if (getpeername(fd, (struct sockaddr *) &remoteaddr, &len) < 0)
    1.37 +		return 0;
    1.38 +
    1.39 +	len = sizeof(localaddr);
    1.40 +	if (getsockname(fd, (struct sockaddr *) &localaddr, &len) < 0)
    1.41 +		return 0;
    1.42 +
    1.43 +	return ident_query(&localaddr.sin_addr, &remoteaddr.sin_addr, ntohs(localaddr.sin_port), ntohs(remoteaddr.sin_port), timeout);
    1.44  }
    1.45  
    1.46  
    1.47 -IDENT *ident_query __P5(struct in_addr *, laddr,
    1.48 -			struct in_addr *, raddr,
    1.49 -			int, lport,
    1.50 -			int, rport,
    1.51 -			int, timeout)
    1.52 +IDENT*
    1.53 +ident_query __P5(struct in_addr *, laddr, struct in_addr *, raddr, int, lport, int, rport, int, timeout)
    1.54  {
    1.55 -    int res;
    1.56 -    ident_t *id;
    1.57 -    struct timeval timout;
    1.58 -    IDENT *ident=0;
    1.59 +	int res;
    1.60 +	ident_t *id;
    1.61 +	struct timeval timout;
    1.62 +	IDENT *ident = 0;
    1.63  
    1.64 -    
    1.65 -    timout.tv_sec = timeout;
    1.66 -    timout.tv_usec = 0;
    1.67 -    
    1.68 -    if (timeout)
    1.69 -	id = id_open( laddr, raddr, &timout);
    1.70 -    else
    1.71 -	id = id_open( laddr, raddr, (struct timeval *)0);
    1.72 -    
    1.73 -    if (!id)
    1.74 -    {
    1.75 -	errno = EINVAL;
    1.76 -	return 0;
    1.77 -    }
    1.78 -  
    1.79 -    if (timeout)
    1.80 -	res = id_query(id, rport, lport, &timout);
    1.81 -    else
    1.82 -	res = id_query(id, rport, lport, (struct timeval *) 0);
    1.83 -    
    1.84 -    if (res < 0)
    1.85 -    {
    1.86 +
    1.87 +	timout.tv_sec = timeout;
    1.88 +	timout.tv_usec = 0;
    1.89 +
    1.90 +	if (timeout)
    1.91 +		id = id_open(laddr, raddr, &timout);
    1.92 +	else
    1.93 +		id = id_open(laddr, raddr, (struct timeval *) 0);
    1.94 +
    1.95 +	if (!id) {
    1.96 +		errno = EINVAL;
    1.97 +		return 0;
    1.98 +	}
    1.99 +
   1.100 +	if (timeout)
   1.101 +		res = id_query(id, rport, lport, &timout);
   1.102 +	else
   1.103 +		res = id_query(id, rport, lport, (struct timeval *) 0);
   1.104 +
   1.105 +	if (res < 0) {
   1.106 +		id_close(id);
   1.107 +		return 0;
   1.108 +	}
   1.109 +
   1.110 +	ident = (IDENT *) malloc(sizeof(IDENT));
   1.111 +	if (!ident) {
   1.112 +		id_close(id);
   1.113 +		return 0;
   1.114 +	}
   1.115 +
   1.116 +	if (timeout)
   1.117 +		res = id_parse(id, &timout, &ident->lport, &ident->fport, &ident->identifier, &ident->opsys, &ident->charset);
   1.118 +	else
   1.119 +		res = id_parse(id, (struct timeval *) 0, &ident->lport, &ident->fport, &ident->identifier, &ident->opsys, &ident->charset);
   1.120 +
   1.121 +	if (res != 1) {
   1.122 +		free(ident);
   1.123 +		id_close(id);
   1.124 +		return 0;
   1.125 +	}
   1.126 +
   1.127  	id_close(id);
   1.128 -	return 0;
   1.129 -    }
   1.130 -    
   1.131 -    ident = (IDENT *) malloc(sizeof(IDENT));
   1.132 -    if (!ident) {
   1.133 -	id_close(id);
   1.134 -	return 0;
   1.135 -    }
   1.136 -    
   1.137 -    if (timeout)
   1.138 -	res = id_parse(id, &timout,
   1.139 -		       &ident->lport,
   1.140 -		       &ident->fport,
   1.141 -		       &ident->identifier,
   1.142 -		       &ident->opsys,
   1.143 -		       &ident->charset);
   1.144 -    else
   1.145 -	res = id_parse(id, (struct timeval *) 0,
   1.146 -		       &ident->lport,
   1.147 -		       &ident->fport,
   1.148 -		       &ident->identifier,
   1.149 -		       &ident->opsys,
   1.150 -		       &ident->charset);
   1.151 -    
   1.152 -    if (res != 1)
   1.153 -    {
   1.154 -	free(ident);
   1.155 -	id_close(id);
   1.156 -	return 0;
   1.157 -    }
   1.158 -    
   1.159 -    id_close(id);
   1.160 -    return ident;			/* At last! */
   1.161 +	return ident;  /* At last! */
   1.162  }
   1.163  
   1.164  
   1.165 -char *ident_id __P2(int, fd,
   1.166 -		    int, timeout)
   1.167 +char*
   1.168 +ident_id __P2(int, fd, int, timeout)
   1.169  {
   1.170 -    IDENT *ident;
   1.171 -    char *id=0;
   1.172 -    
   1.173 -    ident = ident_lookup(fd, timeout);
   1.174 -    if (ident && ident->identifier && *ident->identifier)
   1.175 -    {
   1.176 -	id = id_strdup(ident->identifier);
   1.177 -	if (id == NULL)
   1.178 -	    return NULL;
   1.179 -    }
   1.180 +	IDENT *ident;
   1.181 +	char *id = 0;
   1.182  
   1.183 -    ident_free(ident);
   1.184 -    return id;
   1.185 +	ident = ident_lookup(fd, timeout);
   1.186 +	if (ident && ident->identifier && *ident->identifier) {
   1.187 +		id = id_strdup(ident->identifier);
   1.188 +		if (id == NULL)
   1.189 +			return NULL;
   1.190 +	}
   1.191 +
   1.192 +	ident_free(ident);
   1.193 +	return id;
   1.194  }
   1.195  
   1.196  
   1.197 -void ident_free __P1(IDENT *, id)
   1.198 +void
   1.199 +ident_free __P1(IDENT *, id)
   1.200  {
   1.201 -    if (!id)
   1.202 -	return;
   1.203 -    if (id->identifier)
   1.204 -	free(id->identifier);
   1.205 -    if (id->opsys)
   1.206 -	free(id->opsys);
   1.207 -    if (id->charset)
   1.208 -	free(id->charset);
   1.209 -    free(id);
   1.210 +	if (!id)
   1.211 +		return;
   1.212 +	if (id->identifier)
   1.213 +		free(id->identifier);
   1.214 +	if (id->opsys)
   1.215 +		free(id->opsys);
   1.216 +	if (id->charset)
   1.217 +		free(id->charset);
   1.218 +	free(id);
   1.219  }
   1.220 -