Problem in retrieving the ini file through web page

Posted by MalarN on Stack Overflow See other posts from Stack Overflow or by MalarN
Published on 2010-01-28T07:13:46Z Indexed on 2010/03/28 6:03 UTC
Read the original article Hit count: 384

Filed under:
|

Hi All,

I am using an .ini file to store some values and retrieve values from it using the iniparser.

When I give (hardcode) the query and retrive the value through the command line, I am able to retrive the ini file and do some operation.

But when I pass the query through http, then I am getting an error (file not found), i.e., the ini file couldn't be loaded.


  • Command line :

int main(void)
{
   printf("Content-type: text/html; charset=utf-8\n\n");

   char* data = "/cgi-bin/set.cgi?pname=x&value=700&url=http://IP/home.html";

   //perform some operation
}

  • Through http:

.html

function SetValue(id)
{
    var val;
    var URL = window.location.href;
    if(id =="set")
    {
        document.location = "/cgi-bin/set.cgi?pname="+rwparams+"&value="+val+"&url="+URL;
    }
}

  • .c

int * Value(char* pname)
{
    dictionary * ini ;
    char *key1 = NULL;
    char *key2 =NULL;
    int i =0;

    int val;

    ini = iniparser_load("file.ini");
    if(ini != NULL)
    {
        //key for fetching the value
        key1 = (char*)malloc(sizeof(char)*50);
        if(key1 != NULL)
        {                   
                strcpy(key1,"ValueList:");
                key2 = (char*)malloc(sizeof(char)*50);
                if(key2 != NULL)
                {
                    strcpy(key2,pname);
                    strcat(key1,key2);                  
                    val = iniparser_getint(ini, key1, -1);
                    if(-1 == val || 0 > val)
                    {
                        return 0;                       
                    }
                }
                else
                {
                    //error
                    free(key1);                     
                    return;
                }           
        }       
        else
        {   
            printf("ERROR : Memory Allocation Failure ");
            return;
        }

    }
    else
    {
        printf("ERROR : .ini File Missing");
        return;
    }
    iniparser_freedict(ini);
    free(key1);
    free(key2);
    return (int *)val;
}

void get_Value(char* pname,char* value)
{
        int result =0;                          
        result = Value(pname);
        printf("Result : %d",result);           
}

int main(void)
{
    printf("Content-type: text/html; charset=utf-8\n\n");

    char* data = getenv("QUERY_STRING");    
    //char* data = "/cgi-bin/set.cgi?pname=x&value=700&url=http://10.50.25.40/home.html";

    //Parse to get the values seperately as parameter name, parameter value, url

    //Calling get_Value method to set the value
    get_Value(final_para,final_val);

}

*

  • file.ini

*

[ValueList]

x   = 100;
y   = 70;

When the request is sent through html page, I am always getting .ini file missing. If directly the request is sent from C file them it works fine.

How to resolve this?

© Stack Overflow or respective owner

Related posts about c

    Related posts about ini