// File: qian-jiahong[P]uvncrep017-ws/readini.cpp
// Function: readIniFile(char*)
bool readIniFile(char *iniFilePathAndName)
{
    dictionary *dict;
    int ii;
    char tmpBuf[MY_TMP_BUF_LEN];
    char tmpBuf2[MY_TMP_BUF_LEN];
    
    dict = iniparser_new(iniFilePathAndName);
    
    if (dict != NULL) {        
        //General settings
        //General settings
        viewerPort = iniparser_getint(dict, "general:viewerport", 5900);    
        serverPort = iniparser_getint(dict, "general:serverport", 5500);    

        maxSessions = iniparser_getint(dict, "general:maxsessions", MAX_SESSIONS_DEFAULT);
        if (maxSessions > MAX_SESSIONS_MAX)
            maxSessions = MAX_SESSIONS_DEFAULT;
        if (maxSessions < MAX_SESSIONS_MIN)
            maxSessions = MAX_SESSIONS_DEFAULT;

        allowedModes = iniparser_getint(dict, "general:allowedmodes", (CONN_MODE1 | CONN_MODE2));     
        
        strlcpy(ownIpAddress, iniparser_getstring(dict, "general:ownipaddress", "0.0.0.0"), MY_TMP_BUF_LEN);
        
        strlcpy(runAsUser, iniparser_getstring(dict, "general:runasuser", "uvncrep"), MY_TMP_BUF_LEN);
                
        loggingLevel = iniparser_getint(dict, "general:logginglevel", DEFAULT_LOGGING_LEVEL);     
        if (loggingLevel > LEVEL_3)
            loggingLevel = DEFAULT_LOGGING_LEVEL;
        if (loggingLevel < LEVEL_0)
            loggingLevel = DEFAULT_LOGGING_LEVEL;

        
        //Mode 1 settings
        //Mode 1 settings
        allowedMode1ServerPort = iniparser_getint(dict, "mode1:allowedmode1serverport", 0);        
        requireListedServer = iniparser_getint(dict, "mode1:requirelistedserver", 0);        
        if (requireListedServer == 1) {
            //Allowed servers
            for(ii = 0; ii < SERVERS_LIST_SIZE; ii++) {
                snprintf(tmpBuf, MY_TMP_BUF_LEN, "%s%d", "mode1:srvListAllow", ii);
                
                strlcpy(tmpBuf2, iniparser_getstring(dict, tmpBuf, "255.255.255.255"), MY_TMP_BUF_LEN);
                
                srvListAllow[ii] = getAddrPartsFromString(tmpBuf2);
            }


            //Denied servers
            for(ii = 0; ii < SERVERS_LIST_SIZE; ii++) {
                snprintf(tmpBuf, MY_TMP_BUF_LEN, "%s%d", "mode1:srvListDeny", ii);
                
                strlcpy(tmpBuf2, iniparser_getstring(dict, tmpBuf, "255.255.255.255"), MY_TMP_BUF_LEN);
                
                srvListDeny[ii] = getAddrPartsFromString(tmpBuf2);
            }
        }
        
        
        //Mode 2 settings
        //Mode 2 settings
        requireListedId = iniparser_getint(dict, "mode2:requirelistedid", 0);        
        if (requireListedId == 1) {
            for(ii = 0; ii < ID_LIST_SIZE; ii++) {
                snprintf(tmpBuf, MY_TMP_BUF_LEN, "%s%d", "mode2:idlist", ii);
                idList[ii] = iniparser_getint(dict, tmpBuf, 0);
            }
        }
       
        //Event interface settings
        //Event interface settings
        useEventInterface = (bool) iniparser_getboolean(dict, "eventinterface:useeventinterface", 0);     

        strlcpy(eventListenerHost, iniparser_getstring(dict, 
            "eventinterface:eventlistenerhost", "localhost"), MY_TMP_BUF_LEN);

        eventListenerPort = iniparser_getint(dict, "eventinterface:eventlistenerport", 2002);     
        
        useHttpForEventListener = (bool) iniparser_getboolean(dict,"eventinterface:usehttp", 0);     
        
        iniparser_free(dict);
        return true;           
    }
    else 
        return false;
        
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8460
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x8f25
movq -0x18(%rbp), %rdi
leaq 0x3849(%rip), %rsi      # 0xc37b
movl $0x170c, %edx           # imm = 0x170C
callq 0x7e60
movl %eax, 0x66ae(%rip)      # 0xf1f0
movq -0x18(%rbp), %rdi
leaq 0x3841(%rip), %rsi      # 0xc38e
movl $0x157c, %edx           # imm = 0x157C
callq 0x7e60
movl %eax, 0x6697(%rip)      # 0xf1f4
movq -0x18(%rbp), %rdi
leaq 0x3839(%rip), %rsi      # 0xc3a1
movl $0x64, %edx
callq 0x7e60
movl %eax, 0x6ec8(%rip)      # 0xfa40
cmpl $0x3e8, 0x6ebe(%rip)    # imm = 0x3E8
jle 0x8b8e
movl $0x64, 0x6eb2(%rip)     # 0xfa40
cmpl $0x1, 0x6eab(%rip)      # 0xfa40
jge 0x8ba1
movl $0x64, 0x6e9f(%rip)     # 0xfa40
movq -0x18(%rbp), %rdi
leaq 0x3809(%rip), %rsi      # 0xc3b5
movl $0x3, %edx
callq 0x7e60
movl %eax, 0x663c(%rip)      # 0xf1f8
movq -0x18(%rbp), %rdi
leaq 0x3803(%rip), %rsi      # 0xc3ca
leaq 0x3811(%rip), %rdx      # 0xc3df
callq 0x7c80
movq %rax, %rsi
leaq 0x6723(%rip), %rdi      # 0xf300
movl $0xff, %edx
callq 0x76d0
movq -0x18(%rbp), %rdi
leaq 0x37f5(%rip), %rsi      # 0xc3e7
leaq 0x3800(%rip), %rdx      # 0xc3f9
callq 0x7c80
movq %rax, %rsi
leaq 0x65f8(%rip), %rdi      # 0xf200
movl $0xff, %edx
callq 0x76d0
movq -0x18(%rbp), %rdi
leaq 0x37e4(%rip), %rsi      # 0xc401
movl $0x2, %edx
callq 0x7e60
movl %eax, 0x6e17(%rip)      # 0xfa44
cmpl $0x3, 0x6e10(%rip)      # 0xfa44
jle 0x8c40
movl $0x2, 0x6e04(%rip)      # 0xfa44
cmpl $0x0, 0x6dfd(%rip)      # 0xfa44
jge 0x8c53
movl $0x2, 0x6df1(%rip)      # 0xfa44
movq -0x18(%rbp), %rdi
leaq 0x37b8(%rip), %rsi      # 0xc416
xorl %edx, %edx
callq 0x7e60
movl %eax, 0xf4e5(%rip)      # 0x18150
movq -0x18(%rbp), %rdi
leaq 0x37bd(%rip), %rsi      # 0xc433
xorl %edx, %edx
callq 0x7e60
movl %eax, 0xf66d(%rip)      # 0x182f0
cmpl $0x1, 0xf666(%rip)      # 0x182f0
jne 0x8e0e
movl $0x0, -0x1c(%rbp)
cmpl $0x32, -0x1c(%rbp)
jge 0x8d4e
leaq -0x120(%rbp), %rdi
movl -0x1c(%rbp), %r8d
movl $0xff, %esi
leaq 0x3795(%rip), %rdx      # 0xc44d
leaq 0x3793(%rip), %rcx      # 0xc452
movb $0x0, %al
callq 0x2320
leaq -0x220(%rbp), %rax
movq %rax, -0x248(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq 0x377f(%rip), %rdx      # 0xc465
callq 0x7c80
movq -0x248(%rbp), %rdi
movq %rax, %rsi
movl $0xff, %edx
callq 0x76d0
leaq -0x220(%rbp), %rdi
callq 0x8f40
movq %rax, -0x230(%rbp)
movq %rdx, -0x228(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x66dc(%rip), %rax      # 0xf400
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x230(%rbp), %rcx
movq %rcx, (%rax)
movq -0x228(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x8c97
movl $0x0, -0x1c(%rbp)
cmpl $0x32, -0x1c(%rbp)
jge 0x8e0c
leaq -0x120(%rbp), %rdi
movl -0x1c(%rbp), %r8d
movl $0xff, %esi
leaq 0x36d7(%rip), %rdx      # 0xc44d
leaq 0x36f8(%rip), %rcx      # 0xc475
movb $0x0, %al
callq 0x2320
leaq -0x220(%rbp), %rax
movq %rax, -0x250(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq 0x36c1(%rip), %rdx      # 0xc465
callq 0x7c80
movq -0x250(%rbp), %rdi
movq %rax, %rsi
movl $0xff, %edx
callq 0x76d0
leaq -0x220(%rbp), %rdi
callq 0x8f40
movq %rax, -0x240(%rbp)
movq %rdx, -0x238(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x693e(%rip), %rax      # 0xf720
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x240(%rbp), %rcx
movq %rcx, (%rax)
movq -0x238(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x8d55
jmp 0x8e0e
movq -0x18(%rbp), %rdi
leaq 0x366e(%rip), %rsi      # 0xc487
xorl %edx, %edx
callq 0x7e60
movl %eax, 0xf32e(%rip)      # 0x18154
cmpl $0x1, 0xf327(%rip)      # 0x18154
jne 0x8e90
movl $0x0, -0x1c(%rbp)
cmpl $0x64, -0x1c(%rbp)
jge 0x8e8e
leaq -0x120(%rbp), %rdi
movl -0x1c(%rbp), %r8d
movl $0xff, %esi
leaq 0x35fa(%rip), %rdx      # 0xc44d
leaq 0x3643(%rip), %rcx      # 0xc49d
movb $0x0, %al
callq 0x2320
movq -0x18(%rbp), %rdi
leaq -0x120(%rbp), %rsi
xorl %edx, %edx
callq 0x7e60
movl %eax, %edx
movslq -0x1c(%rbp), %rcx
leaq 0xf2e0(%rip), %rax      # 0x18160
movl %edx, (%rax,%rcx,4)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x8e36
jmp 0x8e90
movq -0x18(%rbp), %rdi
leaq 0x360f(%rip), %rsi      # 0xc4aa
xorl %edx, %edx
callq 0x7f20
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0xf444(%rip)       # 0x182f4
movq -0x18(%rbp), %rdi
leaq 0x3610(%rip), %rsi      # 0xc4cb
leaq 0x362a(%rip), %rdx      # 0xc4ec
callq 0x7c80
movq %rax, %rsi
leaq 0x6b7f(%rip), %rdi      # 0xfa50
movl $0xff, %edx
callq 0x76d0
movq -0x18(%rbp), %rdi
leaq 0x3610(%rip), %rsi      # 0xc4f6
movl $0x7d2, %edx            # imm = 0x7D2
callq 0x7e60
movl %eax, 0x6c5a(%rip)      # 0xfb50
movq -0x18(%rbp), %rdi
leaq 0x3616(%rip), %rsi      # 0xc517
xorl %edx, %edx
callq 0x7f20
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0xf3df(%rip)       # 0x182f5
movq -0x18(%rbp), %rdi
callq 0x8940
movb $0x1, -0x1(%rbp)
jmp 0x8f29
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
nopw (%rax,%rax)