mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
[QRZ callbook] Add logging if http code not 200
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
Controls the interaction with the QRZ.com Subscription based XML API.
|
||||
@@ -12,7 +12,7 @@ class Qrz {
|
||||
// URL to the XML Source
|
||||
$ci = & get_instance();
|
||||
$xml_feed_url = 'https://xmldata.qrz.com/xml/current/?username='.$username.';password='.urlencode($password).';agent=wavelog';
|
||||
|
||||
|
||||
// CURL Functions
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $xml_feed_url);
|
||||
@@ -23,22 +23,22 @@ class Qrz {
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Wavelog/'.$ci->optionslib->get_option('version'));
|
||||
$xml = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
|
||||
// Create XML object
|
||||
$xml = simplexml_load_string($xml);
|
||||
|
||||
|
||||
// Return Session Key
|
||||
return (string) $xml->Session->Key;
|
||||
}
|
||||
|
||||
|
||||
// Set Session Key session.
|
||||
public function set_session($username, $password) {
|
||||
|
||||
|
||||
$ci = & get_instance();
|
||||
|
||||
|
||||
// URL to the XML Source
|
||||
$xml_feed_url = 'https://xmldata.qrz.com/xml/current/?username='.$username.';password='.urlencode($password).';agent=wavelog';
|
||||
|
||||
|
||||
// CURL Functions
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $xml_feed_url);
|
||||
@@ -49,14 +49,14 @@ class Qrz {
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Wavelog/'.$ci->optionslib->get_option('version'));
|
||||
$xml = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
|
||||
// Create XML object
|
||||
$xml = simplexml_load_string($xml);
|
||||
|
||||
|
||||
$key = (string) $xml->Session->Key;
|
||||
|
||||
|
||||
$ci->session->set_userdata('qrz_session_key', $key);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -78,15 +78,19 @@ class Qrz {
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Wavelog/'.$ci->optionslib->get_option('version'));
|
||||
$xml = curl_exec($ch);
|
||||
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($httpcode != 200) {
|
||||
$message = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
|
||||
log_message('debug', 'QRZ.com search for callsign: ' . $callsign . ' returned message: ' . $message . ' HTTP code: ' . $httpcode);
|
||||
curl_close($ch);
|
||||
return $data['error'] = 'Problems with qrz.com communication'; // Exit function if no 200. If request fails, 0 is returned
|
||||
}
|
||||
curl_close($ch);
|
||||
if ($httpcode != 200) return $data['error'] = 'Problems with qrz.com communication'; // Exit function if no 200. If request fails, 0 is returned
|
||||
|
||||
// Create XML object
|
||||
$xml = simplexml_load_string($xml);
|
||||
if (!empty($xml->Session->Error)) {
|
||||
return $data['error'] = $xml->Session->Error;
|
||||
}
|
||||
|
||||
|
||||
// Return Required Fields
|
||||
$data['callsign'] = (string)$xml->Callsign->call;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user