Diff for /embedaddon/miniupnpd/options.c between versions 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2012/02/21 23:16:02 version 1.1.1.2, 2013/07/22 00:32:35
Line 2 Line 2
 /* MiniUPnP project  /* MiniUPnP project
  * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/   * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
  * author: Ryan Wagoner   * author: Ryan Wagoner
 * (c) 2006 Thomas Bernard  * (c) 2006-2012 Thomas Bernard
  * This software is subject to the conditions detailed   * This software is subject to the conditions detailed
  * in the LICENCE file provided within the distribution */   * in the LICENCE file provided within the distribution */
   
Line 11 Line 11
 #include <stdlib.h>  #include <stdlib.h>
 #include <ctype.h>  #include <ctype.h>
 #include <syslog.h>  #include <syslog.h>
   #include "config.h"
 #include "options.h"  #include "options.h"
 #include "upnppermissions.h"  #include "upnppermissions.h"
 #include "upnpglobalvars.h"  #include "upnpglobalvars.h"
   
   #ifndef DISABLE_CONFIG_FILE
 struct option * ary_options = NULL;  struct option * ary_options = NULL;
int num_options = 0;static char * string_repo = NULL;
 unsigned int num_options = 0;
   
 static const struct {  static const struct {
         enum upnpconfigoptions id;          enum upnpconfigoptions id;
Line 29  static const struct { Line 32  static const struct {
         { UPNPBITRATE_UP, "bitrate_up" },          { UPNPBITRATE_UP, "bitrate_up" },
         { UPNPBITRATE_DOWN, "bitrate_down" },          { UPNPBITRATE_DOWN, "bitrate_down" },
         { UPNPPRESENTATIONURL, "presentation_url" },          { UPNPPRESENTATIONURL, "presentation_url" },
           { UPNPFRIENDLY_NAME, "friendly_name" },
         { UPNPNOTIFY_INTERVAL, "notify_interval" },          { UPNPNOTIFY_INTERVAL, "notify_interval" },
         { UPNPSYSTEM_UPTIME, "system_uptime" },          { UPNPSYSTEM_UPTIME, "system_uptime" },
         { UPNPPACKET_LOG, "packet_log" },          { UPNPPACKET_LOG, "packet_log" },
Line 46  static const struct { Line 50  static const struct {
 #endif  #endif
         { UPNPENABLE, "enable_upnp"},          { UPNPENABLE, "enable_upnp"},
 #ifdef USE_PF  #ifdef USE_PF
           { UPNPANCHOR, "anchor"},
         { UPNPQUEUE, "queue"},          { UPNPQUEUE, "queue"},
         { UPNPTAG, "tag"},          { UPNPTAG, "tag"},
 #endif  #endif
Line 69  readoptionsfile(const char * fname) Line 74  readoptionsfile(const char * fname)
         char *value;          char *value;
         char *t;          char *t;
         int linenum = 0;          int linenum = 0;
        int i;        unsigned int i;
         enum upnpconfigoptions id;          enum upnpconfigoptions id;
           size_t string_repo_len = 0;
           size_t len;
           void *tmp;
   
         if(!fname || (strlen(fname) == 0))          if(!fname || (strlen(fname) == 0))
                 return -1;                  return -1;
Line 93  readoptionsfile(const char * fname) Line 101  readoptionsfile(const char * fname)
         while(fgets(buffer, sizeof(buffer), hfile))          while(fgets(buffer, sizeof(buffer), hfile))
         {          {
                 linenum++;                  linenum++;
                t = strchr(buffer, '\n');                 t = strchr(buffer, '\n');
                 if(t)                  if(t)
                 {                  {
                         *t = '\0';                          *t = '\0';
                         t--;                          t--;
                           /* remove spaces at the end of the line */
                         while((t >= buffer) && isspace(*t))                          while((t >= buffer) && isspace(*t))
                         {                          {
                                 *t = '\0';                                  *t = '\0';
                                 t--;                                  t--;
                         }                          }
                 }                  }
       
                 /* skip leading whitespaces */                  /* skip leading whitespaces */
                 name = buffer;                  name = buffer;
                 while(isspace(*name))                  while(isspace(*name))
Line 116  readoptionsfile(const char * fname) Line 125  readoptionsfile(const char * fname)
                 /* check for UPnP permissions rule */                  /* check for UPnP permissions rule */
                 if(0 == memcmp(name, "allow", 5) || 0 == memcmp(name, "deny", 4))                  if(0 == memcmp(name, "allow", 5) || 0 == memcmp(name, "deny", 4))
                 {                  {
                        upnppermlist = realloc(upnppermlist,                        tmp = realloc(upnppermlist, sizeof(struct upnpperm) * (num_upnpperm+1));
                                               sizeof(struct upnpperm) * (num_upnpperm+1));                        if(tmp == NULL)
                        /* parse the rule */ 
                        if(read_permission_line(upnppermlist + num_upnpperm, name) >= 0) 
                         {                          {
                                num_upnpperm++;                                fprintf(stderr, "memory allocation error. Permission line in file %s line %d\n",
                                         fname, linenum);
                         }                          }
                         else                          else
                         {                          {
                                fprintf(stderr, "parsing error file %s line %d : %s\n",                                upnppermlist = tmp;
                                        fname, linenum, name);                                /* parse the rule */
                                 if(read_permission_line(upnppermlist + num_upnpperm, name) >= 0)
                                 {
                                         num_upnpperm++;
                                 }
                                 else
                                 {
                                         fprintf(stderr, "parsing error file %s line %d : %s\n",
                                                 fname, linenum, name);
                                 }
                         }                          }
                         continue;                          continue;
                 }                  }
Line 163  readoptionsfile(const char * fname) Line 180  readoptionsfile(const char * fname)
   
                 if(id == UPNP_INVALID)                  if(id == UPNP_INVALID)
                 {                  {
                        fprintf(stderr, "parsing error file %s line %d : %s=%s\n",                        fprintf(stderr, "invalid option in file %s line %d : %s=%s\n",
                                 fname, linenum, name, value);                                  fname, linenum, name, value);
                 }                  }
                 else                  else
                 {                  {
                        num_options += 1;                        tmp = realloc(ary_options, (num_options + 1) * sizeof(struct option));
                        ary_options = (struct option *) realloc(ary_options, num_options * sizeof(struct option));                        if(tmp == NULL)
                        {
                        ary_options[num_options-1].id = id;                                fprintf(stderr, "memory allocation error. Option in file %s line %d.\n",
                        strncpy(ary_options[num_options-1].value, value, MAX_OPTION_VALUE_LEN);                                        fname, linenum);
                         }
                         else
                         {
                                 ary_options = tmp;
                                 len = strlen(value) + 1;        /* +1 for terminating '\0' */
                                 tmp = realloc(string_repo, string_repo_len + len);
                                 if(tmp == NULL)
                                 {
                                         fprintf(stderr, "memory allocation error, Option value in file %s line %d : %s=%s\n",
                                                 fname, linenum, name, value);
                                 }
                                 else
                                 {
                                         string_repo = tmp;
                                         memcpy(string_repo + string_repo_len, value, len);
                                         ary_options[num_options].id = id;
                                         /* save the offset instead of the absolute address because realloc() could
                                          * change it */
                                         ary_options[num_options].value = (const char *)string_repo_len;
                                         num_options += 1;
                                         string_repo_len += len;
                                 }
                         }
                 }                  }
   
         }          }
        
         fclose(hfile);          fclose(hfile);
        
         for(i = 0; i < num_options; i++)
         {
                 /* add start address of string_repo to get right pointer */
                 ary_options[i].value = string_repo + (size_t)ary_options[i].value;
         }
 
         return 0;          return 0;
 }  }
   
Line 191  freeoptions(void) Line 237  freeoptions(void)
                 ary_options = NULL;                  ary_options = NULL;
                 num_options = 0;                  num_options = 0;
         }          }
           if(string_repo)
           {
                   free(string_repo);
                   string_repo = NULL;
           }
           if(upnppermlist)
           {
                   free(upnppermlist);
                   upnppermlist = NULL;
                   num_upnpperm = 0;
           }
 }  }
   
   #endif /* DISABLE_CONFIG_FILE */
   

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>