Commit 87fd162f authored by mr-ti's avatar mr-ti
Browse files

No commit message

No commit message
parent 73665a19
......@@ -21,7 +21,7 @@ CRegex::CRegex(const string &expr, int flags)
}else{
state=ERROR;
}
nmatch = regex.re_nsub;
nmatch = 1/*regex.re_nsub*/;
pmatch = (regmatch_t*)malloc (sizeof (regmatch_t) * nmatch);
}
......@@ -63,20 +63,28 @@ bool CRegex::exec(int flags){
}
}
string CRegex::getFirstMatch(unsigned int level){
unsigned int CRegex::begin(){
return (state==MATCH?pmatch[0].rm_so:0);
}
unsigned int CRegex::end(){
return (state==MATCH?pmatch[0].rm_eo:0);
}
string CRegex::getFirstMatch(){
string match;
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);
if(exec() && pmatch[0].rm_so!=-1){
match=buffer->substr(pmatch[0].rm_so,pmatch[0].rm_eo - pmatch[0].rm_so);
}
return match;
}
list<string> CRegex::getMatchs(unsigned int level){
list<string> CRegex::getMatchs(){
list<string> lst;
if(state!=ERROR && level<=regex.re_nsub){
if(state!=ERROR){
while(exec()){
if(pmatch[level].rm_so!=-1)
lst.push_back(buffer->substr(pmatch[level].rm_so+offset,pmatch[level].rm_eo - pmatch[level].rm_so));
if(pmatch[0].rm_so!=-1)
lst.push_back(buffer->substr(pmatch[0].rm_so+offset,pmatch[0].rm_eo - pmatch[0].rm_so));
offset+=pmatch[0].rm_eo+1;
}
offset=0;
......@@ -84,7 +92,7 @@ list<string> CRegex::getMatchs(unsigned int level){
return lst;
}
void CRegex::setBuffer(string *buffer){
void CRegex::setBuffer(const string *buffer){
offset=0;
this->buffer=buffer;
}
......
......@@ -26,11 +26,13 @@ public:
};
CRegex(const string &expr, int flags=REG_EXTENDED);
~CRegex();
void setBuffer(string *buffer);
void setBuffer(const string *buffer);
bool exec(int flags=0);
unsigned int begin();
unsigned int end();
State getState();
list<string> getMatchs(unsigned int level=0);
string getFirstMatch(unsigned int level=0);
list<string> getMatchs();
string getFirstMatch();
int getErrorNb();
string getErrorMsg();
virtual string className();
......@@ -40,8 +42,8 @@ private:
size_t nmatch;
regmatch_t *pmatch;
int errNo;
string *buffer;
unsigned long offset;
const string *buffer;
string::size_type offset;
};
#endif
......@@ -10,16 +10,16 @@
//
//
#include "ddnsspluginlist.h"
#include "../ddnssbase/cregex.h"
#include <dlfcn.h>
/**
* @brief DDnsSPluginList constructor.
*/
DDnsSPluginListList::DDnsSPluginListList(CUniConf &config):CUniObj() {
DDnsSPlList::DDnsSPlList(CUniConf &config):CUniObj() {
string dirPath=config.getValue("plugin_dir_path");
if(!dirPath.empty()){
CUniStringList list=config.getListValue("plugin_list");
Plugin *plugin;
string plugPath;
void *handle;
......@@ -51,7 +51,7 @@ DDnsSPluginListList::DDnsSPluginListList(CUniConf &config):CUniObj() {
/**
* @brief DDnsSPluginList destructor.
*/
DDnsSPluginListList::~DDnsSPluginListList() {
DDnsSPlList::~DDnsSPlList() {
for(map<string,Plugin *>::iterator it=plugList.begin();it!=plugList.end();it++){
dlclose(it->second->handle);
delete it->second;
......@@ -59,10 +59,25 @@ DDnsSPluginListList::~DDnsSPluginListList() {
}
}
void DDnsSPlList::exec(const string &request){
CRegex regex("([[:alnum:]]+)");
regex.setBuffer(&request);
map<string,Plugin *>::iterator it=plugList.find(regex.getFirstMatch());
if(it==plugList.end()){
throw string("Unknow command \""+it->first+"\"");
}else{
string::size_type newBeg=request.find_first_not_of("\t ",regex.end()+1);
if(newBeg==string::npos)
it->second->exec("");
else
it->second->exec(request.substr(newBeg));
}
}
/**
* @brief The name of the class.
* @return "DDnsSPluginListList"
* @return "DDnsSPlList"
*/
string DDnsSPluginListList::className() {
return "DDnsSPluginListList";
string DDnsSPlList::className() {
return "DDnsSPlList";
}
......@@ -17,8 +17,8 @@
* @date 29/07/2007
*/
#ifndef DDNSSPLUGINLIST_H
#define DDNSSPLUGINLIST_H
#ifndef DDNSSPLLIST_H
#define DDNSSPLLIST_H
#include <unicomctrl/cuniconf.h>
#include <unicomctrl/unilib.h>
......@@ -28,11 +28,11 @@
* This class can manage a plugin list.
* @brief Plugin list.
*/
class DDnsSPluginListList : public CUniObj{
class DDnsSPlList : public CUniObj{
public:
DDnsSPluginListList(CUniConf &config);
~DDnsSPluginListList();
void exec(const string &name);
DDnsSPlList(CUniConf &config);
~DDnsSPlList();
void exec(const string &request);
virtual string className();
private:
typedef void (*ExecFct)(const string&);
......
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