141 mp::odr o(ODR_ENCODE);
143 if (strcmp(req->method,
"GET"))
151 Z_GDU *gdu = o.create_HTTP_Response(session, req, 405);
152 package.response() = gdu;
158 if (stat(fname.c_str(), &st) == -1 || (st.st_mode & S_IFMT) != S_IFREG)
166 Z_GDU *gdu = o.create_HTTP_Response(session, req, 404);
167 package.response() = gdu;
172 FILE *f = fopen(fname.c_str(),
"rb");
175 Z_GDU *gdu = o.create_HTTP_Response(session, req, 404);
176 package.response() = gdu;
179 if (fseek(f, 0L, SEEK_END) == -1)
182 Z_GDU *gdu = o.create_HTTP_Response(session, req, 404);
183 package.response() = gdu;
190 Z_GDU *gdu = o.create_HTTP_Response(session, req, 404);
191 package.response() = gdu;
195 char *fbuf = (
char*) odr_malloc(o, sz);
198 if (fread(fbuf, sz, 1, f) != 1)
200 Z_GDU *gdu = o.create_HTTP_Response(session, req, 500);
201 package.response() = gdu;
209 mp::odr decode(ODR_DECODE);
212 odr_setbuf(decode, (
char *) fbuf, sz, 0);
213 int r = z_GDU(decode, &gdu, 0, 0);
216 gdu = o.create_HTTP_Response(session, req, 500);
221 gdu = o.create_HTTP_Response(session, req, 200);
222 Z_HTTP_Response *hres = gdu->u.HTTP_Response;
223 hres->content_len = sz;
224 hres->content_buf = fbuf;
226 z_HTTP_header_add(o, &hres->headers,
227 "Content-Type", content_type.c_str());
229 package.response() = gdu;