Jun Furutani / libMiMic

Fork of libMiMic by Ryo Iizuka

Revision:
7:2b33a8d84eb3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cpp/ModBaseClass.cpp	Tue Apr 09 09:32:25 2013 +0000
@@ -0,0 +1,53 @@
+#pragma once
+
+#include "ModBaseClass.h"
+#include "HttpdConnection.h"
+#include "NyLPC_cHttpdConnection_protected.h"
+
+
+
+namespace MiMic
+{
+    ModBaseClass::ModBaseClass(const char* i_path)
+    {
+        this->_path=NULL;
+        this->setParam(i_path);
+    }
+    ModBaseClass::ModBaseClass()
+    {
+        this->_path=NULL;
+    }
+    ModBaseClass::~ModBaseClass()
+    {
+        if(this->_path!=NULL){
+            free(this->_path);
+        }
+    }
+    void ModBaseClass::setParam(const char* i_path)
+    {
+        if(this->_path!=NULL){
+            free(this->_path);            
+        }
+        this->_path=(char*)malloc(strlen(i_path)+1);
+        if(this->_path==NULL){
+            exit(-1);
+        }
+        strcpy(this->_path,i_path);
+    }
+    bool ModBaseClass::canHandle(HttpdConnection& i_connection)
+    {
+        if(this->_path==NULL){
+            return false;
+        }
+        const NyLPC_TChar* in_url;
+        in_url=NyLPC_cHttpdConnection_getUrlPrefix(i_connection._ref_inst);
+        size_t base_url_len=strlen(this->_path);
+        if(strlen(in_url)-2<base_url_len){
+            return false;
+        }
+        if(in_url[0]!='/' || strncmp(in_url+1,this->_path,base_url_len)!=0 || in_url[base_url_len+1]!='/'){
+            return false;
+        }
+        return true;
+    }        
+}
\ No newline at end of file