Clean up white space.

This commit is contained in:
Jan Vidar Krey 2013-03-22 20:00:40 +01:00
parent 5835a06676
commit f25015927a
34 changed files with 232 additions and 232 deletions

View File

@ -168,24 +168,24 @@ int adc_msg_get_arg_offset(struct adc_message* msg)
{ {
if (!msg || !msg->cache) if (!msg || !msg->cache)
return -1; return -1;
switch (msg->cache[0]) switch (msg->cache[0])
{ {
/* These *SHOULD* never be seen on a hub */ /* These *SHOULD* never be seen on a hub */
case 'U': case 'U':
case 'C': case 'C':
return 4; /* Actually: 4 + strlen(cid). */ return 4; /* Actually: 4 + strlen(cid). */
case 'I': case 'I':
case 'H': case 'H':
return 4; return 4;
case 'B': case 'B':
return 9; return 9;
case 'F': case 'F':
return (10 + (list_size(msg->feature_cast_include)*5) + (list_size(msg->feature_cast_exclude)*5)); return (10 + (list_size(msg->feature_cast_include)*5) + (list_size(msg->feature_cast_exclude)*5));
case 'D': case 'D':
case 'E': case 'E':
return 14; return 14;
@ -200,10 +200,10 @@ int adc_msg_is_empty(struct adc_message* msg)
if (offset == -1) if (offset == -1)
return -1; return -1;
if ((msg->length - 1) == (size_t) offset) if ((msg->length - 1) == (size_t) offset)
return 1; return 1;
return 0; return 0;
} }
@ -307,17 +307,17 @@ struct adc_message* adc_msg_copy(const struct adc_message* cmd)
struct adc_message* adc_msg_parse_verify(struct hub_user* u, const char* line, size_t length) struct adc_message* adc_msg_parse_verify(struct hub_user* u, const char* line, size_t length)
{ {
struct adc_message* command = adc_msg_parse(line, length); struct adc_message* command = adc_msg_parse(line, length);
if (!command) if (!command)
return 0; return 0;
if (command->source && (!u || command->source != u->id.sid)) if (command->source && (!u || command->source != u->id.sid))
{ {
LOG_DEBUG("Command does not match user's SID (command->source=%d, user->id.sid=%d)", command->source, (u ? u->id.sid : 0)); LOG_DEBUG("Command does not match user's SID (command->source=%d, user->id.sid=%d)", command->source, (u ? u->id.sid : 0));
adc_msg_free(command); adc_msg_free(command);
return 0; return 0;
} }
return command; return command;
} }
@ -331,7 +331,7 @@ struct adc_message* adc_msg_parse(const char* line, size_t length)
int ok = 1; int ok = 1;
int need_terminate = 0; int need_terminate = 0;
struct linked_list* feature_cast_list; struct linked_list* feature_cast_list;
if (command == NULL) if (command == NULL)
return NULL; /* OOM */ return NULL; /* OOM */
@ -595,14 +595,14 @@ int adc_msg_remove_named_argument(struct adc_message* cmd, const char prefix_[2]
int found = 0; int found = 0;
int arg_offset = adc_msg_get_arg_offset(cmd); int arg_offset = adc_msg_get_arg_offset(cmd);
size_t temp_len = 0; size_t temp_len = 0;
adc_msg_unterminate(cmd); adc_msg_unterminate(cmd);
start = memmem(&cmd->cache[arg_offset], (cmd->length - arg_offset), prefix, 3); start = memmem(&cmd->cache[arg_offset], (cmd->length - arg_offset), prefix, 3);
while (start) while (start)
{ {
endInfo = &cmd->cache[cmd->length]; endInfo = &cmd->cache[cmd->length];
if (&start[0] < &endInfo[0]) if (&start[0] < &endInfo[0])
{ {
end = memchr(&start[1], ' ', &endInfo[0]-&start[1]); end = memchr(&start[1], ' ', &endInfo[0]-&start[1]);
@ -611,13 +611,13 @@ int adc_msg_remove_named_argument(struct adc_message* cmd, const char prefix_[2]
{ {
end = NULL; end = NULL;
} }
if (end) if (end)
{ {
temp_len = &end[0] - &start[0]; // strlen(start); temp_len = &end[0] - &start[0]; // strlen(start);
endlen = strlen(end); endlen = strlen(end);
memmove(start, end, endlen); memmove(start, end, endlen);
start[endlen] = '\0'; start[endlen] = '\0';
found++; found++;
@ -632,9 +632,9 @@ int adc_msg_remove_named_argument(struct adc_message* cmd, const char prefix_[2]
} }
start = memmem(&cmd->cache[arg_offset], (cmd->length - arg_offset), prefix, 3); start = memmem(&cmd->cache[arg_offset], (cmd->length - arg_offset), prefix, 3);
} }
adc_msg_terminate(cmd); adc_msg_terminate(cmd);
return found; return found;
} }
@ -683,7 +683,7 @@ char* adc_msg_get_named_argument(struct adc_message* cmd, const char prefix_[2])
length = &end[0] - &start[0]; length = &end[0] - &start[0];
argument = hub_strndup(start, length); argument = hub_strndup(start, length);
if (length > 0 && argument[length-1] == '\n') if (length > 0 && argument[length-1] == '\n')
{ {
argument[length-1] = 0; argument[length-1] = 0;

View File

@ -229,7 +229,7 @@ void adc_msg_unterminate(struct adc_message* cmd);
/** /**
* @return the offset for the first command argument in msg->cache. * @return the offset for the first command argument in msg->cache.
* or -1 if the command is not understood. * or -1 if the command is not understood.
* NOTE: for 'U' and 'C' commands (normally not seen by hubs), * NOTE: for 'U' and 'C' commands (normally not seen by hubs),
* this returns 4. Should be 4 + lengthOf(cid). * this returns 4. Should be 4 + lengthOf(cid).
*/ */
int adc_msg_get_arg_offset(struct adc_message* msg); int adc_msg_get_arg_offset(struct adc_message* msg);

View File

@ -47,7 +47,7 @@ sid_t string_to_sid(const char* sid)
sid_t nsid = 0; sid_t nsid = 0;
sid_t n, x; sid_t n, x;
sid_t factors[] = { 32768, 1024, 32, 1}; sid_t factors[] = { 32768, 1024, 32, 1};
if (!sid || strlen(sid) != 4) return 0; if (!sid || strlen(sid) != 4) return 0;
for (n = 0; n < 4; n++) { for (n = 0; n < 4; n++) {

View File

@ -26,20 +26,20 @@
static int check_cmd_bool(const char* cmd, struct linked_list* list, char* line, int line_count) static int check_cmd_bool(const char* cmd, struct linked_list* list, char* line, int line_count)
{ {
char* data; char* data;
if (!strncmp(line, cmd, strlen(cmd))) if (!strncmp(line, cmd, strlen(cmd)))
{ {
data = &line[strlen(cmd)]; data = &line[strlen(cmd)];
data[0] = '\0'; data[0] = '\0';
data++; data++;
data = strip_white_space(data); data = strip_white_space(data);
if (!*data) if (!*data)
{ {
LOG_FATAL("ACL parse error on line %d", line_count); LOG_FATAL("ACL parse error on line %d", line_count);
return -1; return -1;
} }
list_append(list, hub_strdup(data)); list_append(list, hub_strdup(data));
LOG_DEBUG("ACL: Deny access for: '%s' (%s)", data, cmd); LOG_DEBUG("ACL: Deny access for: '%s' (%s)", data, cmd);
return 1; return 1;
@ -190,18 +190,18 @@ int acl_initialize(struct hub_config* config, struct acl_handle* handle)
{ {
int ret; int ret;
memset(handle, 0, sizeof(struct acl_handle)); memset(handle, 0, sizeof(struct acl_handle));
handle->users = list_create(); handle->users = list_create();
handle->users_denied = list_create(); handle->users_denied = list_create();
handle->users_banned = list_create(); handle->users_banned = list_create();
handle->cids = list_create(); handle->cids = list_create();
handle->networks = list_create(); handle->networks = list_create();
handle->nat_override = list_create(); handle->nat_override = list_create();
if (!handle->users || !handle->cids || !handle->networks || !handle->users_denied || !handle->users_banned || !handle->nat_override) if (!handle->users || !handle->cids || !handle->networks || !handle->users_denied || !handle->users_banned || !handle->nat_override)
{ {
LOG_FATAL("acl_initialize: Out of memory"); LOG_FATAL("acl_initialize: Out of memory");
list_destroy(handle->users); list_destroy(handle->users);
list_destroy(handle->users_denied); list_destroy(handle->users_denied);
list_destroy(handle->users_banned); list_destroy(handle->users_banned);
@ -210,11 +210,11 @@ int acl_initialize(struct hub_config* config, struct acl_handle* handle)
list_destroy(handle->nat_override); list_destroy(handle->nat_override);
return -1; return -1;
} }
if (config) if (config)
{ {
if (!*config->file_acl) return 0; if (!*config->file_acl) return 0;
ret = file_read_lines(config->file_acl, handle, &acl_parse_line); ret = file_read_lines(config->file_acl, handle, &acl_parse_line);
if (ret == -1) if (ret == -1)
return -1; return -1;
@ -249,26 +249,26 @@ int acl_shutdown(struct acl_handle* handle)
list_clear(handle->users, &acl_free_access_info); list_clear(handle->users, &acl_free_access_info);
list_destroy(handle->users); list_destroy(handle->users);
} }
if (handle->users_denied) if (handle->users_denied)
{ {
list_clear(handle->users_denied, &hub_free); list_clear(handle->users_denied, &hub_free);
list_destroy(handle->users_denied); list_destroy(handle->users_denied);
} }
if (handle->users_banned) if (handle->users_banned)
{ {
list_clear(handle->users_banned, &hub_free); list_clear(handle->users_banned, &hub_free);
list_destroy(handle->users_banned); list_destroy(handle->users_banned);
} }
if (handle->cids) if (handle->cids)
{ {
list_clear(handle->cids, &hub_free); list_clear(handle->cids, &hub_free);
list_destroy(handle->cids); list_destroy(handle->cids);
} }
if (handle->networks) if (handle->networks)
{ {
list_clear(handle->networks, &acl_free_ip_info); list_clear(handle->networks, &acl_free_ip_info);
@ -468,10 +468,10 @@ int acl_password_verify(struct hub_info* hub, struct hub_user* user, const char*
base32_decode(challenge, (unsigned char*) raw_challenge, MAX_CID_LEN); base32_decode(challenge, (unsigned char*) raw_challenge, MAX_CID_LEN);
password_len = strlen(access->password); password_len = strlen(access->password);
memcpy(&buf[0], access->password, password_len); memcpy(&buf[0], access->password, password_len);
memcpy(&buf[password_len], raw_challenge, TIGERSIZE); memcpy(&buf[password_len], raw_challenge, TIGERSIZE);
tiger((uint64_t*) buf, TIGERSIZE+password_len, (uint64_t*) tiger_res); tiger((uint64_t*) buf, TIGERSIZE+password_len, (uint64_t*) tiger_res);
base32_encode((unsigned char*) tiger_res, TIGERSIZE, password_calc); base32_encode((unsigned char*) tiger_res, TIGERSIZE, password_calc);
password_calc[MAX_CID_LEN] = 0; password_calc[MAX_CID_LEN] = 0;

View File

@ -76,7 +76,7 @@ static int config_parse_line(char* line, int line_count, void* ptr_data)
struct hub_config* config = (struct hub_config*) ptr_data; struct hub_config* config = (struct hub_config*) ptr_data;
strip_off_ini_line_comments(line, line_count); strip_off_ini_line_comments(line, line_count);
if (!*line) return 0; if (!*line) return 0;
LOG_DUMP("config_parse_line(): '%s'", line); LOG_DUMP("config_parse_line(): '%s'", line);

View File

@ -32,20 +32,20 @@ int event_queue_initialize(struct event_queue** queue, event_queue_callback call
*queue = (struct event_queue*) hub_malloc_zero(sizeof(struct event_queue)); *queue = (struct event_queue*) hub_malloc_zero(sizeof(struct event_queue));
if (!(*queue)) if (!(*queue))
return -1; return -1;
(*queue)->q1 = list_create(); (*queue)->q1 = list_create();
(*queue)->q2 = list_create(); (*queue)->q2 = list_create();
if (!(*queue)->q1 || !(*queue)->q2) if (!(*queue)->q1 || !(*queue)->q2)
{ {
list_destroy((*queue)->q1); list_destroy((*queue)->q1);
list_destroy((*queue)->q2); list_destroy((*queue)->q2);
return -1; return -1;
} }
(*queue)->callback = callback; (*queue)->callback = callback;
(*queue)->callback_data = ptr; (*queue)->callback_data = ptr;
return 0; return 0;
} }
@ -73,7 +73,7 @@ int event_queue_process(struct event_queue* queue)
struct event_data* data; struct event_data* data;
if (queue->locked) if (queue->locked)
return 0; return 0;
/* lock primary queue, and handle the primary queue messages. */ /* lock primary queue, and handle the primary queue messages. */
queue->locked = 1; queue->locked = 1;
@ -84,10 +84,10 @@ int event_queue_process(struct event_queue* queue)
#endif #endif
queue->callback(queue->callback_data, data); queue->callback(queue->callback_data, data);
}); });
list_clear(queue->q1, event_queue_cleanup_callback); list_clear(queue->q1, event_queue_cleanup_callback);
uhub_assert(list_size(queue->q1) == 0); uhub_assert(list_size(queue->q1) == 0);
/* unlock queue */ /* unlock queue */
queue->locked = 0; queue->locked = 0;
@ -106,18 +106,18 @@ void event_queue_post(struct event_queue* queue, struct event_data* message)
{ {
struct linked_list* q = (!queue->locked) ? queue->q1 : queue->q2; struct linked_list* q = (!queue->locked) ? queue->q1 : queue->q2;
struct event_data* data; struct event_data* data;
data = (struct event_data*) hub_malloc(sizeof(struct event_data)); data = (struct event_data*) hub_malloc(sizeof(struct event_data));
if (data) if (data)
{ {
data->id = message->id; data->id = message->id;
data->ptr = message->ptr; data->ptr = message->ptr;
data->flags = message->flags; data->flags = message->flags;
#ifdef EQ_DEBUG #ifdef EQ_DEBUG
eq_debug("POST", data); eq_debug("POST", data);
#endif #endif
list_append(q, data); list_append(q, data);
} }
else else

View File

@ -55,7 +55,7 @@ enum status_message
status_msg_proto_no_common_hash = -50, /* No common hash algorithms */ status_msg_proto_no_common_hash = -50, /* No common hash algorithms */
status_msg_proto_obsolete_adc0 = -51, /* Client is using an obsolete protocol version */ status_msg_proto_obsolete_adc0 = -51, /* Client is using an obsolete protocol version */
}; };

View File

@ -109,14 +109,14 @@ static int check_cid(struct hub_info* hub, struct hub_user* user, struct adc_mes
hub_free(pid); hub_free(pid);
return status_msg_inf_error_cid_invalid; return status_msg_inf_error_cid_invalid;
} }
if (strlen(pid) != MAX_CID_LEN) if (strlen(pid) != MAX_CID_LEN)
{ {
hub_free(cid); hub_free(cid);
hub_free(pid); hub_free(pid);
return status_msg_inf_error_pid_invalid; return status_msg_inf_error_pid_invalid;
} }
for (pos = 0; pos < MAX_CID_LEN; pos++) for (pos = 0; pos < MAX_CID_LEN; pos++)
{ {
if (!is_valid_base32_char(cid[pos])) if (!is_valid_base32_char(cid[pos]))
@ -133,18 +133,18 @@ static int check_cid(struct hub_info* hub, struct hub_user* user, struct adc_mes
return status_msg_inf_error_pid_invalid; return status_msg_inf_error_pid_invalid;
} }
} }
if (!check_hash_tiger(cid, pid)) if (!check_hash_tiger(cid, pid))
{ {
hub_free(cid); hub_free(cid);
hub_free(pid); hub_free(pid);
return status_msg_inf_error_cid_invalid; return status_msg_inf_error_cid_invalid;
} }
/* Set the cid in the user object */ /* Set the cid in the user object */
memcpy(user->id.cid, cid, MAX_CID_LEN); memcpy(user->id.cid, cid, MAX_CID_LEN);
user->id.cid[MAX_CID_LEN] = 0; user->id.cid[MAX_CID_LEN] = 0;
hub_free(cid); hub_free(cid);
hub_free(pid); hub_free(pid);
return 0; return 0;
@ -154,7 +154,7 @@ static int check_cid(struct hub_info* hub, struct hub_user* user, struct adc_mes
static int check_required_login_flags(struct hub_info* hub, struct hub_user* user, struct adc_message* cmd) static int check_required_login_flags(struct hub_info* hub, struct hub_user* user, struct adc_message* cmd)
{ {
int num = 0; int num = 0;
num = adc_msg_has_named_argument(cmd, ADC_INF_FLAG_CLIENT_ID); num = adc_msg_has_named_argument(cmd, ADC_INF_FLAG_CLIENT_ID);
if (num != 1) if (num != 1)
{ {
@ -162,7 +162,7 @@ static int check_required_login_flags(struct hub_info* hub, struct hub_user* use
return status_msg_inf_error_cid_missing; return status_msg_inf_error_cid_missing;
return status_msg_inf_error_cid_invalid; return status_msg_inf_error_cid_invalid;
} }
num = adc_msg_has_named_argument(cmd, ADC_INF_FLAG_PRIVATE_ID); num = adc_msg_has_named_argument(cmd, ADC_INF_FLAG_PRIVATE_ID);
if (num != 1) if (num != 1)
{ {
@ -190,7 +190,7 @@ static int check_required_login_flags(struct hub_info* hub, struct hub_user* use
static int check_network(struct hub_info* hub, struct hub_user* user, struct adc_message* cmd) static int check_network(struct hub_info* hub, struct hub_user* user, struct adc_message* cmd)
{ {
const char* address = user_get_address(user); const char* address = user_get_address(user);
/* Check for NAT override address */ /* Check for NAT override address */
if (acl_is_ip_nat_override(hub->acl, address)) if (acl_is_ip_nat_override(hub->acl, address))
{ {
@ -236,12 +236,12 @@ static int nick_length_ok(const char* nick)
{ {
return nick_invalid_short; return nick_invalid_short;
} }
if (length > MAX_NICK_LEN) if (length > MAX_NICK_LEN)
{ {
return nick_invalid_long; return nick_invalid_long;
} }
return nick_ok; return nick_ok;
} }
@ -249,16 +249,16 @@ static int nick_length_ok(const char* nick)
static int nick_bad_characters(const char* nick) static int nick_bad_characters(const char* nick)
{ {
const char* tmp; const char* tmp;
/* Nick must not start with a space */ /* Nick must not start with a space */
if (nick[0] == ' ') if (nick[0] == ' ')
return nick_invalid_spaces; return nick_invalid_spaces;
/* Check for ASCII values below 32 */ /* Check for ASCII values below 32 */
for (tmp = nick; *tmp; tmp++) for (tmp = nick; *tmp; tmp++)
if ((*tmp < 32) && (*tmp > 0)) if ((*tmp < 32) && (*tmp > 0))
return nick_invalid_bad_ascii; return nick_invalid_bad_ascii;
return nick_ok; return nick_ok;
} }
@ -286,7 +286,7 @@ static int check_nick(struct hub_info* hub, struct hub_user* user, struct adc_me
nick = adc_msg_unescape(tmp); nick = adc_msg_unescape(tmp);
free(tmp); tmp = 0; free(tmp); tmp = 0;
if (!nick) return 0; if (!nick) return 0;
status = nick_length_ok(nick); status = nick_length_ok(nick);
if (status != nick_ok) if (status != nick_ok)
{ {
@ -295,7 +295,7 @@ static int check_nick(struct hub_info* hub, struct hub_user* user, struct adc_me
return status_msg_inf_error_nick_short; return status_msg_inf_error_nick_short;
return status_msg_inf_error_nick_long; return status_msg_inf_error_nick_long;
} }
status = nick_bad_characters(nick); status = nick_bad_characters(nick);
if (status != nick_ok) if (status != nick_ok)
{ {
@ -304,20 +304,20 @@ static int check_nick(struct hub_info* hub, struct hub_user* user, struct adc_me
return status_msg_inf_error_nick_spaces; return status_msg_inf_error_nick_spaces;
return status_msg_inf_error_nick_bad_chars; return status_msg_inf_error_nick_bad_chars;
} }
status = nick_is_utf8(nick); status = nick_is_utf8(nick);
if (status != nick_ok) if (status != nick_ok)
{ {
hub_free(nick); hub_free(nick);
return status_msg_inf_error_nick_not_utf8; return status_msg_inf_error_nick_not_utf8;
} }
if (user_is_connecting(user)) if (user_is_connecting(user))
{ {
memcpy(user->id.nick, nick, strlen(nick)); memcpy(user->id.nick, nick, strlen(nick));
user->id.nick[strlen(nick)] = 0; user->id.nick[strlen(nick)] = 0;
} }
hub_free(nick); hub_free(nick);
return 0; return 0;
} }
@ -327,12 +327,12 @@ static int check_logged_in(struct hub_info* hub, struct hub_user* user, struct a
{ {
struct hub_user* lookup1 = uman_get_user_by_nick(hub->users, user->id.nick); struct hub_user* lookup1 = uman_get_user_by_nick(hub->users, user->id.nick);
struct hub_user* lookup2 = uman_get_user_by_cid(hub->users, user->id.cid); struct hub_user* lookup2 = uman_get_user_by_cid(hub->users, user->id.cid);
if (lookup1 == user) if (lookup1 == user)
{ {
return 0; return 0;
} }
if (lookup1 || lookup2) if (lookup1 || lookup2)
{ {
if (lookup1 == lookup2) if (lookup1 == lookup2)
@ -368,7 +368,7 @@ static int check_user_agent(struct hub_info* hub, struct hub_user* user, struct
{ {
char* ua_encoded = 0; char* ua_encoded = 0;
char* ua = 0; char* ua = 0;
/* Get client user agent version */ /* Get client user agent version */
ua_encoded = adc_msg_get_named_argument(cmd, ADC_INF_FLAG_USER_AGENT); ua_encoded = adc_msg_get_named_argument(cmd, ADC_INF_FLAG_USER_AGENT);
if (ua_encoded) if (ua_encoded)
@ -391,7 +391,7 @@ static int check_acl(struct hub_info* hub, struct hub_user* user, struct adc_mes
{ {
return status_msg_ban_permanently; return status_msg_ban_permanently;
} }
if (acl_is_user_banned(hub->acl, user->id.nick)) if (acl_is_user_banned(hub->acl, user->id.nick))
{ {
return status_msg_ban_permanently; return status_msg_ban_permanently;
@ -401,7 +401,7 @@ static int check_acl(struct hub_info* hub, struct hub_user* user, struct adc_mes
{ {
return status_msg_inf_error_nick_restricted; return status_msg_inf_error_nick_restricted;
} }
return 0; return 0;
} }
@ -470,7 +470,7 @@ static int check_limits(struct hub_info* hub, struct hub_user* user, struct adc_
hub_free(arg); hub_free(arg);
arg = 0; arg = 0;
} }
arg = adc_msg_get_named_argument(cmd, ADC_INF_FLAG_UPLOAD_SLOTS); arg = adc_msg_get_named_argument(cmd, ADC_INF_FLAG_UPLOAD_SLOTS);
if (arg) if (arg)
{ {
@ -534,7 +534,7 @@ static int set_credentials(struct hub_info* hub, struct hub_user* user, struct a
{ {
int ret = 0; int ret = 0;
struct auth_info* info = acl_get_access_info(hub, user->id.nick); struct auth_info* info = acl_get_access_info(hub, user->id.nick);
if (info) if (info)
{ {
user->credentials = info->credentials; user->credentials = info->credentials;
@ -550,11 +550,11 @@ static int set_credentials(struct hub_info* hub, struct hub_user* user, struct a
{ {
case auth_cred_none: case auth_cred_none:
break; break;
case auth_cred_bot: case auth_cred_bot:
adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_BOT); adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_BOT);
break; break;
case auth_cred_guest: case auth_cred_guest:
/* Nothing to be added to the info message */ /* Nothing to be added to the info message */
break; break;
@ -566,7 +566,7 @@ static int set_credentials(struct hub_info* hub, struct hub_user* user, struct a
case auth_cred_operator: case auth_cred_operator:
adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_OPERATOR); adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_OPERATOR);
break; break;
case auth_cred_super: case auth_cred_super:
adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_SUPER_USER); adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_SUPER_USER);
break; break;
@ -578,7 +578,7 @@ static int set_credentials(struct hub_info* hub, struct hub_user* user, struct a
case auth_cred_link: case auth_cred_link:
break; break;
} }
return ret; return ret;
} }
@ -611,10 +611,10 @@ static int hub_handle_info_common(struct hub_user* user, struct adc_message* cmd
{ {
/* Remove server restricted flags */ /* Remove server restricted flags */
remove_server_restricted_flags(cmd); remove_server_restricted_flags(cmd);
/* Update/set the feature cast flags. */ /* Update/set the feature cast flags. */
set_feature_cast_supports(user, cmd); set_feature_cast_supports(user, cmd);
return 0; return 0;
} }
@ -635,7 +635,7 @@ static int hub_handle_info_low_bandwidth(struct hub_info* hub, struct hub_user*
adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_DESCRIPTION); adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_DESCRIPTION);
adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_EMAIL); adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_EMAIL);
} }
return 0; return 0;
} }
@ -680,20 +680,20 @@ int hub_handle_info_login(struct hub_info* hub, struct hub_user* user, struct ad
{ {
return status_msg_hub_full; return status_msg_hub_full;
} }
if (check_registered_users_only(hub, user)) if (check_registered_users_only(hub, user))
{ {
return status_msg_hub_registered_users_only; return status_msg_hub_registered_users_only;
} }
INF_CHECK(check_limits, hub, user, cmd); INF_CHECK(check_limits, hub, user, cmd);
/* strip off stuff if low_bandwidth_mode is enabled */ /* strip off stuff if low_bandwidth_mode is enabled */
hub_handle_info_low_bandwidth(hub, user, cmd); hub_handle_info_low_bandwidth(hub, user, cmd);
/* Set initial user info */ /* Set initial user info */
user_set_info(user, cmd); user_set_info(user, cmd);
return code; return code;
} }

View File

@ -72,7 +72,7 @@ size_t ioq_recv_set(struct ioq_recv* q, void* buf, size_t bufsize)
q->buf = 0; q->buf = 0;
q->size = 0; q->size = 0;
} }
if (!bufsize) if (!bufsize)
{ {
return 0; return 0;

View File

@ -87,7 +87,7 @@ void setup_signal_handlers(struct hub_info* hub)
act.sa_mask = sig_set; act.sa_mask = sig_set;
act.sa_flags = SA_ONSTACK | SA_RESTART; act.sa_flags = SA_ONSTACK | SA_RESTART;
act.sa_handler = hub_handle_signal; act.sa_handler = hub_handle_signal;
for (i = 0; signals[i]; i++) for (i = 0; signals[i]; i++)
{ {
if (sigaction(signals[i], &act, 0) != 0) if (sigaction(signals[i], &act, 0) != 0)
@ -124,7 +124,7 @@ int main_loop()
hub_log_initialize(arg_log, arg_log_syslog); hub_log_initialize(arg_log, arg_log_syslog);
hub_set_log_verbosity(arg_verbose); hub_set_log_verbosity(arg_verbose);
} }
if (read_config(arg_config, &configuration, !arg_have_config) == -1) if (read_config(arg_config, &configuration, !arg_have_config) == -1)
return -1; return -1;
@ -150,7 +150,7 @@ int main_loop()
#if !defined(WIN32) #if !defined(WIN32)
setup_signal_handlers(hub); setup_signal_handlers(hub);
#ifdef SYSTEMD #ifdef SYSTEMD
/* Notify the service manager that this daemon has /* Notify the service manager that this daemon has
* been successfully initalized and shall enter the * been successfully initalized and shall enter the
* main loop. * main loop.
*/ */
@ -174,7 +174,7 @@ int main_loop()
#if !defined(WIN32) #if !defined(WIN32)
shutdown_signal_handlers(hub); shutdown_signal_handlers(hub);
#endif #endif
if (hub) if (hub)
{ {
hub_shutdown_service(hub); hub_shutdown_service(hub);
@ -288,7 +288,7 @@ void parse_command_line(int argc, char** argv)
arg_dump_config = 1; arg_dump_config = 1;
arg_check_config = 1; arg_check_config = 1;
break; break;
case 'S': case 'S':
arg_dump_config = 2; arg_dump_config = 2;
arg_check_config = 1; arg_check_config = 1;
@ -297,7 +297,7 @@ void parse_command_line(int argc, char** argv)
case 'l': case 'l':
arg_log = optarg; arg_log = optarg;
break; break;
case 'L': case 'L':
arg_log_syslog = 1; arg_log_syslog = 1;
break; break;

View File

@ -153,7 +153,7 @@ static void cbfunc_set_hub_name(struct plugin_handle* plugin, const char* str)
char* new_str = adc_msg_escape(str ? str : hub->config->hub_name); char* new_str = adc_msg_escape(str ? str : hub->config->hub_name);
adc_msg_replace_named_argument(hub->command_info, ADC_INF_FLAG_NICK, new_str); adc_msg_replace_named_argument(hub->command_info, ADC_INF_FLAG_NICK, new_str);
// Broadcast hub name // Broadcast hub name
command = adc_msg_construct(ADC_CMD_IINF, (strlen(new_str) + 8)); command = adc_msg_construct(ADC_CMD_IINF, (strlen(new_str) + 8));
adc_msg_add_named_argument(command, ADC_INF_FLAG_NICK, new_str); adc_msg_add_named_argument(command, ADC_INF_FLAG_NICK, new_str);
@ -170,7 +170,7 @@ static void cbfunc_set_hub_description(struct plugin_handle* plugin, const char*
char* new_str = adc_msg_escape(str ? str : hub->config->hub_description); char* new_str = adc_msg_escape(str ? str : hub->config->hub_description);
adc_msg_replace_named_argument(hub->command_info, ADC_INF_FLAG_DESCRIPTION, new_str); adc_msg_replace_named_argument(hub->command_info, ADC_INF_FLAG_DESCRIPTION, new_str);
// Broadcast hub description // Broadcast hub description
command = adc_msg_construct(ADC_CMD_IINF, (strlen(new_str) + 8)); command = adc_msg_construct(ADC_CMD_IINF, (strlen(new_str) + 8));
adc_msg_add_named_argument(command, ADC_INF_FLAG_DESCRIPTION, new_str); adc_msg_add_named_argument(command, ADC_INF_FLAG_DESCRIPTION, new_str);

View File

@ -73,7 +73,7 @@ static void probe_net_event(struct net_connection* con, int events, void *arg)
} }
#ifdef SSL_SUPPORT #ifdef SSL_SUPPORT
else if (bytes >= 11 && else if (bytes >= 11 &&
probe_recvbuf[0] == 22 && probe_recvbuf[0] == 22 &&
probe_recvbuf[1] == 3 && /* protocol major version */ probe_recvbuf[1] == 3 && /* protocol major version */
probe_recvbuf[5] == 1 && /* message type */ probe_recvbuf[5] == 1 && /* message type */
probe_recvbuf[9] == probe_recvbuf[1]) probe_recvbuf[9] == probe_recvbuf[1])

View File

@ -28,7 +28,7 @@ int route_message(struct hub_info* hub, struct hub_user* u, struct adc_message*
case 'B': /* Broadcast to all logged in clients */ case 'B': /* Broadcast to all logged in clients */
route_to_all(hub, msg); route_to_all(hub, msg);
break; break;
case 'D': case 'D':
target = uman_get_user_by_sid(hub->users, msg->target); target = uman_get_user_by_sid(hub->users, msg->target);
if (target) if (target)
@ -36,7 +36,7 @@ int route_message(struct hub_info* hub, struct hub_user* u, struct adc_message*
route_to_user(hub, target, msg); route_to_user(hub, target, msg);
} }
break; break;
case 'E': case 'E':
target = uman_get_user_by_sid(hub->users, msg->target); target = uman_get_user_by_sid(hub->users, msg->target);
if (target) if (target)
@ -45,11 +45,11 @@ int route_message(struct hub_info* hub, struct hub_user* u, struct adc_message*
route_to_user(hub, u, msg); route_to_user(hub, u, msg);
} }
break; break;
case 'F': case 'F':
route_to_subscribers(hub, msg); route_to_subscribers(hub, msg);
break; break;
default: default:
/* Ignore the message */ /* Ignore the message */
break; break;
@ -152,7 +152,7 @@ int route_to_subscribers(struct hub_info* hub, struct adc_message* command) /* i
{ {
int do_send; int do_send;
char* tmp; char* tmp;
struct hub_user* user; struct hub_user* user;
LIST_FOREACH(struct hub_user*, user, hub->users->list, LIST_FOREACH(struct hub_user*, user, hub->users->list,
{ {
@ -168,10 +168,10 @@ int route_to_subscribers(struct hub_info* hub, struct adc_message* command) /* i
break; break;
} }
}); });
if (!do_send) if (!do_send)
continue; continue;
LIST_FOREACH(char*, tmp, command->feature_cast_exclude, LIST_FOREACH(char*, tmp, command->feature_cast_exclude,
{ {
if (user_have_feature_cast_support(user, tmp)) if (user_have_feature_cast_support(user, tmp))
@ -180,12 +180,12 @@ int route_to_subscribers(struct hub_info* hub, struct adc_message* command) /* i
break; break;
} }
}); });
if (do_send) if (do_send)
route_to_user(hub, user, command); route_to_user(hub, user, command);
} }
}); });
return 0; return 0;
} }
@ -200,7 +200,7 @@ int route_info_message(struct hub_info* hub, struct hub_user* u)
struct adc_message* cmd = adc_msg_copy(u->info); struct adc_message* cmd = adc_msg_copy(u->info);
const char* address = user_get_address(u); const char* address = user_get_address(u);
struct hub_user* user = 0; struct hub_user* user = 0;
adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR); adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR);
adc_msg_add_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR, address); adc_msg_add_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR, address);

View File

@ -38,7 +38,7 @@ static const char* user_log_str(struct hub_user* user)
struct hub_user* user_create(struct hub_info* hub, struct net_connection* con, struct ip_addr_encap* addr) struct hub_user* user_create(struct hub_info* hub, struct net_connection* con, struct ip_addr_encap* addr)
{ {
struct hub_user* user = NULL; struct hub_user* user = NULL;
LOG_TRACE("user_create(), hub=%p, con[sd=%d]", hub, net_con_get_sd(con)); LOG_TRACE("user_create(), hub=%p, con[sd=%d]", hub, net_con_get_sd(con));
user = (struct hub_user*) hub_malloc_zero(sizeof(struct hub_user)); user = (struct hub_user*) hub_malloc_zero(sizeof(struct hub_user));
@ -90,7 +90,7 @@ void user_set_state(struct hub_user* user, enum user_state state)
{ {
return; return;
} }
user->state = state; user->state = state;
} }
@ -135,7 +135,7 @@ void user_update_info(struct hub_user* u, struct adc_message* cmd)
prefix[1] = argument[1]; prefix[1] = argument[1];
adc_msg_replace_named_argument(cmd_new, prefix, argument+2); adc_msg_replace_named_argument(cmd_new, prefix, argument+2);
} }
hub_free(argument); hub_free(argument);
argument = adc_msg_get_argument(cmd, n++); argument = adc_msg_get_argument(cmd, n++);
} }

View File

@ -51,7 +51,7 @@ enum user_flags
flag_muted = 0x00800000, /** User is muted (cannot chat) */ flag_muted = 0x00800000, /** User is muted (cannot chat) */
flag_ignore = 0x01000000, /** Ignore further reads */ flag_ignore = 0x01000000, /** Ignore further reads */
flag_maxbuf = 0x02000000, /** Hit max buf read, ignore msg */ flag_maxbuf = 0x02000000, /** Hit max buf read, ignore msg */
flag_choke = 0x04000000, /** Choked: Cannot send, waiting for write event */ flag_choke = 0x04000000, /** Choked: Cannot send, waiting for write event */
flag_want_read = 0x08000000, /** Need to read (SSL) */ flag_want_read = 0x08000000, /** Need to read (SSL) */
flag_want_write = 0x10000000, /** Need to write (SSL) */ flag_want_write = 0x10000000, /** Need to write (SSL) */
flag_user_list = 0x20000000, /** Send queue bypass (when receiving the send queue) */ flag_user_list = 0x20000000, /** Send queue bypass (when receiving the send queue) */
@ -150,7 +150,7 @@ extern void user_destroy(struct hub_user* user);
* This associates a INF message to the user. * This associates a INF message to the user.
* If the user already has a INF message associated, then this is * If the user already has a INF message associated, then this is
* released before setting the new one. * released before setting the new one.
* *
* @param info new inf message (can be NULL) * @param info new inf message (can be NULL)
*/ */
extern void user_set_info(struct hub_user* user, struct adc_message* info); extern void user_set_info(struct hub_user* user, struct adc_message* info);
@ -244,7 +244,7 @@ extern int user_flag_get(struct hub_user* user, enum user_flags flag);
* Check if a user supports 'feature' for feature casting (basis for 'Fxxx' messages) * Check if a user supports 'feature' for feature casting (basis for 'Fxxx' messages)
* The feature cast is specified as the 'SU' argument to the user's * The feature cast is specified as the 'SU' argument to the user's
* INF-message. * INF-message.
* *
* @param feature a feature to lookup (example: 'TCP4' or 'UDP4') * @param feature a feature to lookup (example: 'TCP4' or 'UDP4')
* @return 1 if 'feature' supported, or 0 otherwise * @return 1 if 'feature' supported, or 0 otherwise
*/ */

View File

@ -77,7 +77,7 @@ extern sid_t uman_get_free_sid(struct hub_user_manager* users, struct hub_user*
* *
* NOTE: This function will only search connected users, which means * NOTE: This function will only search connected users, which means
* that SIDs assigned to users who are not yet completely logged in, * that SIDs assigned to users who are not yet completely logged in,
* or are in the process of being disconnected will result in this * or are in the process of being disconnected will result in this
* function returning NULL even though the sid is not freely available. * function returning NULL even though the sid is not freely available.
* *
* FIXME: Is that really safe / sensible ? * FIXME: Is that really safe / sensible ?

View File

@ -25,10 +25,10 @@ int ip_is_valid_ipv4(const char* address)
int o = 0; /* octet number */ int o = 0; /* octet number */
int n = 0; /* numbers after each dot */ int n = 0; /* numbers after each dot */
int d = 0; /* dots */ int d = 0; /* dots */
if (!address || strlen(address) > 15 || strlen(address) < 7) if (!address || strlen(address) > 15 || strlen(address) < 7)
return 0; return 0;
for (; i < strlen(address); i++) for (; i < strlen(address); i++)
{ {
if (is_num(address[i])) if (is_num(address[i]))
@ -49,9 +49,9 @@ int ip_is_valid_ipv4(const char* address)
return 0; return 0;
} }
} }
if (n == 0 || n > 3 || o > 255 || d != 3) return 0; if (n == 0 || n > 3 || o > 255 || d != 3) return 0;
return 1; return 1;
} }
@ -107,9 +107,9 @@ int ip_convert_address(const char* text_address, int port, struct sockaddr* addr
struct sockaddr_in addr4; struct sockaddr_in addr4;
size_t sockaddr_size; size_t sockaddr_size;
const char* taddr = 0; const char* taddr = 0;
int ipv6sup = net_is_ipv6_supported(); int ipv6sup = net_is_ipv6_supported();
if (strcmp(text_address, "any") == 0) if (strcmp(text_address, "any") == 0)
{ {
if (ipv6sup) if (ipv6sup)
@ -136,8 +136,8 @@ int ip_convert_address(const char* text_address, int port, struct sockaddr* addr
{ {
taddr = text_address; taddr = text_address;
} }
if (ip_is_valid_ipv6(taddr) && ipv6sup) if (ip_is_valid_ipv6(taddr) && ipv6sup)
{ {
sockaddr_size = sizeof(struct sockaddr_in6); sockaddr_size = sizeof(struct sockaddr_in6);
@ -152,7 +152,7 @@ int ip_convert_address(const char* text_address, int port, struct sockaddr* addr
memcpy(addr, &addr6, sockaddr_size); memcpy(addr, &addr6, sockaddr_size);
*addr_len = sockaddr_size; *addr_len = sockaddr_size;
} }
else if (ip_is_valid_ipv4(taddr)) else if (ip_is_valid_ipv4(taddr))
{ {
@ -185,28 +185,28 @@ int ip_mask_create_left(int af, int bits, struct ip_addr_encap* result)
memset(result, 0, sizeof(struct ip_addr_encap)); memset(result, 0, sizeof(struct ip_addr_encap));
result->af = af; result->af = af;
if (bits < 0) bits = 0; if (bits < 0) bits = 0;
if (af == AF_INET) if (af == AF_INET)
{ {
if (bits > 32) bits = 32; if (bits > 32) bits = 32;
mask = (0xffffffff << (32 - bits)); mask = (0xffffffff << (32 - bits));
if (bits == 0) mask = 0; if (bits == 0) mask = 0;
result->internal_ip_data.in.s_addr = (((uint8_t*) &mask)[0] << 24) | (((uint8_t*) &mask)[1] << 16) | (((uint8_t*) &mask)[2] << 8) | (((uint8_t*) &mask)[3] << 0); result->internal_ip_data.in.s_addr = (((uint8_t*) &mask)[0] << 24) | (((uint8_t*) &mask)[1] << 16) | (((uint8_t*) &mask)[2] << 8) | (((uint8_t*) &mask)[3] << 0);
} }
else if (af == AF_INET6) else if (af == AF_INET6)
{ {
if (bits > 128) bits = 128; if (bits > 128) bits = 128;
fill = (128-bits) / 8; fill = (128-bits) / 8;
remain_bits = (128-bits) % 8; remain_bits = (128-bits) % 8;
mask = (0xff << (8 - remain_bits)); mask = (0xff << (8 - remain_bits));
for (n = 0; n < fill; n++) for (n = 0; n < fill; n++)
((uint8_t*) &result->internal_ip_data.in6)[n] = (uint8_t) 0xff; ((uint8_t*) &result->internal_ip_data.in6)[n] = (uint8_t) 0xff;
if (fill < 16) if (fill < 16)
((uint8_t*) &result->internal_ip_data.in6)[fill] = (uint8_t) mask; ((uint8_t*) &result->internal_ip_data.in6)[fill] = (uint8_t) mask;
} }
@ -233,32 +233,32 @@ int ip_mask_create_right(int af, int bits, struct ip_addr_encap* result)
memset(result, 0, sizeof(struct ip_addr_encap)); memset(result, 0, sizeof(struct ip_addr_encap));
result->af = af; result->af = af;
if (bits < 0) bits = 0; if (bits < 0) bits = 0;
if (af == AF_INET) if (af == AF_INET)
{ {
if (bits > 32) bits = 32; if (bits > 32) bits = 32;
mask = (0xffffffff >> (32-bits)); mask = (0xffffffff >> (32-bits));
if (bits == 0) mask = 0; if (bits == 0) mask = 0;
result->internal_ip_data.in.s_addr = (((uint8_t*) &mask)[0] << 24) | (((uint8_t*) &mask)[1] << 16) | (((uint8_t*) &mask)[2] << 8) | (((uint8_t*) &mask)[3] << 0); result->internal_ip_data.in.s_addr = (((uint8_t*) &mask)[0] << 24) | (((uint8_t*) &mask)[1] << 16) | (((uint8_t*) &mask)[2] << 8) | (((uint8_t*) &mask)[3] << 0);
} }
else if (af == AF_INET6) else if (af == AF_INET6)
{ {
if (bits > 128) bits = 128; if (bits > 128) bits = 128;
fill = (128-bits) / 8; fill = (128-bits) / 8;
remain_bits = (128-bits) % 8; remain_bits = (128-bits) % 8;
mask8 = (0xff >> (8 - remain_bits)); mask8 = (0xff >> (8 - remain_bits));
start = 16-fill; start = 16-fill;
for (n = 0; n < start; n++) for (n = 0; n < start; n++)
((uint8_t*) &result->internal_ip_data.in6)[n] = (uint8_t) 0x00; ((uint8_t*) &result->internal_ip_data.in6)[n] = (uint8_t) 0x00;
for (n = start; n < 16; n++) for (n = start; n < 16; n++)
((uint8_t*) &result->internal_ip_data.in6)[n] = (uint8_t) 0xff; ((uint8_t*) &result->internal_ip_data.in6)[n] = (uint8_t) 0xff;
if (start > 0) if (start > 0)
((uint8_t*) &result->internal_ip_data.in6)[start-1] = (uint8_t) mask8; ((uint8_t*) &result->internal_ip_data.in6)[start-1] = (uint8_t) mask8;
} }
@ -266,13 +266,13 @@ int ip_mask_create_right(int af, int bits, struct ip_addr_encap* result)
{ {
return -1; return -1;
} }
#ifdef IP_CALC_DEBUG #ifdef IP_CALC_DEBUG
char* r_str = hub_strdup(ip_convert_to_string(result)); char* r_str = hub_strdup(ip_convert_to_string(result));
LOG_DUMP("Created right mask: %s", r_str); LOG_DUMP("Created right mask: %s", r_str);
hub_free(r_str); hub_free(r_str);
#endif #endif
return 0; return 0;
} }
@ -281,7 +281,7 @@ void ip_mask_apply_AND(struct ip_addr_encap* addr, struct ip_addr_encap* mask, s
{ {
memset(result, 0, sizeof(struct ip_addr_encap)); memset(result, 0, sizeof(struct ip_addr_encap));
result->af = addr->af; result->af = addr->af;
if (addr->af == AF_INET) if (addr->af == AF_INET)
{ {
result->internal_ip_data.in.s_addr = addr->internal_ip_data.in.s_addr & mask->internal_ip_data.in.s_addr; result->internal_ip_data.in.s_addr = addr->internal_ip_data.in.s_addr & mask->internal_ip_data.in.s_addr;
@ -294,19 +294,19 @@ void ip_mask_apply_AND(struct ip_addr_encap* addr, struct ip_addr_encap* mask, s
for (n = 0; n < 4; n++) for (n = 0; n < 4; n++)
{ {
offset = n * 4; offset = n * 4;
A = (((uint8_t*) &addr->internal_ip_data.in6)[offset+0] << 24) | A = (((uint8_t*) &addr->internal_ip_data.in6)[offset+0] << 24) |
(((uint8_t*) &addr->internal_ip_data.in6)[offset+1] << 16) | (((uint8_t*) &addr->internal_ip_data.in6)[offset+1] << 16) |
(((uint8_t*) &addr->internal_ip_data.in6)[offset+2] << 8) | (((uint8_t*) &addr->internal_ip_data.in6)[offset+2] << 8) |
(((uint8_t*) &addr->internal_ip_data.in6)[offset+3] << 0); (((uint8_t*) &addr->internal_ip_data.in6)[offset+3] << 0);
B = (((uint8_t*) &mask->internal_ip_data.in6)[offset+0] << 24) | B = (((uint8_t*) &mask->internal_ip_data.in6)[offset+0] << 24) |
(((uint8_t*) &mask->internal_ip_data.in6)[offset+1] << 16) | (((uint8_t*) &mask->internal_ip_data.in6)[offset+1] << 16) |
(((uint8_t*) &mask->internal_ip_data.in6)[offset+2] << 8) | (((uint8_t*) &mask->internal_ip_data.in6)[offset+2] << 8) |
(((uint8_t*) &mask->internal_ip_data.in6)[offset+3] << 0); (((uint8_t*) &mask->internal_ip_data.in6)[offset+3] << 0);
C = A & B; C = A & B;
D = (((uint8_t*) &C)[0] << 24) | D = (((uint8_t*) &C)[0] << 24) |
(((uint8_t*) &C)[1] << 16) | (((uint8_t*) &C)[1] << 16) |
(((uint8_t*) &C)[2] << 8) | (((uint8_t*) &C)[2] << 8) |
@ -321,7 +321,7 @@ void ip_mask_apply_OR(struct ip_addr_encap* addr, struct ip_addr_encap* mask, st
{ {
memset(result, 0, sizeof(struct ip_addr_encap)); memset(result, 0, sizeof(struct ip_addr_encap));
result->af = addr->af; result->af = addr->af;
if (addr->af == AF_INET) if (addr->af == AF_INET)
{ {
result->internal_ip_data.in.s_addr = addr->internal_ip_data.in.s_addr | mask->internal_ip_data.in.s_addr; result->internal_ip_data.in.s_addr = addr->internal_ip_data.in.s_addr | mask->internal_ip_data.in.s_addr;
@ -334,19 +334,19 @@ void ip_mask_apply_OR(struct ip_addr_encap* addr, struct ip_addr_encap* mask, st
for (n = 0; n < 4; n++) for (n = 0; n < 4; n++)
{ {
offset = n * 4; offset = n * 4;
A = (((uint8_t*) &addr->internal_ip_data.in6)[offset+0] << 24) | A = (((uint8_t*) &addr->internal_ip_data.in6)[offset+0] << 24) |
(((uint8_t*) &addr->internal_ip_data.in6)[offset+1] << 16) | (((uint8_t*) &addr->internal_ip_data.in6)[offset+1] << 16) |
(((uint8_t*) &addr->internal_ip_data.in6)[offset+2] << 8) | (((uint8_t*) &addr->internal_ip_data.in6)[offset+2] << 8) |
(((uint8_t*) &addr->internal_ip_data.in6)[offset+3] << 0); (((uint8_t*) &addr->internal_ip_data.in6)[offset+3] << 0);
B = (((uint8_t*) &mask->internal_ip_data.in6)[offset+0] << 24) | B = (((uint8_t*) &mask->internal_ip_data.in6)[offset+0] << 24) |
(((uint8_t*) &mask->internal_ip_data.in6)[offset+1] << 16) | (((uint8_t*) &mask->internal_ip_data.in6)[offset+1] << 16) |
(((uint8_t*) &mask->internal_ip_data.in6)[offset+2] << 8) | (((uint8_t*) &mask->internal_ip_data.in6)[offset+2] << 8) |
(((uint8_t*) &mask->internal_ip_data.in6)[offset+3] << 0); (((uint8_t*) &mask->internal_ip_data.in6)[offset+3] << 0);
C = A | B; C = A | B;
D = (((uint8_t*) &C)[0] << 24) | D = (((uint8_t*) &C)[0] << 24) |
(((uint8_t*) &C)[1] << 16) | (((uint8_t*) &C)[1] << 16) |
(((uint8_t*) &C)[2] << 8) | (((uint8_t*) &C)[2] << 8) |
@ -368,7 +368,7 @@ int ip_compare(struct ip_addr_encap* a, struct ip_addr_encap* b)
(((uint8_t*) &a->internal_ip_data.in.s_addr)[1] << 16) | (((uint8_t*) &a->internal_ip_data.in.s_addr)[1] << 16) |
(((uint8_t*) &a->internal_ip_data.in.s_addr)[2] << 8) | (((uint8_t*) &a->internal_ip_data.in.s_addr)[2] << 8) |
(((uint8_t*) &a->internal_ip_data.in.s_addr)[3] << 0); (((uint8_t*) &a->internal_ip_data.in.s_addr)[3] << 0);
B = (((uint8_t*) &b->internal_ip_data.in.s_addr)[0] << 24) | B = (((uint8_t*) &b->internal_ip_data.in.s_addr)[0] << 24) |
(((uint8_t*) &b->internal_ip_data.in.s_addr)[1] << 16) | (((uint8_t*) &b->internal_ip_data.in.s_addr)[1] << 16) |
(((uint8_t*) &b->internal_ip_data.in.s_addr)[2] << 8) | (((uint8_t*) &b->internal_ip_data.in.s_addr)[2] << 8) |
@ -386,19 +386,19 @@ int ip_compare(struct ip_addr_encap* a, struct ip_addr_encap* b)
(((uint8_t*) &a->internal_ip_data.in6)[offset+1] << 16) | (((uint8_t*) &a->internal_ip_data.in6)[offset+1] << 16) |
(((uint8_t*) &a->internal_ip_data.in6)[offset+2] << 8) | (((uint8_t*) &a->internal_ip_data.in6)[offset+2] << 8) |
(((uint8_t*) &a->internal_ip_data.in6)[offset+3] << 0); (((uint8_t*) &a->internal_ip_data.in6)[offset+3] << 0);
B = (((uint8_t*) &b->internal_ip_data.in6)[offset+0] << 24) | B = (((uint8_t*) &b->internal_ip_data.in6)[offset+0] << 24) |
(((uint8_t*) &b->internal_ip_data.in6)[offset+1] << 16) | (((uint8_t*) &b->internal_ip_data.in6)[offset+1] << 16) |
(((uint8_t*) &b->internal_ip_data.in6)[offset+2] << 8) | (((uint8_t*) &b->internal_ip_data.in6)[offset+2] << 8) |
(((uint8_t*) &b->internal_ip_data.in6)[offset+3] << 0); (((uint8_t*) &b->internal_ip_data.in6)[offset+3] << 0);
if (A == B) continue; if (A == B) continue;
return A - B; return A - B;
} }
return 0; return 0;
} }
#ifdef IP_CALC_DEBUG #ifdef IP_CALC_DEBUG
char* a_str = hub_strdup(ip_convert_to_string(a)); char* a_str = hub_strdup(ip_convert_to_string(a));
char* b_str = hub_strdup(ip_convert_to_string(b)); char* b_str = hub_strdup(ip_convert_to_string(b));
@ -406,7 +406,7 @@ int ip_compare(struct ip_addr_encap* a, struct ip_addr_encap* b)
hub_free(a_str); hub_free(a_str);
hub_free(b_str); hub_free(b_str);
#endif #endif
return ret; return ret;
} }

View File

@ -18,7 +18,7 @@
*/ */
/* /*
* This file is used for fiddling with IP-addresses, * This file is used for fiddling with IP-addresses,
* primarily used for IP-banning in uhub. * primarily used for IP-banning in uhub.
*/ */

View File

@ -449,7 +449,7 @@ int net_is_ipv6_supported()
is_ipv6_supported = 0; is_ipv6_supported = 0;
return 0; return 0;
} }
net_error_out(ret, "net_is_ipv6_supported"); net_error_out(ret, "net_is_ipv6_supported");
} }
else else
@ -508,7 +508,7 @@ const char* net_address_to_string(int af, const void* src, char* dst, socklen_t
size_t size; size_t size;
LPSOCKADDR addr; LPSOCKADDR addr;
DWORD len = cnt; DWORD len = cnt;
switch (af) switch (af)
{ {
case AF_INET: case AF_INET:
@ -531,7 +531,7 @@ const char* net_address_to_string(int af, const void* src, char* dst, socklen_t
default: default:
return NULL; return NULL;
} }
if (WSAAddressToStringA(addr, size, NULL, dst, &len) == 0) if (WSAAddressToStringA(addr, size, NULL, dst, &len) == 0)
{ {
return dst; return dst;
@ -602,15 +602,15 @@ const char* net_get_peer_address(int fd)
struct sockaddr_in* name4; struct sockaddr_in* name4;
struct sockaddr* name; struct sockaddr* name;
socklen_t namelen; socklen_t namelen;
memset(address, 0, INET6_ADDRSTRLEN); memset(address, 0, INET6_ADDRSTRLEN);
namelen = sizeof(struct sockaddr_storage); namelen = sizeof(struct sockaddr_storage);
memset(&storage, 0, namelen); memset(&storage, 0, namelen);
name6 = (struct sockaddr_in6*) &storage; name6 = (struct sockaddr_in6*) &storage;
name4 = (struct sockaddr_in*) &storage; name4 = (struct sockaddr_in*) &storage;
name = (struct sockaddr*) &storage; name = (struct sockaddr*) &storage;
if (getpeername(fd, (struct sockaddr*) name, &namelen) != -1) if (getpeername(fd, (struct sockaddr*) name, &namelen) != -1)
{ {
int af = storage.ss_family; int af = storage.ss_family;

View File

@ -73,7 +73,7 @@ int net_ssl_library_shutdown()
ERR_free_strings(); ERR_free_strings();
EVP_cleanup(); EVP_cleanup();
CRYPTO_cleanup_all_ex_data(); CRYPTO_cleanup_all_ex_data();
// sk_SSL_COMP_free(SSL_COMP_get_compression_methods()); // sk_SSL_COMP_free(SSL_COMP_get_compression_methods());
return 1; return 1;
} }

View File

@ -89,9 +89,9 @@ void timeout_queue_insert(struct timeout_queue* t, struct timeout_evt* evt, size
size_t pos = ((t->last + seconds) % t->max); size_t pos = ((t->last + seconds) % t->max);
evt->timestamp = t->last + seconds; evt->timestamp = t->last + seconds;
evt->next = 0; evt->next = 0;
first = t->events[pos]; first = t->events[pos];
if (first) if (first)
{ {
uhub_assert(first->timestamp == evt->timestamp); uhub_assert(first->timestamp == evt->timestamp);

View File

@ -199,7 +199,7 @@ static plugin_st get_user(struct plugin_handle* plugin, const char* nickname, st
sqlite3_free(errMsg); sqlite3_free(errMsg);
return st_default; return st_default;
} }
if (result.found) if (result.found)
return st_allow; return st_allow;
return st_default; return st_default;
@ -222,7 +222,7 @@ static plugin_st register_user(struct plugin_handle* plugin, struct auth_info* u
return st_deny; return st_deny;
} }
return st_allow; return st_allow;
} }
static plugin_st update_user(struct plugin_handle* plugin, struct auth_info* user) static plugin_st update_user(struct plugin_handle* plugin, struct auth_info* user)
@ -243,7 +243,7 @@ static plugin_st update_user(struct plugin_handle* plugin, struct auth_info* use
return st_deny; return st_deny;
} }
return st_allow; return st_allow;
} }
static plugin_st delete_user(struct plugin_handle* plugin, struct auth_info* user) static plugin_st delete_user(struct plugin_handle* plugin, struct auth_info* user)

View File

@ -135,7 +135,7 @@ static int command_history(struct plugin_handle* plugin, struct plugin_user* use
maxlines = arg->data.integer; maxlines = arg->data.integer;
else else
maxlines = data->history_default; maxlines = data->history_default;
buf = cbuf_create(MAX_HISTORY_SIZE); buf = cbuf_create(MAX_HISTORY_SIZE);
cbuf_append_format(buf, "*** %s: Chat History:\n", cmd->prefix); cbuf_append_format(buf, "*** %s: Chat History:\n", cmd->prefix);
get_messages(data, maxlines, buf); get_messages(data, maxlines, buf);

View File

@ -366,7 +366,7 @@ static int ADC_client_on_recv_line(struct ADC_client* client, const char* line,
} }
*/ */
break; break;
default: default:
break; break;
} }

View File

@ -77,7 +77,7 @@ const char* chat_messages[MAX_CHAT_MSGS] = {
"can anyone help me, pls?", "can anyone help me, pls?",
"wtf?", "wtf?",
"bullshit", "bullshit",
"resistance is futile.", "resistance is futile.",
"You crossed the line first, sir. You squeezed them, you hammered them to the point of desperation. And in their desperation they turned to a man they didn't fully understand.", "You crossed the line first, sir. You squeezed them, you hammered them to the point of desperation. And in their desperation they turned to a man they didn't fully understand.",
"beam me up, scotty", "beam me up, scotty",
"morning", "morning",
@ -87,10 +87,10 @@ const char* chat_messages[MAX_CHAT_MSGS] = {
"*punt*", "*punt*",
"*nudge*", "*nudge*",
"that's ok", "that's ok",
"...anyway", "...anyway",
"hola", "hola",
"hey", "hey",
"hi", "hi",
"nevermind", "nevermind",
"i think so", "i think so",
"dunno", "dunno",
@ -173,7 +173,7 @@ static void perf_chat(struct ADC_client* client, int priv)
else else
cmd = adc_msg_construct_source(ADC_CMD_BMSG, ADC_client_get_sid(client), strlen(msg)); cmd = adc_msg_construct_source(ADC_CMD_BMSG, ADC_client_get_sid(client), strlen(msg));
hub_free(msg); hub_free(msg);
ADC_client_send(client, cmd); ADC_client_send(client, cmd);
} }
@ -294,7 +294,7 @@ static void perf_normal_action(struct ADC_client* client)
bot_output(client, LVL_VERBOSE, "timeout -> chat"); bot_output(client, LVL_VERBOSE, "timeout -> chat");
if (user->logged_in) if (user->logged_in)
perf_chat(client, 0); perf_chat(client, 0);
} }
break; break;
@ -486,7 +486,7 @@ int parse_address(const char* arg)
{ {
if (!arg || strlen(arg) < 9) if (!arg || strlen(arg) < 9)
return 0; return 0;
if (strncmp(arg, "adc://", 6) && strncmp(arg, "adcs://", 7)) if (strncmp(arg, "adc://", 6) && strncmp(arg, "adcs://", 7))
return 0; return 0;
@ -537,7 +537,7 @@ int main(int argc, char** argv)
{ {
parse_command_line(argc, argv); parse_command_line(argc, argv);
net_initialize(); net_initialize();
net_stats_get(&stats_intermediate, &stats_total); net_stats_get(&stats_intermediate, &stats_total);

View File

@ -132,7 +132,7 @@ static int handle(struct ADC_client* client, enum ADC_client_callback_type type,
break; break;
case ADC_CLIENT_USER_JOIN: case ADC_CLIENT_USER_JOIN:
user_add(data->user); user_add(data->user);
break; break;

View File

@ -319,7 +319,7 @@ static int pass(size_t argc, const char** argv)
fprintf(stderr, "Unable to change password for user \"%s\"\n", argv[0]); fprintf(stderr, "Unable to change password for user \"%s\"\n", argv[0]);
return 1; return 1;
} }
return 0; return 0;
} }

View File

@ -71,7 +71,7 @@ const char* auth_cred_to_string(enum auth_credentials cred)
case auth_cred_link: return "link"; case auth_cred_link: return "link";
case auth_cred_admin: return "admin"; case auth_cred_admin: return "admin";
} }
return ""; return "";
}; };

View File

@ -36,7 +36,7 @@ void flood_control_reset(struct flood_control*);
* @param max_count Max count for flood control * @param max_count Max count for flood control
* @param window Time window for max_count to appear. * @param window Time window for max_count to appear.
* @param now The current time. * @param now The current time.
* *
* @return 0 if flood no flood detected. * @return 0 if flood no flood detected.
* 1 if flood detected. * 1 if flood detected.
*/ */

View File

@ -65,7 +65,7 @@ void list_append(struct linked_list* list, void* data_ptr)
return; return;
} }
new_node->ptr = data_ptr; new_node->ptr = data_ptr;
if (list->last) if (list->last)
{ {
list->last->next = new_node; list->last->next = new_node;
@ -123,10 +123,10 @@ void list_remove(struct linked_list* list, void* data_ptr)
{ {
if (node->next) if (node->next)
node->next->prev = node->prev; node->next->prev = node->prev;
if (node->prev) if (node->prev)
node->prev->next = node->next; node->prev->next = node->next;
if (node == list->last) if (node == list->last)
list->last = node->prev; list->last = node->prev;
@ -194,7 +194,7 @@ void* list_get_first(struct linked_list* list)
list->iterator = list->first; list->iterator = list->first;
if (list->iterator == NULL) if (list->iterator == NULL)
return NULL; return NULL;
return list->iterator->ptr; return list->iterator->ptr;
} }
@ -203,7 +203,7 @@ struct node* list_get_first_node(struct linked_list* list)
list->iterator = list->first; list->iterator = list->first;
if (list->iterator == NULL) if (list->iterator == NULL)
return NULL; return NULL;
return list->iterator; return list->iterator;
} }
@ -212,7 +212,7 @@ void* list_get_last(struct linked_list* list)
list->iterator = list->last; list->iterator = list->last;
if (list->iterator == NULL) if (list->iterator == NULL)
return NULL; return NULL;
return list->iterator->ptr; return list->iterator->ptr;
} }
@ -221,9 +221,9 @@ struct node* list_get_last_node(struct linked_list* list)
list->iterator = list->last; list->iterator = list->last;
if (list->iterator == NULL) if (list->iterator == NULL)
return NULL; return NULL;
return list->iterator; return list->iterator;
} }
void* list_get_next(struct linked_list* list) void* list_get_next(struct linked_list* list)
@ -232,7 +232,7 @@ void* list_get_next(struct linked_list* list)
list->iterator = list->first; list->iterator = list->first;
else else
list->iterator = list->iterator->next; list->iterator = list->iterator->next;
if (list->iterator == NULL) if (list->iterator == NULL)
return NULL; return NULL;
@ -244,9 +244,9 @@ void* list_get_prev(struct linked_list* list)
{ {
if (list->iterator == NULL) if (list->iterator == NULL)
return NULL; return NULL;
list->iterator = list->iterator->prev; list->iterator = list->iterator->prev;
if (list->iterator == NULL) if (list->iterator == NULL)
return NULL; return NULL;

View File

@ -86,7 +86,7 @@ void hub_log_initialize(const char* file, int syslog)
return; return;
} }
#endif #endif
#ifndef WIN32 #ifndef WIN32
if (syslog) if (syslog)
{ {
@ -97,13 +97,13 @@ void hub_log_initialize(const char* file, int syslog)
} }
#endif #endif
if (!file) if (!file)
{ {
logfile = stderr; logfile = stderr;
return; return;
} }
logfile = fopen(file, "a"); logfile = fopen(file, "a");
if (!logfile) if (!logfile)
{ {
@ -137,7 +137,7 @@ void hub_log_shutdown()
netdump = NULL; netdump = NULL;
} }
#endif #endif
#ifndef WIN32 #ifndef WIN32
if (use_syslog) if (use_syslog)
{ {
@ -186,7 +186,7 @@ void hub_log(int log_verbosity, const char *format, ...)
return; return;
} }
#endif #endif
if (log_verbosity < verbosity) if (log_verbosity < verbosity)
{ {
t = time(NULL); t = time(NULL);
@ -195,7 +195,7 @@ void hub_log(int log_verbosity, const char *format, ...)
va_start(args, format); va_start(args, format);
vsnprintf(logmsg, 1024, format, args); vsnprintf(logmsg, 1024, format, args);
va_end(args); va_end(args);
if (logfile) if (logfile)
{ {
fprintf(logfile, "%s %6s: %s\n", timestamp, prefixes[log_verbosity], logmsg); fprintf(logfile, "%s %6s: %s\n", timestamp, prefixes[log_verbosity], logmsg);
@ -211,14 +211,14 @@ void hub_log(int log_verbosity, const char *format, ...)
if (use_syslog) if (use_syslog)
{ {
int level = 0; int level = 0;
if (verbosity < log_info) if (verbosity < log_info)
return; return;
va_start(args, format); va_start(args, format);
vsnprintf(logmsg, 1024, format, args); vsnprintf(logmsg, 1024, format, args);
va_end(args); va_end(args);
switch (log_verbosity) switch (log_verbosity)
{ {
case log_fatal: level = LOG_CRIT; break; case log_fatal: level = LOG_CRIT; break;
@ -232,15 +232,15 @@ void hub_log(int log_verbosity, const char *format, ...)
#endif #endif
case log_info: level = LOG_INFO; break; case log_info: level = LOG_INFO; break;
case log_debug: level = LOG_DEBUG; break; case log_debug: level = LOG_DEBUG; break;
default: default:
level = 0; level = 0;
break; break;
} }
if (level == 0) if (level == 0)
return; return;
#ifdef SYSTEMD #ifdef SYSTEMD
sd_journal_print(level, "%s", logmsg); sd_journal_print(level, "%s", logmsg);
@ -250,5 +250,5 @@ void hub_log(int log_verbosity, const char *format, ...)
#endif #endif
} }
#endif #endif
} }

View File

@ -48,7 +48,7 @@ void internal_debug_print_leaks()
size_t leak = 0; size_t leak = 0;
size_t count = 0; size_t count = 0;
LOG_MEMORY("--- exit (allocs: %d, size: " PRINTF_SIZE_T ") ---", hub_alloc_count, hub_alloc_size); LOG_MEMORY("--- exit (allocs: %d, size: " PRINTF_SIZE_T ") ---", hub_alloc_count, hub_alloc_size);
for (; n < UHUB_MAX_ALLOCS; n++) for (; n < UHUB_MAX_ALLOCS; n++)
{ {
if (hub_allocs[n].ptr) if (hub_allocs[n].ptr)
@ -58,7 +58,7 @@ void internal_debug_print_leaks()
LOG_MEMORY("leak %p size: " PRINTF_SIZE_T " (bt: %p %p)", hub_allocs[n].ptr, hub_allocs[n].size, hub_allocs[n].stack1, hub_allocs[n].stack2); LOG_MEMORY("leak %p size: " PRINTF_SIZE_T " (bt: %p %p)", hub_allocs[n].ptr, hub_allocs[n].size, hub_allocs[n].stack1, hub_allocs[n].stack2);
} }
} }
LOG_MEMORY("--- done (allocs: %d, size: " PRINTF_SIZE_T ", peak: %d/" PRINTF_SIZE_T ", oom: " PRINTF_SIZE_T ") ---", count, leak, hub_alloc_peak_count, hub_alloc_peak_size, hub_alloc_oom); LOG_MEMORY("--- done (allocs: %d, size: " PRINTF_SIZE_T ", peak: %d/" PRINTF_SIZE_T ", oom: " PRINTF_SIZE_T ") ---", count, leak, hub_alloc_peak_count, hub_alloc_peak_size, hub_alloc_oom);
} }
#endif /* REALTIME_MALLOC_TRACKING */ #endif /* REALTIME_MALLOC_TRACKING */
@ -67,9 +67,9 @@ void* internal_debug_mem_malloc(size_t size, const char* where)
{ {
size_t n = 0; size_t n = 0;
char* ptr = malloc(size); char* ptr = malloc(size);
#ifdef REALTIME_MALLOC_TRACKING #ifdef REALTIME_MALLOC_TRACKING
/* Make sure the malloc info struct is initialized */ /* Make sure the malloc info struct is initialized */
if (!hub_alloc_count) if (!hub_alloc_count)
{ {
@ -81,17 +81,17 @@ void* internal_debug_mem_malloc(size_t size, const char* where)
hub_allocs[n].stack1 = 0; hub_allocs[n].stack1 = 0;
hub_allocs[n].stack2 = 0; hub_allocs[n].stack2 = 0;
} }
atexit(&internal_debug_print_leaks); atexit(&internal_debug_print_leaks);
} }
if (ptr) if (ptr)
{ {
if (malloc_slot != -1) if (malloc_slot != -1)
n = (size_t) malloc_slot; n = (size_t) malloc_slot;
else else
n = 0; n = 0;
for (; n < UHUB_MAX_ALLOCS; n++) for (; n < UHUB_MAX_ALLOCS; n++)
{ {
if (!hub_allocs[n].ptr) if (!hub_allocs[n].ptr)
@ -100,13 +100,13 @@ void* internal_debug_mem_malloc(size_t size, const char* where)
hub_allocs[n].size = size; hub_allocs[n].size = size;
hub_allocs[n].stack1 = __builtin_return_address(1); hub_allocs[n].stack1 = __builtin_return_address(1);
hub_allocs[n].stack2 = __builtin_return_address(2); hub_allocs[n].stack2 = __builtin_return_address(2);
hub_alloc_size += size; hub_alloc_size += size;
hub_alloc_count++; hub_alloc_count++;
hub_alloc_peak_count = MAX(hub_alloc_count, hub_alloc_peak_count); hub_alloc_peak_count = MAX(hub_alloc_count, hub_alloc_peak_count);
hub_alloc_peak_size = MAX(hub_alloc_size, hub_alloc_peak_size); hub_alloc_peak_size = MAX(hub_alloc_size, hub_alloc_peak_size);
LOG_MEMORY("%s %p (%d bytes) (bt: %p %p) {allocs: %d, size: " PRINTF_SIZE_T "}", where, ptr, (int) size, hub_allocs[n].stack1, hub_allocs[n].stack2, hub_alloc_count, hub_alloc_size); LOG_MEMORY("%s %p (%d bytes) (bt: %p %p) {allocs: %d, size: " PRINTF_SIZE_T "}", where, ptr, (int) size, hub_allocs[n].stack1, hub_allocs[n].stack2, hub_alloc_count, hub_alloc_size);
break; break;
} }
@ -147,7 +147,7 @@ void internal_debug_mem_free(void* ptr)
return; return;
} }
} }
malloc_slot = -1; malloc_slot = -1;
abort(); abort();
LOG_MEMORY("free %p *** NOT ALLOCATED *** (bt: %p %p)", ptr, stack1, stack2); LOG_MEMORY("free %p *** NOT ALLOCATED *** (bt: %p %p)", ptr, stack1, stack2);

View File

@ -37,7 +37,7 @@ static int is_printable(unsigned char c)
{ {
if (c >= 32) if (c >= 32)
return 1; return 1;
if (c == '\t' || c == '\r' || c == '\n') if (c == '\t' || c == '\r' || c == '\n')
return 1; return 1;
return 0; return 0;
@ -59,7 +59,7 @@ char* strip_white_space(char* string)
/* Strip appending whitespace */ /* Strip appending whitespace */
pos = &string[strlen(string)-1]; pos = &string[strlen(string)-1];
while (&string[0] < &pos[0] && is_white_space(pos[0])) { pos[0] = 0; pos--; } while (&string[0] < &pos[0] && is_white_space(pos[0])) { pos[0] = 0; pos--; }
return string; return string;
} }
@ -68,9 +68,9 @@ static int is_valid_utf8_str(const char* string, size_t length)
int expect = 0; int expect = 0;
char div = 0; char div = 0;
size_t pos = 0; size_t pos = 0;
if (length == 0) return 1; if (length == 0) return 1;
for (pos = 0; pos < length; pos++) for (pos = 0; pos < length; pos++)
{ {
if (expect) if (expect)
@ -243,7 +243,7 @@ int file_read_lines(const char* file, void* data, file_line_handler_t handler)
LOG_ERROR("Unable to open file %s: %s", file, strerror(errno)); LOG_ERROR("Unable to open file %s: %s", file, strerror(errno));
return -2; return -2;
} }
ret = read(fd, buf, MAX_RECV_BUF-1); ret = read(fd, buf, MAX_RECV_BUF-1);
close(fd); close(fd);
@ -274,12 +274,12 @@ int uhub_atoi(const char* value) {
int val = 0; int val = 0;
int i = 0; int i = 0;
for (; i < len; i++) for (; i < len; i++)
if (value[i] > '9' || value[i] < '0') if (value[i] > '9' || value[i] < '0')
offset++; offset++;
for (i = offset; i< len; i++) for (i = offset; i< len; i++)
val = val*10 + (value[i] - '0'); val = val*10 + (value[i] - '0');
return value[0] == '-' ? -val : val; return value[0] == '-' ? -val : val;
} }
@ -360,7 +360,7 @@ void* memmem(const void *haystack, size_t haystacklen, const void *needle, size_
char* c_buf = (char*) haystack; char* c_buf = (char*) haystack;
char* c_pat = (char*) needle; char* c_pat = (char*) needle;
char* ptr = memchr(c_buf, c_pat[0], haystacklen); char* ptr = memchr(c_buf, c_pat[0], haystacklen);
while (ptr && ((size_t) (&ptr[0] - &c_buf[0]) < haystacklen)) while (ptr && ((size_t) (&ptr[0] - &c_buf[0]) < haystacklen))
{ {
if (!memcmp(ptr, c_pat, needlelen)) if (!memcmp(ptr, c_pat, needlelen))
@ -382,7 +382,7 @@ int split_string(const char* string, const char* split, struct linked_list* list
for (;;) for (;;)
{ {
tmp1 = strstr(string, split); tmp1 = strstr(string, split);
if (tmp1) tmp2 = hub_strndup(string, tmp1 - string); if (tmp1) tmp2 = hub_strndup(string, tmp1 - string);
else tmp2 = hub_strdup(string); else tmp2 = hub_strdup(string);

View File

@ -57,7 +57,7 @@ void tiger_compress(uint64_t* str, uint64_t state[3]) {
a = state[0]; a = state[0];
b = state[1]; b = state[1];
c = state[2]; c = state[2];
x0 = str[0]; x0 = str[0];
x1 = str[1]; x1 = str[1];
x2 = str[2]; x2 = str[2];
@ -70,7 +70,7 @@ void tiger_compress(uint64_t* str, uint64_t state[3]) {
aa = a; aa = a;
bb = b; bb = b;
cc = c; cc = c;
PASS(a, b, c, 5); PASS(a, b, c, 5);
x0 -= x7 ^ 0xA5A5A5A5A5A5A5A5ULL; x0 -= x7 ^ 0xA5A5A5A5A5A5A5A5ULL;
@ -91,7 +91,7 @@ void tiger_compress(uint64_t* str, uint64_t state[3]) {
x7 -= x6 ^ 0x0123456789ABCDEFULL; x7 -= x6 ^ 0x0123456789ABCDEFULL;
PASS(c, a, b, 7); PASS(c, a, b, 7);
x0 -= x7 ^ 0xA5A5A5A5A5A5A5A5ULL; x0 -= x7 ^ 0xA5A5A5A5A5A5A5A5ULL;
x1 ^= x0; x1 ^= x0;
x2 += x1; x2 += x1;
@ -130,9 +130,9 @@ void tiger_compress(uint64_t* str, uint64_t state[3]) {
x5 ^= x4; x5 ^= x4;
x6 += x5; x6 += x5;
x7 -= x6 ^ 0x0123456789ABCDEFULL; x7 -= x6 ^ 0x0123456789ABCDEFULL;
PASS(a, b, c, 9); PASS(a, b, c, 9);
swap = a; swap = a;
a = c; a = c;
c = b; c = b;
@ -143,7 +143,7 @@ void tiger_compress(uint64_t* str, uint64_t state[3]) {
a ^= aa; a ^= aa;
b -= bb; b -= bb;
c += cc; c += cc;
state[0] = a; state[0] = a;
state[1] = b; state[1] = b;
state[2] = c; state[2] = c;
@ -207,7 +207,7 @@ void tiger(uint64_t* str, uint64_t length, uint64_t res[3]) {
} }
for (; j < 56; j++) temp[j] = 0; for (; j < 56; j++) temp[j] = 0;
((uint64_t*) (&(temp[56])))[0] = ((uint64_t) length) << 3; ((uint64_t*) (&(temp[56])))[0] = ((uint64_t) length) << 3;
tiger_compress(((uint64_t*) temp), res); tiger_compress(((uint64_t*) temp), res);