Issue when not using CURL()

Sync Blizzards' Armory data with WoWRoster (addon depreciated no longer works see ApiSync)

Moderators: Ulminia, poetter

Issue when not using CURL()

Postby Pugro » Tue Aug 07, 2007 11:11 pm

Was diging about as someone else was having this issue, basically use CURL and everything OK, disable it and all users come back with an invalid data error as if they have not been updated for a while.

The following wored on my test machine, so if someone else is having the issue as well it may fix it.

The issue is that the non-curl method of getting the data leaves a header before the XML returned from the Blizz servers. This needs to be stripped off before it's passed back up for processing.

I've modified the function getContentFileSocket in functions.general.php:

Code: Select all
function getContentFileSocket($host, $page, $args, $sendAsBrowser = true) {
   global $addon_conf;
   
   $request = "/" . $page . "?" . $args;
   $useragent = "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2";
//   $useragent = "User-Agent: Firefox/2";
   
   $cookie = "cookieLangId=".$addon_conf['ArmorySync']['ArmoryLocale'].";";
   $content = '';
   
   if ($addon_conf['ArmorySync']['DebugLevel'] >= 1) {
      print "GetContentFileSocket: " . $request. ", " . $sendAsBrowser . ", " . $useragent . "<br>";
   }
   
   if ($fp = fsockopen($host, 80, $errno, $errstr, 30)) {
      stream_set_timeout($fp, 30);
      $buffer = '';
      
      $headers =
         "GET $request HTTP/1.0\r\n" .
         "Host: $host\r\n".
         (($sendAsBrowser) ? $useragent : "") .
         //"Content-Length: " . strlen($request) . "\r\n" .
         "\r\nConnection: close\r\n".
         "Cookie: $cookie\r\n".
         "\r\n";
      
      if ($addon_conf['ArmorySync']['DebugLevel'] >= 1) {
         print $headers . "<br>";
      }
      
      fwrite($fp, $headers);
      while (!feof($fp)) {
        $content .= fread($fp, 8192);       
    }
    fclose($fp);
   } else {
      //Throw Error
      print "CRITICAL ERROR - socket not connected";
   }
   
   if ($addon_conf['ArmorySync']['DebugLevel'] >= 2) {
      print $content. "<br>";
   }

   //Now split off the HTML header..
   //anything up to the first <?xml need to go
   $pos = stripos ($content, '<?xml');
   
   if ($pos != 0){
      //Need to trim header off..
      $content = substr ($content, $pos);
   }
   
//      print "<br><br><hr><textarea>$content</textarea><hr><br><br>";
   
   return $content;
}


As usual, I'm not a HUGE php developer, so I looked up the functions to do what I needed, if there's a better way, let me know!

Pugs_
--------------------------------
Pugro_
Ice and Trinity Guilds, Nordrassil, EU PvE
www.iceguild.org.uk, www.trinityguild.net
Image
Pugro
WR.net Journeyman
WR.net Journeyman
 
Posts: 79
Joined: Fri Jul 07, 2006 2:14 pm
Location: London, UK

Re: Issue when not using CURL()

Postby Pugro » Tue Aug 07, 2007 11:13 pm

I also added another CR after the user agent was output, as it seemed that this did not get output and I was just seeing if it was this that was confusing the server you can probably change:

Code: Select all
\r\nConnection


back to

Code: Select all
Connection
--------------------------------
Pugro_
Ice and Trinity Guilds, Nordrassil, EU PvE
www.iceguild.org.uk, www.trinityguild.net
Image
Pugro
WR.net Journeyman
WR.net Journeyman
 
Posts: 79
Joined: Fri Jul 07, 2006 2:14 pm
Location: London, UK

Issue when not using CURL()

Postby Kristoff22 » Wed Aug 08, 2007 5:22 am

Thanks Pugro, I'll have a look at it later this week and hopefully roll it into the changes for the next version.
Kristoff22
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 103
Joined: Mon Nov 13, 2006 5:54 am

Issue when not using CURL()

Postby MortyRS » Fri Aug 10, 2007 5:52 pm

After applying above changes I get the following error when running ArmorySynch :

Fatal error: Call to undefined function: stripos() in */addons/ArmorySynch/functions.general.php on line 94

line 94 : $pos = stripos ($content, '<?xml');


I am running the latest official updated with the gradual (no CURL)

Any idea how to solve this?
Last edited by MortyRS on Fri Aug 10, 2007 5:57 pm, edited 1 time in total.
MortyRS
WR.net Apprentice
WR.net Apprentice
 
Posts: 5
Joined: Wed Aug 30, 2006 2:28 am

Issue when not using CURL()

Postby Pugro » Fri Aug 10, 2007 7:18 pm

Oops, told you I wasn't a proper PHP coder :P

The function appears to be a PHP5 only call, change it to strpos (note, no "i") and it should be ok.
--------------------------------
Pugro_
Ice and Trinity Guilds, Nordrassil, EU PvE
www.iceguild.org.uk, www.trinityguild.net
Image
Pugro
WR.net Journeyman
WR.net Journeyman
 
Posts: 79
Joined: Fri Jul 07, 2006 2:14 pm
Location: London, UK

Issue when not using CURL()

Postby MortyRS » Fri Aug 10, 2007 8:33 pm

thannks, that worked :)
MortyRS
WR.net Apprentice
WR.net Apprentice
 
Posts: 5
Joined: Wed Aug 30, 2006 2:28 am

Issue when not using CURL()

Postby MortyRS » Fri Aug 10, 2007 9:23 pm

blast, getting the
Set-Cookie: JSESSIONID=0AE025FFF41A03AC4BC9B6A29CBD6492.app08_06; Path=/

error now. I better wait till the next update
MortyRS
WR.net Apprentice
WR.net Apprentice
 
Posts: 5
Joined: Wed Aug 30, 2006 2:28 am

Issue when not using CURL()

Postby Pugro » Fri Aug 10, 2007 10:53 pm

I'm prob not going to get a chance to look at this for a while now as something has come up.... I just tried something locally that seemed to work...

Add this function under the above:

Code: Select all
function stripos_b($haystack, $needle){
    return strpos($haystack, stristr( $haystack, $needle ));
}


And change the stripos to stripos_b in that function....like I said, worked for me, but not elegant just in case it works for you until I put a proper fix in the gradual updates stuff.
--------------------------------
Pugro_
Ice and Trinity Guilds, Nordrassil, EU PvE
www.iceguild.org.uk, www.trinityguild.net
Image
Pugro
WR.net Journeyman
WR.net Journeyman
 
Posts: 79
Joined: Fri Jul 07, 2006 2:14 pm
Location: London, UK

Issue when not using CURL()

Postby Pugro » Fri Aug 10, 2007 10:55 pm

/Edit - I'm sure Kristoff22 can pop a proper fix in on this, as opposed to my "Band-aid" :D
--------------------------------
Pugro_
Ice and Trinity Guilds, Nordrassil, EU PvE
www.iceguild.org.uk, www.trinityguild.net
Image
Pugro
WR.net Journeyman
WR.net Journeyman
 
Posts: 79
Joined: Fri Jul 07, 2006 2:14 pm
Location: London, UK

Issue when not using CURL()

Postby MortyRS » Mon Aug 13, 2007 4:40 pm

Code: Select all
    //Now split off the HTML header.. 
    //anything up to the first <?xml need to go
    
$pos strpos ($content'<?xml');
    function 
strpos_b($haystack$needle){
    return 
strpos($haystackstristr$haystack$needle ));
}
 


gives me

Scanning Player: Testplayer
Fatal error: Cannot redeclare strpos_b() (previously declared in /*/addons/ArmorySynch/functions.general.php:95) in /*/addons/ArmorySynch/functions.general.php on line 95


*edit removed the real links :roll:
Last edited by MortyRS on Mon Aug 13, 2007 4:52 pm, edited 1 time in total.
MortyRS
WR.net Apprentice
WR.net Apprentice
 
Posts: 5
Joined: Wed Aug 30, 2006 2:28 am


Return to ArmorySync - Depreciated

Who is online

Users browsing this forum: No registered users and 1 guest

cron