// File: st0ne[P]XReflectorPlus/dxrfd.cpp
// Function: read_config(char*)
static int read_config(char *cfgFile)
{
   short int valid_params = 11;
   short int params = 0;

   FILE *cnf = NULL;
   char inbuf[1024];
   char *p;
   char *ptr = NULL;
   unsigned short int i;
   unsigned short int j;

   cnf = fopen(cfgFile, "r");
   if (!cnf)
   {
      traceit("Failed to open file %s\n", cfgFile);
      return 1;
   }

   traceit("Reading file %s\n", cfgFile);
   while (fgets(inbuf, 1020, cnf) != NULL)
   {
      if (strchr(inbuf, '#'))
         continue;

      p = strchr(inbuf, '\r');
      if (p)
         *p = '\0';
      p = strchr(inbuf, '\n');
      if (p)
         *p = '\0';

      p = strchr(inbuf, '=');
      if (!p)
         continue;
      *p = '\0';

      if (strcmp(inbuf,"OWNER") == 0)
      {
          memset(OWNER,' ', sizeof(OWNER));
          OWNER[OWNER_SIZE] = '\0';

          ptr = strchr(p + 1, ' ');
          if (ptr)
             *ptr = '\0';
          
          if (strlen(p + 1) != OWNER_SIZE - 2)
             traceit("OWNER value %s invalid, length must be exactly %d\n", 
                      p + 1, OWNER_SIZE - 2);
          else
          {
             memcpy(OWNER, p + 1, OWNER_SIZE - 2);

             for (i = 0; i < strlen(OWNER); i++)
                OWNER[i] = toupper(OWNER[i]);

             if ((memcmp(OWNER, "XRF", 3) != 0) ||
                 !isdigit(OWNER[3]) ||
                 !isdigit(OWNER[4]) ||
                 !isdigit(OWNER[5]))
                traceit("Reflector names must be XRFzzz where zzz are digits from 1 thru 9\n");
             else
             {
                traceit("OWNER=%s\n",OWNER);
                params ++;
             }
          }
      }
      else
      if (strcmp(inbuf,"ADMIN") == 0)
      {
          memset(ADMIN,' ', sizeof(ADMIN));
          ADMIN[CALL_SIZE] = '\0';

          /* no spaces after the equal sign */
          if (p[1] == ' ')
             traceit("ADMIN: no spaces after the equal sign\n");
          else
          {
             /* take up to 8 characters, throw away the rest */
             p[CALL_SIZE + 1] = '\0';

             /* valid length? */
             if ((strlen(p + 1) < 3) || (strlen(p + 1) > CALL_SIZE))
                traceit("ADMIN value [%s] invalid\n", p + 1);
             else
             {
                memcpy(ADMIN, p + 1, strlen(p + 1));

                /* uppercase it */
                for (j = 0; j < CALL_SIZE; j++)
                   ADMIN[j] = toupper(ADMIN[j]);

                traceit("ADMIN=[%s]\n",ADMIN);
                params ++;
             }
          }
      }
      else
      if (strcmp(inbuf,"LISTEN_IP") == 0)
      {
         ptr = strchr(p + 1, ' ');
         if (ptr)
            *ptr = '\0';

         if (strlen(p + 1) < 1)
            traceit("LISTEN_IP value %s invalid\n", p + 1);
         else
         {
            memset(LISTEN_IP, '\0', sizeof(LISTEN_IP));
            strncpy(LISTEN_IP, p + 1, IP_SIZE);
            traceit("LISTEN_IP=%s\n",LISTEN_IP);
            params ++;
         }
      }
      else
      if (strcmp(inbuf,"LISTEN_PORT") == 0)
      {
         LISTEN_PORT = atoi(p + 1);
         traceit("LISTEN_PORT=%d\n",LISTEN_PORT);
         params ++;
      }
      else
      if (strcmp(inbuf,"COMMAND_PORT") == 0)
      {
         COMMAND_PORT = atoi(p + 1);
         traceit("COMMAND_PORT=%d\n",COMMAND_PORT);
         params ++;
      }
      else
      if (strcmp(inbuf,"MAX_USERS") == 0)
      {
         MAX_USERS = atoi(p + 1);
         traceit("MAX_USERS=%d\n",MAX_USERS);
         params ++;
      }
      else
      if (strcmp(inbuf,"MAX_OTHER_USERS") == 0)
      {
         MAX_OTHER_USERS = atoi(p + 1); 
         traceit("MAX_OTHER_USERS=%d\n",MAX_OTHER_USERS);
         params ++; 
      }
      else
      if (strcmp(inbuf,"STATUS_FILE") == 0)
      {
         memset(STATUS_FILE, '\0', sizeof(STATUS_FILE));
         strncpy(STATUS_FILE, p + 1,FILENAME_MAX);
         traceit("STATUS_FILE=%s\n",STATUS_FILE);
         params ++;
      }
      else
      if (strcmp(inbuf,"USERS") == 0)
      {
         memset(USERS, '\0', sizeof(USERS));
         strncpy(USERS, p + 1, FILENAME_MAX);
         traceit("USERS=%s\n",USERS);
         params ++;
      }
      else
      if (strcmp(inbuf,"BLOCKS") == 0)
      {
         memset(BLOCKS, '\0', sizeof(BLOCKS));
         strncpy(BLOCKS, p + 1, FILENAME_MAX);
         traceit("BLOCKS=%s\n",BLOCKS);
         params ++;
      }
      else
      if (strcmp(inbuf,"QSO_DETAILS") == 0)
      {
         if (*(p + 1) == 'Y')
            QSO_DETAILS = true;
         else
            QSO_DETAILS = false;
         traceit("QSO_DETAILS=%c\n", *(p + 1));
         params ++;
      }
   }
   fclose(cnf);

   if (params != valid_params)
   {
      traceit("Configuration file %s invalid\n",cfgFile);
      return 1;
   }      

   if (COMMAND_PORT == LISTEN_PORT)
   {
      traceit("Error: COMMAND_PORT must be different from LISTEN_PORT\n");
      return 1;
   }
   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x450, %rsp            # imm = 0x450
movq %rdi, -0x10(%rbp)
movw $0xb, -0x12(%rbp)
movw $0x0, -0x14(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x430(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x13437(%rip), %rsi     # 0x171e0
callq 0x3380
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x3dd7
movq -0x10(%rbp), %rsi
leaq 0x1341e(%rip), %rdi     # 0x171e2
movb $0x0, %al
callq 0x3820
movl $0x1, -0x4(%rbp)
jmp 0x45ff
movq -0x10(%rbp), %rsi
leaq 0x13418(%rip), %rdi     # 0x171fa
movb $0x0, %al
callq 0x3820
leaq -0x420(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl $0x3fc, %esi            # imm = 0x3FC
callq 0x34b0
cmpq $0x0, %rax
je 0x45a3
leaq -0x420(%rbp), %rdi
movl $0x23, %esi
callq 0x3120
cmpq $0x0, %rax
je 0x3e21
jmp 0x3de9
leaq -0x420(%rbp), %rdi
movl $0xd, %esi
callq 0x3120
movq %rax, -0x428(%rbp)
cmpq $0x0, -0x428(%rbp)
je 0x3e4d
movq -0x428(%rbp), %rax
movb $0x0, (%rax)
leaq -0x420(%rbp), %rdi
movl $0xa, %esi
callq 0x3120
movq %rax, -0x428(%rbp)
cmpq $0x0, -0x428(%rbp)
je 0x3e79
movq -0x428(%rbp), %rax
movb $0x0, (%rax)
leaq -0x420(%rbp), %rdi
movl $0x3d, %esi
callq 0x3120
movq %rax, -0x428(%rbp)
cmpq $0x0, -0x428(%rbp)
jne 0x3ea0
jmp 0x3de9
movq -0x428(%rbp), %rax
movb $0x0, (%rax)
leaq -0x420(%rbp), %rdi
leaq 0x13353(%rip), %rsi     # 0x1720b
callq 0x3460
cmpl $0x0, %eax
jne 0x4063
leaq 0x1ecb3(%rip), %rdi     # 0x22b80
movl $0x20, %esi
movl $0x9, %edx
callq 0x31a0
movb $0x0, 0x1eca5(%rip)     # 0x22b88
movq -0x428(%rbp), %rdi
addq $0x1, %rdi
movl $0x20, %esi
callq 0x3120
movq %rax, -0x430(%rbp)
cmpq $0x0, -0x430(%rbp)
je 0x3f13
movq -0x430(%rbp), %rax
movb $0x0, (%rax)
movq -0x428(%rbp), %rdi
addq $0x1, %rdi
callq 0x3150
cmpq $0x6, %rax
je 0x3f4c
movq -0x428(%rbp), %rsi
addq $0x1, %rsi
leaq 0x132d6(%rip), %rdi     # 0x17211
movl $0x6, %edx
movb $0x0, %al
callq 0x3820
jmp 0x405e
movq -0x428(%rbp), %rax
movl 0x1(%rax), %ecx
movl %ecx, 0x1ec24(%rip)     # 0x22b80
movw 0x5(%rax), %ax
movw %ax, 0x1ec1d(%rip)      # 0x22b84
movw $0x0, -0x432(%rbp)
movzwl -0x432(%rbp), %eax
movq %rax, -0x440(%rbp)
leaq 0x1ebfb(%rip), %rdi     # 0x22b80
callq 0x3150
movq %rax, %rcx
movq -0x440(%rbp), %rax
cmpq %rcx, %rax
jae 0x3fdb
movzwl -0x432(%rbp), %eax
movl %eax, %ecx
leaq 0x1ebd7(%rip), %rax     # 0x22b80
movsbl (%rax,%rcx), %edi
callq 0x3560
movb %al, %dl
movzwl -0x432(%rbp), %eax
movl %eax, %ecx
leaq 0x1ebbc(%rip), %rax     # 0x22b80
movb %dl, (%rax,%rcx)
movw -0x432(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x432(%rbp)
jmp 0x3f70
leaq 0x1eb9e(%rip), %rdi     # 0x22b80
leaq 0x1325b(%rip), %rsi     # 0x17244
movl $0x3, %edx
callq 0x3170
cmpl $0x0, %eax
jne 0x402b
movsbl 0x1eb84(%rip), %edi     # 0x22b83
callq 0x3290
cmpl $0x0, %eax
je 0x402b
movsbl 0x1eb74(%rip), %edi     # 0x22b84
callq 0x3290
cmpl $0x0, %eax
je 0x402b
movsbl 0x1eb64(%rip), %edi     # 0x22b85
callq 0x3290
cmpl $0x0, %eax
jne 0x403b
leaq 0x13216(%rip), %rdi     # 0x17248
movb $0x0, %al
callq 0x3820
jmp 0x405c
leaq 0x13249(%rip), %rdi     # 0x1728b
leaq 0x1eb37(%rip), %rsi     # 0x22b80
movb $0x0, %al
callq 0x3820
movw -0x14(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x14(%rbp)
jmp 0x405e
jmp 0x459e
leaq -0x420(%rbp), %rdi
leaq 0x13224(%rip), %rsi     # 0x17295
callq 0x3460
cmpl $0x0, %eax
jne 0x41cb
leaq 0x1eb03(%rip), %rdi     # 0x22b89
movl $0x20, %esi
movl $0x9, %edx
callq 0x31a0
movb $0x0, 0x1eaf5(%rip)     # 0x22b91
movq -0x428(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x20, %eax
jne 0x40bf
leaq 0x131e8(%rip), %rdi     # 0x1729b
movb $0x0, %al
callq 0x3820
jmp 0x41c6
movq -0x428(%rbp), %rax
movb $0x0, 0x9(%rax)
movq -0x428(%rbp), %rdi
addq $0x1, %rdi
callq 0x3150
cmpq $0x3, %rax
jb 0x40f6
movq -0x428(%rbp), %rdi
addq $0x1, %rdi
callq 0x3150
cmpq $0x8, %rax
jbe 0x4114
movq -0x428(%rbp), %rsi
addq $0x1, %rsi
leaq 0x131ba(%rip), %rdi     # 0x172c2
movb $0x0, %al
callq 0x3820
jmp 0x41c4
movq -0x428(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x448(%rbp)
movq -0x428(%rbp), %rdi
addq $0x1, %rdi
callq 0x3150
movq -0x448(%rbp), %rsi
movq %rax, %rdx
leaq 0x1ea42(%rip), %rdi     # 0x22b89
callq 0x3260
movw $0x0, -0x434(%rbp)
movzwl -0x434(%rbp), %eax
cmpl $0x8, %eax
jge 0x41a3
movzwl -0x434(%rbp), %eax
movl %eax, %ecx
leaq 0x1ea18(%rip), %rax     # 0x22b89
movsbl (%rax,%rcx), %edi
callq 0x3560
movb %al, %dl
movzwl -0x434(%rbp), %eax
movl %eax, %ecx
leaq 0x1e9fd(%rip), %rax     # 0x22b89
movb %dl, (%rax,%rcx)
movw -0x434(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x434(%rbp)
jmp 0x4155
leaq 0x13132(%rip), %rdi     # 0x172dc
leaq 0x1e9d8(%rip), %rsi     # 0x22b89
movb $0x0, %al
callq 0x3820
movw -0x14(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x14(%rbp)
jmp 0x41c6
jmp 0x459c
leaq -0x420(%rbp), %rdi
leaq 0x1310f(%rip), %rsi     # 0x172e8
callq 0x3460
cmpl $0x0, %eax
jne 0x429d
movq -0x428(%rbp), %rdi
addq $0x1, %rdi
movl $0x20, %esi
callq 0x3120
movq %rax, -0x430(%rbp)
cmpq $0x0, -0x430(%rbp)
je 0x4217
movq -0x430(%rbp), %rax
movb $0x0, (%rax)
movq -0x428(%rbp), %rdi
addq $0x1, %rdi
callq 0x3150
cmpq $0x1, %rax
jae 0x4248
movq -0x428(%rbp), %rsi
addq $0x1, %rsi
leaq 0x130b3(%rip), %rdi     # 0x172f2
movb $0x0, %al
callq 0x3820
jmp 0x4298
leaq 0x1e951(%rip), %rdi     # 0x22ba0
xorl %esi, %esi
movl $0x10, %edx
callq 0x31a0
movq -0x428(%rbp), %rsi
addq $0x1, %rsi
leaq 0x1e933(%rip), %rdi     # 0x22ba0
movl $0xf, %edx
callq 0x3180
leaq 0x13090(%rip), %rdi     # 0x1730e
leaq 0x1e91b(%rip), %rsi     # 0x22ba0
movb $0x0, %al
callq 0x3820
movw -0x14(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x14(%rbp)
jmp 0x459a
leaq -0x420(%rbp), %rdi
leaq 0x13071(%rip), %rsi     # 0x1731c
callq 0x3460
cmpl $0x0, %eax
jne 0x42f0
movq -0x428(%rbp), %rdi
addq $0x1, %rdi
callq 0x3490
movl %eax, 0x1b01d(%rip)     # 0x1f2e8
movl 0x1b017(%rip), %esi     # 0x1f2e8
leaq 0x13050(%rip), %rdi     # 0x17328
movb $0x0, %al
callq 0x3820
movw -0x14(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x14(%rbp)
jmp 0x4598
leaq -0x420(%rbp), %rdi
leaq 0x1303a(%rip), %rsi     # 0x17338
callq 0x3460
cmpl $0x0, %eax
jne 0x4343
movq -0x428(%rbp), %rdi
addq $0x1, %rdi
callq 0x3490
movl %eax, 0x1afce(%rip)     # 0x1f2ec
movl 0x1afc8(%rip), %esi     # 0x1f2ec
leaq 0x1301a(%rip), %rdi     # 0x17345
movb $0x0, %al
callq 0x3820
movw -0x14(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x14(%rbp)
jmp 0x4596
leaq -0x420(%rbp), %rdi
leaq 0x13005(%rip), %rsi     # 0x17356
callq 0x3460
cmpl $0x0, %eax
jne 0x4396
movq -0x428(%rbp), %rdi
addq $0x1, %rdi
callq 0x3490
movl %eax, 0x1af7f(%rip)     # 0x1f2f0
movl 0x1af79(%rip), %esi     # 0x1f2f0
leaq 0x12fe2(%rip), %rdi     # 0x17360
movb $0x0, %al
callq 0x3820
movw -0x14(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x14(%rbp)
jmp 0x4594
leaq -0x420(%rbp), %rdi
leaq 0x12fca(%rip), %rsi     # 0x1736e
callq 0x3460
cmpl $0x0, %eax
jne 0x43e9
movq -0x428(%rbp), %rdi
addq $0x1, %rdi
callq 0x3490
movl %eax, 0x1af30(%rip)     # 0x1f2f4
movl 0x1af2a(%rip), %esi     # 0x1f2f4
leaq 0x12fad(%rip), %rdi     # 0x1737e
movb $0x0, %al
callq 0x3820
movw -0x14(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x14(%rbp)
jmp 0x4592
leaq -0x420(%rbp), %rdi
leaq 0x12f9b(%rip), %rsi     # 0x17392
callq 0x3460
cmpl $0x0, %eax
jne 0x4456
leaq 0x1d768(%rip), %rdi     # 0x21b70
xorl %esi, %esi
movl $0x1001, %edx           # imm = 0x1001
callq 0x31a0
movq -0x428(%rbp), %rsi
addq $0x1, %rsi
leaq 0x1d74a(%rip), %rdi     # 0x21b70
movl $0x1000, %edx           # imm = 0x1000
callq 0x3180
leaq 0x12f67(%rip), %rdi     # 0x1739e
leaq 0x1d732(%rip), %rsi     # 0x21b70
movb $0x0, %al
callq 0x3820
movw -0x14(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x14(%rbp)
jmp 0x4590
leaq -0x420(%rbp), %rdi
leaq 0x12f14(%rip), %rsi     # 0x17378
callq 0x3460
cmpl $0x0, %eax
jne 0x44c3
leaq 0x1b05b(%rip), %rdi     # 0x1f4d0
xorl %esi, %esi
movl $0x1001, %edx           # imm = 0x1001
callq 0x31a0
movq -0x428(%rbp), %rsi
addq $0x1, %rsi
leaq 0x1b03d(%rip), %rdi     # 0x1f4d0
movl $0x1000, %edx           # imm = 0x1000
callq 0x3180
leaq 0x12f0a(%rip), %rdi     # 0x173ae
leaq 0x1b025(%rip), %rsi     # 0x1f4d0
movb $0x0, %al
callq 0x3820
movw -0x14(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x14(%rbp)
jmp 0x458e
leaq -0x420(%rbp), %rdi
leaq 0x12ee7(%rip), %rsi     # 0x173b8
callq 0x3460
cmpl $0x0, %eax
jne 0x452d
leaq 0x1bffe(%rip), %rdi     # 0x204e0
xorl %esi, %esi
movl $0x1001, %edx           # imm = 0x1001
callq 0x31a0
movq -0x428(%rbp), %rsi
addq $0x1, %rsi
leaq 0x1bfe0(%rip), %rdi     # 0x204e0
movl $0x1000, %edx           # imm = 0x1000
callq 0x3180
leaq 0x12eae(%rip), %rdi     # 0x173bf
leaq 0x1bfc8(%rip), %rsi     # 0x204e0
movb $0x0, %al
callq 0x3820
movw -0x14(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x14(%rbp)
jmp 0x458c
leaq -0x420(%rbp), %rdi
leaq 0x12e8f(%rip), %rsi     # 0x173ca
callq 0x3460
cmpl $0x0, %eax
jne 0x458a
movq -0x428(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x59, %eax
jne 0x455e
movb $0x1, 0x1e654(%rip)     # 0x22bb0
jmp 0x4565
movb $0x0, 0x1e64b(%rip)     # 0x22bb0
movq -0x428(%rbp), %rax
movsbl 0x1(%rax), %esi
leaq 0x12e5f(%rip), %rdi     # 0x173d6
movb $0x0, %al
callq 0x3820
movw -0x14(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x14(%rbp)
jmp 0x458c
jmp 0x458e
jmp 0x4590
jmp 0x4592
jmp 0x4594
jmp 0x4596
jmp 0x4598
jmp 0x459a
jmp 0x459c
jmp 0x459e
jmp 0x3de9
movq -0x20(%rbp), %rdi
callq 0x32d0
movswl -0x14(%rbp), %eax
movswl -0x12(%rbp), %ecx
cmpl %ecx, %eax
je 0x45d3
movq -0x10(%rbp), %rsi
leaq 0x12e23(%rip), %rdi     # 0x173e6
movb $0x0, %al
callq 0x3820
movl $0x1, -0x4(%rbp)
jmp 0x45ff
movl 0x1ad13(%rip), %eax     # 0x1f2ec
cmpl 0x1ad09(%rip), %eax     # 0x1f2e8
jne 0x45f8
leaq 0x12e1d(%rip), %rdi     # 0x17405
movb $0x0, %al
callq 0x3820
movl $0x1, -0x4(%rbp)
jmp 0x45ff
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x450, %rsp            # imm = 0x450
popq %rbp
retq
nopl (%rax,%rax)