Get rid of character arrays.
authorfatbob313 <martin@fatbob.nu>
Sun, 24 Jan 2010 21:38:08 +0000 (21:38 +0000)
committerfatbob313 <martin@fatbob.nu>
Sun, 24 Jan 2010 21:38:08 +0000 (21:38 +0000)
Fix speling error...

src/channel.c
src/channel.h
src/conf.c
src/conf.h
src/messagehandler.c
src/messages.h

index d55653b50b9c1300b9dff9e299c0768bdc6186a0..1e71be3db880492061e52e3495aa91665565a581 100644 (file)
@@ -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);
        }
 }
 
index aeb21dc7dfb762c59bdee82f47a0448d1a431923..d0b0a8a4314627b867fff54ff86037a43d134eb4 100644 (file)
@@ -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;
index a9d2c08e88d030429e637d5ae82c408260da2439..4d82e2f1b7e6aa16e0bfe03836fc6ac9af6876c6 100644 (file)
@@ -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;
 }
index 04beaa3ba55428d44b4de29bba472e73bd758981..7967716fa04a65a22f43d5493a3a171a77487464 100644 (file)
@@ -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);
index c69f65ed20ae90a6411034192aadd5bf4344736e..708c33c6ef2defbf24af0387c07e9d91fc15a881 100644 (file)
 #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);
                        
index 732cb87f48b445f1c0d818724be453591d8e054f..9aebc4b6574f8066b8bd957f708b1d5f2a3d6f95 100644 (file)
@@ -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