Luigi Auriemma

aluigi.org (ARCHIVE-ONLY FORUM!)
It is currently 19 Jul 2012 13:30

All times are UTC [ DST ]





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: proxocket problem
PostPosted: 10 May 2009 18:47 

Joined: 24 Oct 2007 00:44
Posts: 26
I am trying to load an INI file, get the number of strings to search for and replace, and then replace them.
Code:

int mysend(SOCKET s, u_char **retbuf, int len, int flags) {
    u_char  *buf = *retbuf; // do NOT touch this

   /*test start*/
   int      total,current;
   char   *search;
   char   *replaced;
   char   keys[50];
   char   keyr[50];


   GetPrivateProfileInt("Main","total",total,"C:\\test.in");

   if(total>0)
   {
      for(current=0;current<total;current++)
      {
         sprintf(keys,"search(%i)",current);
         sprintf(keyr,"replace(%i)",current);

         GetPrivateProfileString("REPLACE", keyr, NULL, replaced, 50, "C:\\test.ini");
         GetPrivateProfileString("SEARCH", keys, NULL, search, 50, "C:\\test.ini");
         if(!strstr(buf,search))
         {
            buf=find_replace_string(buf, &len, search,replaced);
         }
      
      }
   }
   /*test end*/

    *retbuf = buf;  // do NOT touch this
    return(len);
}


this makes the program crash.
any ideas?


Top
 Profile  
 
 
 Post subject: Re: proxocket problem
PostPosted: 10 May 2009 18:51 

Joined: 24 Oct 2007 00:44
Posts: 26
The ini would look like this:
Code:
[Main]
total=1
[SEARCH]
search(0)=what
[REPLACE]
replace(0)=tahw


Top
 Profile  
 
 Post subject: Re: proxocket problem
PostPosted: 10 May 2009 19:59 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
from a first look I see various errors.
the first is "C:\\test.in" without the final 'i'
then the absence of the handling of the return value in GetPrivateProfileInt, indeed the correct usage is:
Code:
total = GetPrivateProfileInt("Main","total",0,"C:\\test.ini");

then the "search" and "replace" which are pointer and not buffer and more.
the following is the corrected code:
Code:
int mysend(SOCKET s, u_char **retbuf, int len, int flags) {
    u_char  *buf = *retbuf; // do NOT touch this

   /*test start*/
   int      total,current;
   char   search[50];
   char   replaced[50];
   char   keys[50];
   char   keyr[50];

   total = GetPrivateProfileInt("Main","total",0,"C:\\test.ini");

   if(total>0)
   {
      for(current=0;current<total;current++)
      {
         sprintf(keys,"search(%i)",current);
         sprintf(keyr,"replace(%i)",current);

         if(!GetPrivateProfileString("REPLACE", keyr, NULL, replaced, sizeof(replaced), "C:\\test.ini")) continue;
         if(!GetPrivateProfileString("SEARCH", keys, NULL, search, sizeof(search), "C:\\test.ini")) continue;
         buf=find_replace_string(buf, &len, search,replaced);
      }
   }
   /*test end*/

    *retbuf = buf;  // do NOT touch this
    return(len);
}


Top
 Profile  
 
 Post subject: Re: proxocket problem
PostPosted: 10 May 2009 20:28 

Joined: 24 Oct 2007 00:44
Posts: 26
damn such noob errors, feel like a tard now -_-
learn from mistakes though...

tested and working, ty aluigi.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron