// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
callq 0x5c33
movq %rax, %rbx
testq %rax, %rax
je 0x635f
leaq 0x32e4(%rip), %rsi      # 0x9349
movq %rbx, %rdi
movl $0x170c, %edx           # imm = 0x170C
callq 0x595e
movl %eax, 0x6178(%rip)      # 0xc1f0
leaq 0x32dd(%rip), %rsi      # 0x935c
movq %rbx, %rdi
movl $0x157c, %edx           # imm = 0x157C
callq 0x595e
movl %eax, 0x6162(%rip)      # 0xc1f4
leaq 0x32d6(%rip), %rsi      # 0x936f
pushq $0x64
popq %rbp
movq %rbx, %rdi
movl %ebp, %edx
callq 0x595e
cmpl $0x3e9, %eax            # imm = 0x3E9
cmovgel %ebp, %eax
testl %eax, %eax
cmovlel %ebp, %eax
movl %eax, 0x6987(%rip)      # 0xca40
leaq 0x32c3(%rip), %rsi      # 0x9383
pushq $0x3
popq %rdx
movq %rbx, %rdi
callq 0x595e
movl %eax, 0x6127(%rip)      # 0xc1f8
leaq 0x32c0(%rip), %rsi      # 0x9398
leaq 0x32ce(%rip), %rdx      # 0x93ad
movq %rbx, %rdi
callq 0x5867
leaq 0x6212(%rip), %rdi      # 0xc300
movl $0xff, %edx
movq %rax, %rsi
callq 0x553a
leaq 0x32b3(%rip), %rsi      # 0x93b5
leaq 0x32be(%rip), %rdx      # 0x93c7
movq %rbx, %rdi
callq 0x5867
leaq 0x60e8(%rip), %rdi      # 0xc200
movl $0xff, %edx
movq %rax, %rsi
callq 0x553a
leaq 0x32a3(%rip), %rsi      # 0x93cf
pushq $0x2
popq %rbp
movq %rbx, %rdi
movl %ebp, %edx
callq 0x595e
cmpl $0x4, %eax
cmovgel %ebp, %eax
testl %eax, %eax
cmovsl %ebp, %eax
movl %eax, 0x68fa(%rip)      # 0xca44
leaq 0x3293(%rip), %rsi      # 0x93e4
movq %rbx, %rdi
xorl %edx, %edx
callq 0x595e
movl %eax, 0xefbf(%rip)      # 0x15120
leaq 0x3299(%rip), %rsi      # 0x9401
movq %rbx, %rdi
xorl %edx, %edx
callq 0x595e
movl %eax, 0xf148(%rip)      # 0x152c0
cmpl $0x1, %eax
jne 0x6271
leaq 0x6280(%rip), %r15      # 0xc408
movq %rsp, %r12
leaq 0x32a1(%rip), %r13      # 0x9433
leaq 0x100(%rsp), %rbp
xorl %r14d, %r14d
cmpq $0x32, %r14
je 0x61f9
movl $0xff, %esi
movq %r12, %rdi
leaq 0x3269(%rip), %rdx      # 0x941b
leaq 0x3267(%rip), %rcx      # 0x9420
movl %r14d, %r8d
xorl %eax, %eax
callq 0x2320
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x5867
movl $0xff, %edx
movq %rbp, %rdi
movq %rax, %rsi
callq 0x553a
movq %rbp, %rdi
callq 0x6378
movq %rax, -0x8(%r15)
movq %rdx, (%r15)
incq %r14
addq $0x10, %r15
jmp 0x619d
leaq 0x6528(%rip), %r15      # 0xc728
movq %rsp, %r12
leaq 0x3229(%rip), %r13      # 0x9433
leaq 0x100(%rsp), %rbp
xorl %r14d, %r14d
cmpq $0x32, %r14
je 0x6271
movl $0xff, %esi
movq %r12, %rdi
leaq 0x31f1(%rip), %rdx      # 0x941b
leaq 0x3212(%rip), %rcx      # 0x9443
movl %r14d, %r8d
xorl %eax, %eax
callq 0x2320
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x5867
movl $0xff, %edx
movq %rbp, %rdi
movq %rax, %rsi
callq 0x553a
movq %rbp, %rdi
callq 0x6378
movq %rax, -0x8(%r15)
movq %rdx, (%r15)
incq %r14
addq $0x10, %r15
jmp 0x6215
leaq 0x31dd(%rip), %rsi      # 0x9455
movq %rbx, %rdi
xorl %edx, %edx
callq 0x595e
movl %eax, 0xee9c(%rip)      # 0x15124
cmpl $0x1, %eax
jne 0x62df
leaq 0xee9c(%rip), %rbp      # 0x15130
leaq 0x3180(%rip), %r14      # 0x941b
leaq 0x31c9(%rip), %r15      # 0x946b
movq %rsp, %r12
xorl %r13d, %r13d
cmpq $0x64, %r13
je 0x62df
movl $0xff, %esi
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x2320
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x595e
movl %eax, (%rbp)
incq %r13
addq $0x4, %rbp
jmp 0x62a8
leaq 0x3192(%rip), %rsi      # 0x9478
movq %rbx, %rdi
xorl %edx, %edx
callq 0x59a0
testl %eax, %eax
setne 0xefcb(%rip)            # 0x152c4
leaq 0x3199(%rip), %rsi      # 0x9499
leaq 0x31b3(%rip), %rdx      # 0x94ba
movq %rbx, %rdi
callq 0x5867
leaq 0x673a(%rip), %rdi      # 0xca50
movl $0xff, %edx
movq %rax, %rsi
callq 0x553a
leaq 0x319a(%rip), %rsi      # 0x94c4
movq %rbx, %rdi
movl $0x7d2, %edx            # imm = 0x7D2
callq 0x595e
movl %eax, 0x6813(%rip)      # 0xcb50
leaq 0x31a1(%rip), %rsi      # 0x94e5
movq %rbx, %rdi
xorl %edx, %edx
callq 0x59a0
testl %eax, %eax
setne 0xef6e(%rip)            # 0x152c5
movq %rbx, %rdi
callq 0x5f5c
testq %rbx, %rbx
setne %al
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop