1 /*
2  *
3  *  C++ Portable Types Library (PTypes)
4  *  Version 2.1.1  Released 27-Jun-2007
5  *
6  *  Copyright (C) 2001-2007 Hovik Melikyan
7  *
8  *  http://www.melikyan.com/ptypes/
9  *
10  */
11 
12 #include "request.h"
13 #include "modules.h"
14 
15 
16 USING_PTYPES
17 
18 
19 static handler_info* method_list;
20 static handler_info* path_list;
21 static handler_info* file_list;
22 
23 
handler_info(handler_info * inext,void * icallback,const string & iparam)24 handler_info::handler_info(handler_info* inext, void* icallback, const string& iparam)
25     : next(inext), callback(icallback), param(iparam)
26 {
27 }
28 
29 
add_method_handler(const string & method,method_callback cb)30 void add_method_handler(const string& method, method_callback cb)
31 {
32     method_list = new handler_info(method_list, (void*)cb, method);
33 }
34 
35 
add_path_handler(const string & path,path_callback cb)36 void add_path_handler(const string& path, path_callback cb)
37 {
38     path_list = new handler_info(path_list, (void*)cb, path);
39 }
40 
41 
42 
add_file_handler(const string & ext,file_callback cb)43 void add_file_handler(const string& ext, file_callback cb)
44 {
45     file_list = new handler_info(file_list, (void*)cb, ext);
46 }
47 
48 
find_handler(handler_info * list,const string & param)49 handler_info* find_handler(handler_info* list, const string& param)
50 {
51     while (list != 0)
52     {
53         if (list->param == param)
54             return list;
55         list = list->next;
56     }
57     return 0;
58 }
59 
60 
find_method_handler(const string & method)61 handler_info* find_method_handler(const string& method)
62 {
63     return find_handler(method_list, method);
64 }
65 
66 
find_path_handler(const string & path)67 handler_info* find_path_handler(const string& path)
68 {
69     return find_handler(path_list, path);
70 }
71 
72 
find_file_handler(const string & ext)73 handler_info* find_file_handler(const string& ext)
74 {
75     return find_handler(file_list, ext);
76 }
77 
78 
init_handlers()79 void init_handlers()
80 {
81     ADD_PATH_HANDLER("/", handle_file);
82     ADD_PATH_HANDLER("/.about", handle_about);
83     ADD_PATH_HANDLER("/.wstat", handle_wstat);
84 }
85 
86