From: fatbob313 Date: Sun, 24 Jan 2010 21:38:08 +0000 (+0000) Subject: Get rid of character arrays. X-Git-Url: http://git.code-monkey.de/?p=umurmur.git;a=commitdiff_plain;h=90a18c3aebe9e2478bc9b24bd2d1680e1487cf8f Get rid of character arrays. Fix speling error... --- diff --git a/src/channel.c b/src/channel.c index d55653b..1e71be3 100644 --- a/src/channel.c +++ b/src/channel.c @@ -49,8 +49,9 @@ static channel_t *createChannel(int id, const char *name, const char *desc) Log_fatal("out of memory"); memset(ch, 0, sizeof(channel_t)); ch->id = id; - strncpy(ch->name, name, MAX_TEXT); - strncpy(ch->desc, desc, MAX_TEXT); + ch->name = strdup(name); + if (desc) + ch->desc = strdup(desc); init_list_entry(&ch->subs); init_list_entry(&ch->node); init_list_entry(&ch->clients); @@ -139,7 +140,7 @@ void Chan_init() conf_channel_link_t chlink; const char *defaultChannelName; - defaultChannelName = getStrConf(DEAFULT_CHANNEL); + defaultChannelName = getStrConf(DEFAULT_CHANNEL); for (i = 0; ; i++) { if (Conf_getNextChannel(&chdesc, i) < 0) { @@ -195,7 +196,8 @@ void Chan_init() Chan_iterate(&ch_itr); } while (ch_itr != NULL && strcmp(ch_itr->name, chlink.source) != 0); if (ch_itr == NULL) - Log_fatal("Error in channel link configuration: source channel '%s' not found.", chlink.source); + Log_fatal("Error in channel link configuration: source channel '%s' not found.", + chlink.source); else ch_src = ch_itr; @@ -204,7 +206,8 @@ void Chan_init() Chan_iterate(&ch_itr); } while (ch_itr != NULL && strcmp(ch_itr->name, chlink.destination) != 0); if (ch_itr == NULL) - Log_fatal("Error in channel link configuration: destination channel '%s' not found", chlink.destination); + Log_fatal("Error in channel link configuration: destination channel '%s' not found", + chlink.destination); else ch_dst = ch_itr; @@ -216,10 +219,15 @@ void Chan_init() void Chan_free() { struct dlist *itr, *save; + channel_t *ch; list_iterate_safe(itr, save, &channels) { - Log_debug("Free channel %s", list_get_entry(itr, channel_t, flatlist_node)->name); - free(list_get_entry(itr, channel_t, flatlist_node)); + ch = list_get_entry(itr, channel_t, flatlist_node); + Log_debug("Free channel %s", ch->name); + free(ch->name); + if (ch->desc) + free(ch->desc); + free(ch); } } diff --git a/src/channel.h b/src/channel.h index aeb21dc..d0b0a8a 100644 --- a/src/channel.h +++ b/src/channel.h @@ -37,8 +37,8 @@ typedef struct channel { int id; - char name[MAX_TEXT]; - char desc[MAX_TEXT]; + char *name; + char *desc; struct channel *parent; bool_t temporary, noenter; struct dlist node; diff --git a/src/conf.c b/src/conf.c index a9d2c08..4d82e2f 100644 --- a/src/conf.c +++ b/src/conf.c @@ -135,7 +135,7 @@ const char *getStrConf(param_t param) return DEFAULT_WELCOME; } break; - case DEAFULT_CHANNEL: + case DEFAULT_CHANNEL: setting = config_lookup(&configuration, "default_channel"); if (!setting) return ""; @@ -196,20 +196,20 @@ int Conf_getNextChannel(conf_channel_t *chdesc, int index) setting = config_lookup(&configuration, configstr); if (setting == NULL) return -1; /* Required */ - strncpy(chdesc->name, config_setting_get_string(setting), MAX_TEXT); + chdesc->name = config_setting_get_string(setting); sprintf(configstr, "channels.[%d].parent", index); setting = config_lookup(&configuration, configstr); if (setting == NULL) return -1; /* Required */ - strncpy(chdesc->parent, config_setting_get_string(setting), MAX_TEXT); + chdesc->parent = config_setting_get_string(setting); sprintf(configstr, "channels.[%d].description", index); setting = config_lookup(&configuration, configstr); if (setting == NULL) /* Optional */ - strncpy(chdesc->description, "", MAX_TEXT); + chdesc->description = NULL; else - strncpy(chdesc->description, config_setting_get_string(setting), MAX_TEXT); + chdesc->description = config_setting_get_string(setting); sprintf(configstr, "channels.[%d].noenter", index); setting = config_lookup(&configuration, configstr); @@ -230,13 +230,13 @@ int Conf_getNextChannelLink(conf_channel_link_t *chlink, int index) setting = config_lookup(&configuration, configstr); if (setting == NULL) return -1; - strncpy(chlink->source, config_setting_get_string(setting), MAX_TEXT); + chlink->source = config_setting_get_string(setting); sprintf(configstr, "channel_links.[%d].destination", index); setting = config_lookup(&configuration, configstr); if (setting == NULL) return -1; - strncpy(chlink->destination, config_setting_get_string(setting), MAX_TEXT); + chlink->destination = config_setting_get_string(setting); return 0; } diff --git a/src/conf.h b/src/conf.h index 04beaa3..7967716 100644 --- a/src/conf.h +++ b/src/conf.h @@ -42,19 +42,19 @@ typedef enum param { WELCOMETEXT, MAX_BANDWIDTH, MAX_CLIENTS, - DEAFULT_CHANNEL, + DEFAULT_CHANNEL, } param_t; typedef struct { - char parent[MAX_TEXT]; - char name[MAX_TEXT]; - char description[MAX_TEXT]; + const char *parent; + const char *name; + const char *description; bool_t noenter; } conf_channel_t; typedef struct { - char source[MAX_TEXT]; - char destination[MAX_TEXT]; + const char *source; + const char *destination; } conf_channel_link_t; int Conf_init(const char *conffile); diff --git a/src/messagehandler.c b/src/messagehandler.c index c69f65e..708c33c 100644 --- a/src/messagehandler.c +++ b/src/messagehandler.c @@ -35,11 +35,14 @@ #include "list.h" #include "client.h" #include "messages.h" +#include "messagehandler.h" #include "crypt.h" #include "channel.h" #include "conf.h" #include "voicetarget.h" +#define MAX_TEXT 512 + extern channel_t *defaultChan; extern int iCodecAlpha, iCodecBeta; extern bool_t bPreferAlpha; @@ -112,12 +115,14 @@ void Mh_handle_message(client_t *client, message_t *msg) goto disconnect; } } - if (msg->payload.authenticate->password && strncmp(getStrConf(PASSPHRASE), msg->payload.authenticate->password, MAX_TEXT) != 0) { - char buf[64]; - sprintf(buf, "Wrong server password"); - Log_debug("Wrong server password: %s", msg->payload.authenticate->password); - sendServerReject(client, buf, MUMBLE_PROTO__REJECT__REJECT_TYPE__WrongServerPW); - goto disconnect; + if (strlen(getStrConf(PASSPHRASE)) > 0) { + if (!msg->payload.authenticate->password || strncmp(getStrConf(PASSPHRASE), msg->payload.authenticate->password, MAX_TEXT) != 0) { + char buf[64]; + sprintf(buf, "Wrong server password"); + sendServerReject(client, buf, MUMBLE_PROTO__REJECT__REJECT_TYPE__WrongServerPW); + Log_debug("Wrong server password: %s", msg->payload.authenticate->password); + goto disconnect; + } } if (strlen(msg->payload.authenticate->username) == 0 || strlen(msg->payload.authenticate->username) >= MAX_TEXT) { /* XXX - other invalid names? */ @@ -195,9 +200,8 @@ void Mh_handle_message(client_t *client, message_t *msg) sendmsg->payload.channelState->parent = ch_itr->parent->id; } sendmsg->payload.channelState->name = strdup(ch_itr->name); - if (strlen(ch_itr->desc) > 0) { + if (ch_itr->desc) sendmsg->payload.channelState->description = strdup(ch_itr->desc); - } Log_debug("Send channel info: %s", sendmsg->payload.channelState->name); Client_send_message(client, sendmsg); diff --git a/src/messages.h b/src/messages.h index 732cb87..9aebc4b 100644 --- a/src/messages.h +++ b/src/messages.h @@ -41,9 +41,6 @@ #define PROTVER_PATCH 0 #define PROTOCOL_VERSION ((PROTVER_MAJOR << 16) | (PROTVER_MINOR << 8) | (PROTVER_PATCH)) -#define MAX_TEXT 512 - - #define PERM_NONE 0x0 #define PERM_WRITE 0x1 #define PERM_TRAVERSE 0x2