Reputation: 66945
I decided to implement OpenID login into my C++ server. I looked at list of avaliable C++ OpenID clients and found only one popular libopkele
. But its requirements seem quite way 2 much for my simple server which has its own xml parser, uses boost for regexps and so on.
So I want to create simple openID client in C++, so I decided to port PHPclient (because I know PHPa bit). There is class called class.openid.php
which in its first version is just 200 lines of PHP code. My main problem is I never used curl before in PHP nor in c++. SO I beg for help in translating to C/C++ such PHP code:
function CURL_Request($url, $method="GET", $params = "") { // Remember, SSL MUST BE SUPPORTED
if (is_array($params)) $params = $this->array2url($params);
$curl = curl_init($url . ($method == "GET" && $params != "" ? "?" . $params : ""));
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTPGET, ($method == "GET"));
curl_setopt($curl, CURLOPT_POST, ($method == "POST"));
if ($method == "POST") curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if (curl_errno($curl) == 0){
$response;
}else{
$this->ErrorStore('OPENID_CURL', curl_error($curl));
}
return $response;
}
So.. How to translate such function to C++ (using libCURL) from PHP?
Upvotes: 1
Views: 1304
Reputation:
cURL has a C API: link. You can use this from C++ too.
It shouldn't be difficult to rewrite the function you gave when you use the cURL API.
Upvotes: 5