Commit 6a5bc7fe authored by mr-ti's avatar mr-ti
Browse files

No commit message

No commit message
parent 81202ee4
......@@ -29,7 +29,7 @@ IF(NOT DEFINED project_WC_REVISION)
ENDIF(NOT DEFINED project_WC_REVISION)
SET(global_unicomctrl_DEFS ${global_unicomctrl_DEFS} -D_UNI_REVISION="\\"${project_WC_REVISION}\\"" -D_UNI_VERSION="\\"0.7.0a0\\"")
MESSAGE("UniComPlug Project revision ${project_WC_REVISION}")
MESSAGE("DDnsSync Project revision ${project_WC_REVISION}")
SUBDIRS(ddnssbase ddnssync)
#SUBDIRS(ddnssbase ddnssync ddnssplugins)
......@@ -2,7 +2,7 @@
PROJECT(ddnssbase)
# ### COMMUN ###
SET(ddnssbase_SRCS ddnsshttpcl.cpp)
SET(ddnssbase_SRCS ddnsshttpcl.cpp cregex.cpp)
SET(ddnssbase_LIBS unicomcl curl)
SET(ddnssbase_DEFS ${global_unicomctrl_DEFS})
SET(ddnssbase_LDFS )
......
......@@ -13,6 +13,7 @@
#include <iostream>
CRegex::CRegex(const string &expr, int flags)
: CUniObj()
{
errNo=regcomp(&regex,expr.c_str(),flags);
if(errNo==0){
......@@ -62,6 +63,14 @@ bool CRegex::exec(int flags){
}
}
string CRegex::getFirstMatch(){
string match;
if(exec()){
match=buffer->substr(pmatch[0].rm_so,pmatch[0].rm_eo - pmatch[0].rm_so);
}
return match;
}
list<string> CRegex::getMatchs(){
list<string> lst;
if(state!=ERROR){
......@@ -78,3 +87,11 @@ void CRegex::setBuffer(string *buffer){
offset=0;
this->buffer=buffer;
}
/**
* @brief The ame of the class.
* @return "CRegex"
*/
string CRegex::className() {
return "CRegex";
}
......@@ -14,10 +14,9 @@
#include <string>
#include <list>
#include <regex.h>
#include <unicomctrl/cuniobj.h>
using namespace std;
class CRegex{
class CRegex : public CUniObj{
public:
typedef enum State{
NOSTATE,
......@@ -31,8 +30,10 @@ public:
bool exec(int flags=0);
State getState();
list<string> getMatchs();
string getFirstMatch();
int getErrorNb();
string getErrorMsg();
virtual string className();
private:
State state;
regex_t regex;
......
......@@ -10,6 +10,7 @@
//
//
#include "ddnsshttpcl.h"
#include "cregex.h"
string *DdnssHttpCl::resBuf=NULL;
CUniMutex DdnssHttpCl::mutResBuf;
......@@ -32,6 +33,16 @@ DdnssHttpCl::~DdnssHttpCl() {
curl_easy_cleanup(handle); //Détrut le handle cURL
}
string DdnssHttpCl::getPublicIp(){
string res;
if(!get(res,publicIpGetAdress)){
return "";
}
CRegex reg("((([01]?[0-9]{1,2})|2([0-4][0-9]|5[0-5]))\\.){3}(([01]?[0-9]{1,2})|2([0-4][0-9]|5[0-5]))");
reg.setBuffer(&res);
return reg.getFirstMatch();
}
void DdnssHttpCl::setHttpUserPwd(const string &login, const string &passwd){
string tmp=login+":"+passwd;
curl_easy_setopt(handle,CURLOPT_USERPWD,tmp.c_str());
......@@ -74,3 +85,11 @@ size_t DdnssHttpCl::writeInRepBuf(void *ptr, size_t size, size_t nmemb, FILE *ou
resBuf->append((char*)ptr,size*nmemb);
return size*nmemb;
}
/**
* @brief The ame of the class.
* @return "DdnssHttpCl"
*/
string DdnssHttpCl::className() {
return "DdnssHttpCl";
}
......@@ -23,6 +23,7 @@ public:
void setHttpUserPwd(const string &login, const string &passwd);
bool get(string &result, const string &url);
bool post(string &result, const string &url);
virtual string className();
private:
string publicIpGetAdress;
CURL *handle;
......
......@@ -4,9 +4,9 @@
int main(int argc, char **argv) {
DdnssHttpCl cl;
string res;
cl.get(res,string(argv[1]));
cout << res << endl;
//string res;
//cl.get(res,string(argv[1]));
cout << cl.getPublicIp() << endl;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment