Skip to content

Commit

Permalink
more code style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarning committed Feb 14, 2018
1 parent 4da4db2 commit 8d4a2b9
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 72 deletions.
12 changes: 6 additions & 6 deletions src/ext-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static void cmd_exec(FILE *fp, const char request[], int allow_debug)
if (rc == EXIT_SUCCESS) {
// Print results
for (i = 0; i < num; ++i) {
fprintf(fp, "%s\n", str_addr( &addrs[i] ));
fprintf(fp, "%s\n", str_addr(&addrs[i]));
}

if (num == 0) {
Expand All @@ -172,10 +172,10 @@ static void cmd_exec(FILE *fp, const char request[], int allow_debug)
fprintf(fp, "%d announcements started.\n", count);
} else if (sscanf(request, "announce %255s %c", hostname, &d) == 1) {
cmd_announce(fp, hostname, 0, -1);
} else if (sscanf( request, "announce %255[^: ] %d %c", hostname, &minutes, &d) == 2) {
} else if (sscanf(request, "announce %255[^: ] %d %c", hostname, &minutes, &d) == 2) {
cmd_announce(fp, hostname, 0, minutes);
} else if (sscanf( request, "announce %255[^: ]:%d %d %c", hostname, &port, &minutes, &d) == 3) {
cmd_announce(fp, hostname, port, minutes );
} else if (sscanf(request, "announce %255[^: ]:%d %d %c", hostname, &port, &minutes, &d) == 3) {
cmd_announce(fp, hostname, port, minutes);
} else if (match(request, "list %*s %n") && allow_debug) {
if (sscanf(request, "blacklist %255[^: ]", hostname) == 1) {
cmd_blacklist(fp, hostname);
Expand All @@ -187,7 +187,7 @@ static void cmd_exec(FILE *fp, const char request[], int allow_debug)
rc = kad_export_nodes(fp);

if (rc == 0) {
fprintf(fp, "No good nodes found.\n" );
fprintf(fp, "No good nodes found.\n");
}
#ifdef FWD
} else if (match(request, "list forwardings %n")) {
Expand Down Expand Up @@ -356,7 +356,7 @@ int cmd_client(int argc, char *argv[])
if (strcmp(argv[0], "-h") == 0) {
fprintf(stdout, "%s", g_client_usage);
return 0;
} else if (strcmp( argv[0], "-p") == 0) {
} else if (strcmp(argv[0], "-p") == 0) {
if (argc >= 2) {
path = argv[1];
// Skip option and path
Expand Down
6 changes: 3 additions & 3 deletions src/ext-fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ void fwd_free(void);
struct forwarding_t *fwd_get(void);

// List all entries
void fwd_debug( int fd );
void fwd_debug(int fd);

// Count all entries
int fwd_count( void );
int fwd_count(void);

// Add a port forwarding from external port to the same local port
void fwd_add( int port, time_t host_lifetime );
void fwd_add(int port, time_t host_lifetime);


#endif // _EXT_FWD_H_
60 changes: 30 additions & 30 deletions src/ext-libnss.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int _nss_kadnode_lookup(const char hostname[], int hostlen, IP addrs[])
enum nss_status _nss_kadnode_hostent(
const char *hostname, int af, struct hostent *result,
char *buf, size_t buflen, int *errnop,
int *h_errnop, int32_t *ttlp, char **canonp ) {
int *h_errnop, int32_t *ttlp, char **canonp) {

IP addrs[MAX_ADDRS];
char *p_addr;
Expand All @@ -83,44 +83,44 @@ enum nss_status _nss_kadnode_hostent(
int addrsnum;
int i;

hostlen = strlen( hostname );
hostlen = strlen(hostname);

if( af != AF_INET6 && af != AF_INET ) {
if (af != AF_INET6 && af != AF_INET) {
*errnop = EAFNOSUPPORT;
*h_errnop = NO_DATA;
return NSS_STATUS_UNAVAIL;
}

memset( addrs, '\0', sizeof(addrs) );
addrsnum = _nss_kadnode_lookup( hostname, hostlen, addrs );
if( addrsnum < 0 ) {
memset(addrs, '\0', sizeof(addrs));
addrsnum = _nss_kadnode_lookup(hostname, hostlen, addrs);
if (addrsnum < 0) {
*errnop = ENOENT;
*h_errnop = HOST_NOT_FOUND;
return NSS_STATUS_UNAVAIL;
} else if( addrsnum == 0 ) {
} else if (addrsnum == 0) {
*errnop = ENOENT;
*h_errnop = HOST_NOT_FOUND;
return NSS_STATUS_NOTFOUND;
}

// Check upper bound
if( buflen < ((hostlen + 1) + sizeof(char*) + (addrsnum * sizeof(struct in6_addr)) + (addrsnum + 1) * sizeof(char*)) ) {
if (buflen < ((hostlen + 1) + sizeof(char*) + (addrsnum * sizeof(struct in6_addr)) + (addrsnum + 1) * sizeof(char*))) {
*errnop = ENOMEM;
*h_errnop = NO_RECOVERY;
return NSS_STATUS_TRYAGAIN;
} else if( addrs[0].ss_family == AF_INET6 ) {
} else if (addrs[0].ss_family == AF_INET6) {
af = AF_INET6;
addrlen = sizeof(struct in6_addr);
} else {
af = AF_INET;
addrlen = sizeof(struct in_addr);
}

memset( buf, '\0', buflen );
memset(buf, '\0', buflen);

// Hostname
p_name = buf;
memcpy( p_name, hostname, hostlen );
memcpy(p_name, hostname, hostlen);
p_idx = p_name + hostlen + 1;

// Alias
Expand All @@ -130,19 +130,19 @@ enum nss_status _nss_kadnode_hostent(

// Address data
p_addr = p_idx;
for( i = 0; i < addrsnum; i++ ) {
if( af == AF_INET6 ) {
memcpy( p_addr, &((IP6 *)&addrs[i])->sin6_addr, addrlen );
for (i = 0; i < addrsnum; i++) {
if (af == AF_INET6) {
memcpy(p_addr, &((IP6 *)&addrs[i])->sin6_addr, addrlen);
} else {
memcpy( p_addr, &((IP4 *)&addrs[i])->sin_addr, addrlen );
memcpy(p_addr, &((IP4 *)&addrs[i])->sin_addr, addrlen);
}
}
p_idx += addrsnum * addrlen;

// Address pointer
p_addr_list = p_idx;
p_idx = p_addr;
for( i = 0; i < addrsnum; i++ ) {
for (i = 0; i < addrsnum; i++) {
((char**) p_addr_list)[i] = p_idx;
p_idx += addrlen;
}
Expand All @@ -154,11 +154,11 @@ enum nss_status _nss_kadnode_hostent(
result->h_length = addrlen;
result->h_addr_list = (char**) p_addr_list;

if( ttlp != NULL ) {
if (ttlp != NULL) {
*ttlp = 0;
}

if( canonp != NULL ) {
if (canonp != NULL) {
*canonp = p_name;
}

Expand All @@ -167,27 +167,27 @@ enum nss_status _nss_kadnode_hostent(

enum nss_status _nss_kadnode_gethostbyname_r(
const char *hostname, struct hostent *result,
char *buf, size_t buflen, int *errnop, int *h_errnop ) {
char *buf, size_t buflen, int *errnop, int *h_errnop) {

return _nss_kadnode_hostent( hostname, AF_INET6, result,
buf, buflen, errnop, h_errnop, NULL, NULL );
return _nss_kadnode_hostent(hostname, AF_INET6, result,
buf, buflen, errnop, h_errnop, NULL, NULL);
}

enum nss_status _nss_kadnode_gethostbyname2_r(
const char *hostname, int af, struct hostent *result,
char *buf, size_t buflen, int *errnop, int *h_errnop ) {
char *buf, size_t buflen, int *errnop, int *h_errnop) {

return _nss_kadnode_hostent( hostname, af, result,
buf, buflen, errnop, h_errnop, NULL, NULL );
return _nss_kadnode_hostent(hostname, af, result,
buf, buflen, errnop, h_errnop, NULL, NULL);
}

enum nss_status _nss_kadnode_gethostbyname3_r(
const char *hostname, int af, struct hostent *result,
char *buf, size_t buflen, int *errnop, int *h_errnop,
int32_t *ttlp, char **canonp ) {
int32_t *ttlp, char **canonp) {

return _nss_kadnode_hostent( hostname, af, result,
buf, buflen, errnop, h_errnop, ttlp, canonp );
return _nss_kadnode_hostent(hostname, af, result,
buf, buflen, errnop, h_errnop, ttlp, canonp);
}

enum nss_status _nss_kadnode_gethostbyaddr_r(
Expand All @@ -209,13 +209,13 @@ static ns_mtab methods[] = {
{ NSDB_HOSTS, "gethostbyname2_r", __nss_compat_gethostbyname2_r, NULL },
};

ns_mtab *nss_module_register( const char *source, unsigned int *mtabsize, nss_module_unregister_fn *unreg ) {
ns_mtab *nss_module_register(const char *source, unsigned int *mtabsize, nss_module_unregister_fn *unreg) {
*mtabsize = sizeof(methods) / sizeof(methods[0]);
*unreg = NULL;
return methods;
}

int __nss_compat_gethostbyname2_r( void *retval, void *mdata, va_list ap ) {
int __nss_compat_gethostbyname2_r(void *retval, void *mdata, va_list ap) {
int s;
const char *name;
int af;
Expand All @@ -233,7 +233,7 @@ int __nss_compat_gethostbyname2_r( void *retval, void *mdata, va_list ap ) {
errnop = va_arg(ap, int*);
h_errnop = va_arg(ap, int*);

s = _nss_kadnode_gethostbyname2_r( name, af, hptr, buffer, buflen, errnop, h_errnop );
s = _nss_kadnode_gethostbyname2_r(name, af, hptr, buffer, buflen, errnop, h_errnop);
*(struct hostent**) retval = (s == NS_SUCCESS) ? hptr : NULL;

return __nss_compat_result(s, *errnop);
Expand Down
8 changes: 4 additions & 4 deletions src/ext-libnss.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
enum nss_status _nss_kadnode_gethostbyname_r(
const char *hostname, struct hostent *host,
char *buffer, size_t buflen, int *errnop,
int *h_errnop ) _public_;
int *h_errnop) _public_;

enum nss_status _nss_kadnode_gethostbyname2_r(
const char *hostname, int af, struct hostent *host,
char *buffer, size_t buflen, int *errnop,
int *h_errnop ) _public_;
int *h_errnop) _public_;

enum nss_status _nss_kadnode_gethostbyname3_r(
const char *hostname, int af, struct hostent *host,
char *buf, size_t buflen, int *errnop,
int *h_errnop, int32_t *ttlp, char **canonp ) _public_;
int *h_errnop, int32_t *ttlp, char **canonp) _public_;

enum nss_status _nss_kadnode_gethostbyname4_r(
const char *hostname, struct gaih_addrtuple **pat,
char *buffer, size_t buflen, int *errnop,
int *h_errnop, int32_t *ttlp ) _public_;
int *h_errnop, int32_t *ttlp) _public_;

#endif // _EXT_LIBNSS_H_
4 changes: 2 additions & 2 deletions src/ext-nss.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ static void nss_client_handler(int rc, int clientsock)

num = ARRAY_SIZE(addrs);
rc = kad_lookup(hostname, addrs, &num);
if ( EXIT_SUCCESS == rc) {
if (EXIT_SUCCESS == rc) {
// Found addresses
log_debug( "NSS: Found %lu addresses.", num);
log_debug("NSS: Found %lu addresses.", num);
} else {
num = 0;
}
Expand Down
24 changes: 12 additions & 12 deletions src/libkadnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "libkadnode.h"


int kadnode_init( void ) {
if( gconf == NULL ) {
int kadnode_init(void) {
if (gconf == NULL) {
// Setup gconf
conf_init();
return 0;
Expand All @@ -18,23 +18,23 @@ int kadnode_init( void ) {
}
}

void kadnode_stop( void ) {
if( gconf ) {
void kadnode_stop(void) {
if (gconf) {
gconf->is_running = 0;
}
}

int kadnode_set( const char opt[], const char val[] ) {
if( gconf && !gconf->is_running ) {
return conf_set( opt, val );
int kadnode_set(const char opt[], const char val[]) {
if (gconf && !gconf->is_running) {
return conf_set(opt, val);
} else {
return 1;
}
}

void kadnode_loop( void )
void kadnode_loop(void)
{
if( gconf && gconf->is_running == 0 ) {
if (gconf && gconf->is_running == 0) {
conf_check();

main_setup();
Expand All @@ -51,10 +51,10 @@ void kadnode_loop( void )
}
}

int kadnode_lookup( const char query[], struct sockaddr_storage addr_array[], size_t *addr_num )
int kadnode_lookup(const char query[], struct sockaddr_storage addr_array[], size_t *addr_num)
{
if( gconf && gconf->is_running ) {
return kad_lookup( query, addr_array, addr_num );
if (gconf && gconf->is_running) {
return kad_lookup(query, addr_array, addr_num);
} else {
return EXIT_FAILURE;
}
Expand Down
8 changes: 4 additions & 4 deletions src/libkadnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* Not yet finished!
*/

int kadnode_init( void );
int kadnode_set( const char opt[], const char val[] );
int kadnode_lookup( const char query[], struct sockaddr_storage addr_array[], size_t addr_num );
void kadnode_stop( void );
int kadnode_init(void);
int kadnode_set(const char opt[], const char val[]);
int kadnode_lookup(const char query[], struct sockaddr_storage addr_array[], size_t addr_num);
void kadnode_stop(void);

#endif // _LIBKADNODE_H_
8 changes: 4 additions & 4 deletions src/peerfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
*/

// Setup callbacks
void peerfile_setup( void );
void peerfile_free( void );
void peerfile_setup(void);
void peerfile_free(void);

// Write peers to peerfile
void peerfile_export( void );
void peerfile_export(void);

// Add a static peer
int peerfile_add_peer( const char addr_str[] );
int peerfile_add_peer(const char addr_str[]);


#endif // _PEERFILE_H
4 changes: 2 additions & 2 deletions src/searches.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum AUTH_STATE {
AUTH_WAITING // Not yet started
};

typedef void auth_callback( void );
typedef void auth_callback(void);

// An address that was received as a result of an id search
struct result_t {
Expand All @@ -36,7 +36,7 @@ struct search_t {
};

void searches_set_auth_state(const char query[], const IP *addr, const int state);
struct result_t *searches_get_auth_target( char query[], IP *addr, auth_callback *callback);
struct result_t *searches_get_auth_target(char query[], IP *addr, auth_callback *callback);

void searches_setup(void);
void searches_free(void);
Expand Down
8 changes: 4 additions & 4 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ int port_parse(const char pstr[], int err)
}
}

int port_set( IP *addr, uint16_t port )
int port_set(IP *addr, uint16_t port)
{
switch (addr->ss_family) {
case AF_INET:
Expand Down Expand Up @@ -392,8 +392,8 @@ const char *str_id(const uint8_t id[])
return bytes_to_base16hex(hexbuf, sizeof(hexbuf), id, SHA1_BIN_LENGTH);
}

const char *str_af( int af ) {
switch( af ) {
const char *str_af(int af) {
switch (af) {
case AF_INET:
return "IPv4";
case AF_INET6:
Expand Down Expand Up @@ -505,7 +505,7 @@ int addr_parse(IP *addr, const char addr_str[], const char port_str[], int af)
while (p != NULL) {
if (p->ai_family == AF_INET6) {
memcpy(addr, p->ai_addr, sizeof(IP6));
freeaddrinfo( info );
freeaddrinfo(info);
return 0;
}
if (p->ai_family == AF_INET) {
Expand Down
Loading

0 comments on commit 8d4a2b9

Please sign in to comment.