aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Kropf <josh@slashdev.ca>2007-08-02 02:29:38 (GMT)
committerJosh Kropf <josh@slashdev.ca>2007-08-02 02:29:38 (GMT)
commit824668425ee62aa09a126f63cd44962eeeb25a28 (patch)
tree88c846f7be183a93be2696a9783c3dd16707543a
parenta4393dc3e62856eb4feb5cfe040a7b0f4dd212f8 (diff)
downloadecho-server-824668425ee62aa09a126f63cd44962eeeb25a28.zip
echo-server-824668425ee62aa09a126f63cd44962eeeb25a28.tar.gz
echo-server-824668425ee62aa09a126f63cd44962eeeb25a28.tar.bz2
Fixed symbol macro errors in action.h
-rw-r--r--action/action.cpp19
-rw-r--r--action/action.h33
-rw-r--r--fcgi/dispatcher.cpp5
-rw-r--r--modules/Makefile2
4 files changed, 25 insertions, 34 deletions
diff --git a/action/action.cpp b/action/action.cpp
index 3f837a5..e1c4277 100644
--- a/action/action.cpp
+++ b/action/action.cpp
@@ -1,6 +1,7 @@
#include "action.h"
#include "config.h"
#include <dlfcn.h>
+#include <stdexcept>
using namespace std;
using namespace action;
@@ -17,18 +18,18 @@ ActionFactory::ActionFactory()
// open modules dynamic library
handle = dlopen((*i).c_str(), RTLD_NOW);
- if (!handle) throw action_error(dlerror());
+ if (!handle) throw runtime_error(dlerror());
// function that returns action count
- count_func_t count_f = (count_func_t)dlsym(handle, "COUNT_FUNC");
- if (!count_f) throw action_error(dlerror());
+ count_func_t count_f = (count_func_t)dlsym(handle, COUNT_FUNC);
+ if (!count_f) throw runtime_error(dlerror());
// function for getting action mapping
- mapping_func_t mapping_f = (mapping_func_t)dlsym(handle, "MAPPING_FUNC");
- if (!mapping_f) throw action_error(dlerror());
+ mapping_func_t mapping_f = (mapping_func_t)dlsym(handle, MAPPING_FUNC);
+ if (!mapping_f) throw runtime_error(dlerror());
int count = count_f();
-
+
// for each action, call the mapping function
for (int i=0; i<count; i++) {
char* key; // action key string
@@ -52,11 +53,11 @@ ActionFactory::~ActionFactory()
}
}
-bool ActionFactory::contains(const char* key) const
+bool ActionFactory::contains(string& key) const
{ return _factory_map.count(key) != 0; }
-Action* ActionFactory::create(const char* key)
+Action* ActionFactory::create(string& key)
{ return (*_factory_map[key].create)(); }
-void ActionFactory::destroy(const char* key, Action* action)
+void ActionFactory::destroy(string& key, Action* action)
{ (*_factory_map[key].destroy)(action); }
diff --git a/action/action.h b/action/action.h
index 262b3aa..3119b16 100644
--- a/action/action.h
+++ b/action/action.h
@@ -14,32 +14,19 @@
* discover the
*/
-// function symbol that returns number of actions in the module
-#define COUNT_FUNC __action_count
+// function name that returns number of actions in the module
+#define COUNT_FUNC "__action_count"
-// function symbol that return action key and create/destroy functions
-#define MAPPING_FUNC __action_mapping
+// function name that return action key and create/destroy functions
+#define MAPPING_FUNC "__action_mapping"
-#define BEGIN_MAPPING_FUNC extern "C" void MAPPING_FUNC(int i, char* key, create_t create, destroy_t destroy) {
-#define BEGIN_COUNT_FUNC extern "C" int COUNT_FUNC() {
+#define BEGIN_MAPPING_FUNC extern "C" void __action_mapping(int i, char* key, create_t create, destroy_t destroy) {
+#define BEGIN_COUNT_FUNC extern "C" int __action_count() {
#define END_FUNC }
namespace action {
/**
- * Exception raised when an error occured loading an action module
- */
-class action_error: public std::exception
-{
-private:
- const char* _msg;
-
-public:
- action_error(const char* msg) { _msg = msg; }
- virtual const char* what() { return _msg; }
-};
-
-/**
* Interface for all dispatchable actions. An action handles an http request
* and formats an http response.
*/
@@ -73,7 +60,7 @@ private:
destroy_t destroy;
};
- std::map<const char*, factory> _factory_map;
+ std::map<std::string, factory> _factory_map;
std::vector<void*> _handles;
@@ -94,21 +81,21 @@ public:
* @param key string identifier
* @return true if registry contains an action for the key, false otherwise
*/
- bool contains(const char* key) const;
+ bool contains(std::string& key) const;
/**
* Instantiates the action for the given key and returns it
* @param key string identifier
* @return pointer to instance of action class
*/
- Action* create(const char* key);
+ Action* create(std::string& key);
/**
* Deletes the action instance
* @param key string identifier
* @param action pointer to action
*/
- void destroy(const char* key, Action* action);
+ void destroy(std::string& key, Action* action);
};
} /* end namespace */
diff --git a/fcgi/dispatcher.cpp b/fcgi/dispatcher.cpp
index e615eb7..b441c2a 100644
--- a/fcgi/dispatcher.cpp
+++ b/fcgi/dispatcher.cpp
@@ -23,7 +23,7 @@ int main (void)
Cgicc cgi(&io);
Action* action = NULL;
- const char* key = NULL;
+ string key;
// script name is the full path of the request
string script = cgi.getEnvironment().getScriptName();
@@ -38,13 +38,14 @@ int main (void)
// if another / wasn't found, use size as end index
if (end == string::npos) end = script.size();
- key = script.substr(begin, end-begin).c_str();
+ key = script.substr(begin, end-begin);
if (factory.contains(key)) {
action = factory.create(key);
}
}
+cerr << "***DEBUG*** " << (action == NULL) << endl;
if (action != NULL) {
action->execute(cgi, io);
diff --git a/modules/Makefile b/modules/Makefile
index e84a051..bc604dd 100644
--- a/modules/Makefile
+++ b/modules/Makefile
@@ -1,6 +1,8 @@
CXXFLAGS=-Wall -fpic -g -I../../action
LDFLAGS=-shared
+all: $(TARGET)
+
$(TARGET): $(OBJS)
$(CXX) $(LDFLAGS) $^ -o $@