28 |
28 |
29 #include "nametrans.h" |
29 #include "nametrans.h" |
30 |
30 |
31 #include "../daemon/log.h" |
31 #include "../daemon/log.h" |
32 #include "../util/pblock.h" |
32 #include "../util/pblock.h" |
33 |
33 #include "../util/util.h" |
34 int test_nametrans(pblock *pb, Session *sn, Request *rq) { |
|
35 printf("test_nametrans...\n"); |
|
36 |
|
37 // set ppath |
|
38 //char *ppath = "/export/home/olaf/Desktop/hello.txt"; |
|
39 //pblock_kvinsert(pb_key_ppath, ppath, strlen(ppath), rq->vars); |
|
40 |
|
41 return REQ_NOACTION; |
|
42 } |
|
43 |
34 |
44 /* |
35 /* |
45 * assign_name |
36 * assign_name |
46 * |
37 * |
47 * Assigns the name specified by the name parameter if the uri has the |
38 * Assigns the name specified by the name parameter if the uri has the |
78 // add object to rq->vars |
69 // add object to rq->vars |
79 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars); |
70 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars); |
80 |
71 |
81 return REQ_NOACTION; |
72 return REQ_NOACTION; |
82 } |
73 } |
|
74 |
|
75 /* |
|
76 * document_root |
|
77 * |
|
78 * Specifies the document root directory. |
|
79 * |
|
80 * pblock parameter: |
|
81 * root path to document root |
|
82 */ |
|
83 int document_root(pblock *pb, Session *sn, Request *rq) { |
|
84 char *root = pblock_findkeyval(pb_key_root, pb); |
|
85 if(!root) { |
|
86 log_ereport(LOG_MISCONFIG, "document-root: missing rootparameter"); |
|
87 protocol_status(sn, rq, 500, NULL); |
|
88 return REQ_ABORTED; |
|
89 } |
|
90 |
|
91 sstr_t root_str = sstr(root); |
|
92 sstr_t uri_str = sstr(pblock_findkeyval(pb_key_uri, rq->reqpb)); |
|
93 util_add_ppath(root_str, uri_str, rq->vars); |
|
94 |
|
95 return REQ_PROCEED; |
|
96 } |
|
97 |
|
98 /* |
|
99 * pfx2dir |
|
100 * |
|
101 * ... |
|
102 * |
|
103 * pblock parameter: |
|
104 * from prefix |
|
105 * dir file system directory |
|
106 * name (optional) object name |
|
107 * |
|
108 */ |
|
109 int pfx2dir(pblock *pb, Session *sn, Request *rq) { |
|
110 char *from = pblock_findkeyval(pb_key_from, pb); |
|
111 char *dir = pblock_findkeyval(pb_key_dir, pb); |
|
112 char *name = pblock_findkeyval(pb_key_name, pb); |
|
113 |
|
114 if(!from || !dir) { |
|
115 if(!from && dir) { |
|
116 log_ereport(LOG_MISCONFIG, "pfx2dir: missing from parameter"); |
|
117 } else if(!dir && from) { |
|
118 log_ereport(LOG_MISCONFIG, "pfx2dir: missing dir parameter"); |
|
119 } else { |
|
120 log_ereport( |
|
121 LOG_MISCONFIG, |
|
122 "pfx2dir: missing from and dir parameter"); |
|
123 } |
|
124 protocol_status(sn, rq, 500, NULL); |
|
125 return REQ_ABORTED; |
|
126 } |
|
127 |
|
128 // check prefix |
|
129 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb); |
|
130 char fc; |
|
131 char uc; |
|
132 int i = 0; |
|
133 while((fc = from[i]) != 0) { |
|
134 uc = uri[i]; |
|
135 if(fc != uc) { |
|
136 return REQ_NOACTION; |
|
137 } |
|
138 i++; |
|
139 } |
|
140 |
|
141 // url has the specified prefix |
|
142 |
|
143 uri = uri + i; |
|
144 if(uri[0] == '/') { |
|
145 uri++; |
|
146 } |
|
147 sstr_t ppath = util_path_append(sn->pool, dir, uri); |
|
148 pblock_kvinsert( |
|
149 pb_key_ppath, |
|
150 ppath.ptr, |
|
151 ppath.length, |
|
152 rq->vars); |
|
153 |
|
154 if(name) { |
|
155 // add object to rq->vars |
|
156 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars); |
|
157 } |
|
158 |
|
159 return REQ_PROCEED; |
|
160 } |
|
161 |
|
162 |