Commit 3e4ce756 authored by mr-ti's avatar mr-ti
Browse files

No commit message

No commit message
parent cb35964a
......@@ -21,7 +21,7 @@ CRegex::CRegex(const string &expr, int flags)
}else{
state=ERROR;
}
nmatch = 1 /*regex.re_nsub*/;
nmatch = regex.re_nsub;
pmatch = (regmatch_t*)malloc (sizeof (regmatch_t) * nmatch);
}
......@@ -51,31 +51,32 @@ CRegex::State CRegex::getState(){
bool CRegex::exec(int flags){
int match = regexec (&regex, buffer->c_str()+offset, nmatch, pmatch, flags);
if(match==0){
state=MATCH;
return true;
}else if (match == REG_NOMATCH){
if (match == REG_NOMATCH || pmatch[0].rm_eo == pmatch[0].rm_so){
state=NOMATCH;
return false;
}else if(match==0){
state=MATCH;
return true;
}else{
state=ERROR;
return false;
}
}
string CRegex::getFirstMatch(){
string CRegex::getFirstMatch(unsigned int level){
string match;
if(exec()){
match=buffer->substr(pmatch[0].rm_so,pmatch[0].rm_eo - pmatch[0].rm_so);
if(exec() && pmatch[level].rm_so!=-1 && level<=regex.re_nsub){
match=buffer->substr(pmatch[level].rm_so,pmatch[level].rm_eo - pmatch[level].rm_so);
}
return match;
}
list<string> CRegex::getMatchs(){
list<string> CRegex::getMatchs(unsigned int level){
list<string> lst;
if(state!=ERROR){
if(state!=ERROR && level<=regex.re_nsub){
while(exec()){
lst.push_back(buffer->substr(pmatch[0].rm_so+offset,pmatch[0].rm_eo - pmatch[0].rm_so));
if(pmatch[level].rm_so!=-1)
lst.push_back(buffer->substr(pmatch[level].rm_so+offset,pmatch[level].rm_eo - pmatch[level].rm_so));
offset+=pmatch[0].rm_eo+1;
}
offset=0;
......
......@@ -29,8 +29,8 @@ public:
void setBuffer(string *buffer);
bool exec(int flags=0);
State getState();
list<string> getMatchs();
string getFirstMatch();
list<string> getMatchs(unsigned int level=0);
string getFirstMatch(unsigned int level=0);
int getErrorNb();
string getErrorMsg();
virtual string className();
......
......@@ -14,19 +14,34 @@
#include "cunipluginlib.h"
/**
* @brief CUniPlugin constructor.
* @brief DDnsSPluginList constructor.
*/
CUniPluginList::CUniPluginList(CUniConf *config):CUniObj(),map<string,CUniPlugin *>() {
this->config=config;
DDnsSPluginListList::DDnsSPluginListList(CUniConf *config):CUniObj() {
string dirPath=config->getValue("plugin_dir_path");
if(!dirPath.empty()){
CUniStringList list=config->getListValue("plugin_dlib_list");
CUniStringList list=config->getListValue("plugin_list");
Plugin *plugin;
string plugPath;
void *handle;
ExecFct exec;
char *tmp;
for(CUniStringList::iterator it=list.begin();it!=list.end();it++){
insert(make_pair(*it,new CUniPluginLib(config,dirPath+"/"+*it,*it)));
}
list=config->getListValue("plugin_exe_list");
for(CUniStringList::iterator it=list.begin();it!=list.end();it++){
insert(make_pair(*it,new CUniPluginPus(config,dirPath+"/"+*it,*it)));
plugPath=dirPath+"lib"+*it+".so";
handle = dlopen (plugPath.c_str(), RTLD_LAZY|RTLD_GLOBAL);
if (!handle) {
printc("dlopen() >> "+string(dlerror())+"\n");
}else{
exec=(ExecFct)dlsym(handle, "exec");
if ((tmp = dlerror()) != NULL) {
printc("dlsym() >> "+string(tmp)+"\n");
dlclose(handle);
}else{
plugin=(Plugin *)malloc(sizeof(Plugin));
plugin->handle=handle;
plugin->exec=exec;
plugList.push_back(plugin);
}
}
}
}else{
printc("The \"plugin_dir_path\" is empty !\n");
......@@ -34,105 +49,20 @@ CUniPluginList::CUniPluginList(CUniConf *config):CUniObj(),map<string,CUniPlugin
}
/**
* @brief CUniPlugin destructor.
* @brief DDnsSPluginList destructor.
*/
CUniPluginList::~CUniPluginList() {
stopAll();
DDnsSPluginListList::~DDnsSPluginListList() {
for(iterator it=begin();it!=end();it++){
dlclose(it->second->handle);
delete it->second;
printd("~() >> plugin \""+it->first+"\" unloaded.\n");
}
}
/**
* @brief Function to call at initialization.
*/
void CUniPluginList::init(){
CUniStringList list=config->getListValue("plugin_at_start_list");
for(CUniStringList::iterator it=list.begin();it!=list.end();it++){
start(*it);
}
}
/**
* @brief Start (Load) a plugin.
* @param name Plugin name.
* @return true if the plugin is started correctly, otherwise false.
*/
bool CUniPluginList::start(const string &name) {
iterator it=find(name);
if(it!=end()){
if(it->second->start()){
return true;
}else{
lastError=it->second->getLastError();
return false;
}
}else{
lastError="Plugin don't exist !";
return false;
}
}
/**
* @brief Stop (Unload) a plugin.
* @param name Plugin name.
* @return true if the plugin is stopped correctly, otherwise false.
*/
bool CUniPluginList::stop(const string &name) {
iterator it=find(name);
if(it!=end()){
if(it->second->stop()){
return true;
}else{
lastError=it->second->getLastError();
return false;
}
}else{
lastError="Plugin don't exist !";
return false;
}
}
/**
* @brief Start (Load) all plugins.
*/
void CUniPluginList::startAll() {
for(iterator it=begin();it!=end();it++)
it->second->start();
}
/**
* @brief Stop (Unload) all plugins.
*/
void CUniPluginList::stopAll() {
for(iterator it=begin();it!=end();it++)
it->second->stop();
}
/**
* @brief Get a 2D list within the state of all plugins.
*/
void CUniPluginList::getStateList(CUniString2DList &list2d) {
CUniStringList tmp;
for(iterator it=begin();it!=end();it++){
it->second->getState(tmp);
list2d.push_back(tmp);
tmp.clear();
}
}
/**
* @brief Get the last Error.
* @return a reference to the last error string.
*/
const string& CUniPluginList::getLastError(){
return lastError;
}
/**
* @brief The name of the class.
* @return "CUniPluginList"
* @return "DDnsSPluginListList"
*/
string CUniPluginList::className() {
return "CUniPluginList";
string DDnsSPluginListList::className() {
return "DDnsSPluginListList";
}
......@@ -17,30 +17,29 @@
* @date 29/07/2007
*/
#ifndef CUNIPLUGINLIST_H
#define CUNIPLUGINLIST_H
#ifndef DDNSSPLUGINLIST_H
#define DDNSSPLUGINLIST_H
#include "cuniplugin.h"
#include <unicomctrl/cuniobj.h>
#include <map>
/**
* This class can manage a plugin list.
* @brief Plugin list.
*/
class CUniPluginList : public CUniObj, public map<string,CUniPlugin *> {
class DDnsSPluginListList : public CUniObj{
public:
CUniPluginList(CUniConf &config);
~CUniPluginList();
bool start(const string &name);
void init();
bool stop(const string &name);
void startAll();
void stopAll();
void getStateList(CUniString2DList &list2d);
const string &getLastError();
DDnsSPluginListList(CUniConf &config);
~DDnsSPluginListList();
void exec(const string &name);
virtual string className();
private:
map<string,CUniPlugin *>
typedef void (*ExecFct)(const string&);
typedef struct Plugin{
void *handle;
ExecFct exec;
}Plugin;
map<string,Plugin *> plugList;
};
#endif
#include <iostream>
#include <string>
#include <list>
#include "../ddnssbase/ddnsshttpcl.h"
int main(int argc, char **argv) {
// CRegex reg((const string)string(argv[1]));
// if(reg.getState()==CRegex::ERROR){
// cout << reg.getErrorMsg() << endl;
// return 1;
// }
// string buf(argv[2]);
// reg.setBuffer(&buf);
// // cout << reg.getFirstMatch() << endl;
// list<string> lst=reg.getMatchs(atoi(argv[3]));
// for(list<string>::iterator it=lst.begin();it!=lst.end();it++){
// cout << "\"" << *it << "\"" << endl;
// }
DdnssHttpCl cl;
//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