Changeset 740 for vendor/current/source4/web_server
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- Location:
- vendor/current/source4/web_server
- Files:
-
- 1 added
- 2 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source4/web_server/web_server.c
r414 r740 22 22 23 23 #include "includes.h" 24 #include "smbd/service_task.h"25 #include "smbd/service_stream.h"26 #include "smbd/service.h"27 24 #include "web_server/web_server.h" 25 #include "../lib/util/dlinklist.h" 26 #include "lib/tls/tls.h" 28 27 #include "lib/events/events.h" 29 #include "system/filesys.h"30 #include "system/network.h"31 28 #include "lib/socket/netif.h" 32 #include "lib/tls/tls.h"33 #include "../lib/util/dlinklist.h"34 29 #include "param/param.h" 35 30 … … 301 296 { 302 297 NTSTATUS status; 303 uint16_t port = lp _web_port(task->lp_ctx);298 uint16_t port = lpcfg_web_port(task->lp_ctx); 304 299 const struct model_ops *model_ops; 305 300 struct web_server_data *wdata; … … 308 303 309 304 /* run the web server as a single process */ 310 model_ops = process_model_startup( task->event_ctx,"single");305 model_ops = process_model_startup("single"); 311 306 if (!model_ops) goto failed; 312 307 313 if (lp_interfaces(task->lp_ctx) && lp_bind_interfaces_only(task->lp_ctx)) { 308 /* startup the Python processor - unfortunately we can't do this 309 per connection as that wouldn't allow for session variables */ 310 wdata = talloc_zero(task, struct web_server_data); 311 if (wdata == NULL) goto failed; 312 313 task->private_data = wdata; 314 315 if (lpcfg_interfaces(task->lp_ctx) && lpcfg_bind_interfaces_only(task->lp_ctx)) { 314 316 int num_interfaces; 315 317 int i; 316 318 struct interface *ifaces; 317 319 318 load_interfaces(NULL, lp _interfaces(task->lp_ctx), &ifaces);320 load_interfaces(NULL, lpcfg_interfaces(task->lp_ctx), &ifaces); 319 321 320 322 num_interfaces = iface_count(ifaces); 321 323 for(i = 0; i < num_interfaces; i++) { 322 324 const char *address = iface_n_ip(ifaces, i); 323 status = stream_setup_socket(task->event_ctx, 324 task->lp_ctx, model_ops, 325 status = stream_setup_socket(task, 326 task->event_ctx, 327 task->lp_ctx, model_ops, 325 328 &web_stream_ops, 326 329 "ipv4", address, 327 &port, lp _socket_options(task->lp_ctx),330 &port, lpcfg_socket_options(task->lp_ctx), 328 331 task); 329 332 if (!NT_STATUS_IS_OK(status)) goto failed; … … 332 335 talloc_free(ifaces); 333 336 } else { 334 status = stream_setup_socket(task->event_ctx, task->lp_ctx, 335 model_ops, &web_stream_ops, 336 "ipv4", lp_socket_address(task->lp_ctx), 337 &port, lp_socket_options(task->lp_ctx), task); 337 status = stream_setup_socket(task, task->event_ctx, 338 task->lp_ctx, model_ops, 339 &web_stream_ops, 340 "ipv4", lpcfg_socket_address(task->lp_ctx), 341 &port, lpcfg_socket_options(task->lp_ctx), 342 task); 338 343 if (!NT_STATUS_IS_OK(status)) goto failed; 339 344 } 340 345 341 /* startup the esp processor - unfortunately we can't do this342 per connection as that wouldn't allow for session variables */343 wdata = talloc_zero(task, struct web_server_data);344 if (wdata == NULL)goto failed;345 346 task->private_data = wdata;347 348 346 wdata->tls_params = tls_initialise(wdata, task->lp_ctx); 349 347 if (wdata->tls_params == NULL) goto failed; … … 351 349 if (!wsgi_initialize(wdata)) goto failed; 352 350 351 353 352 return; 354 353 -
vendor/current/source4/web_server/web_server.h
r414 r740 17 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 18 */ 19 20 #ifndef __WEB_SERVER_H__ 21 #define __WEB_SERVER_H__ 19 22 20 23 #include "smbd/process_model.h" … … 61 64 }; 62 65 66 bool wsgi_initialize(struct web_server_data *wdata); 67 void http_error(struct websrv_context *web, const char *status, const char *info); 68 void websrv_output_headers(struct websrv_context *web, const char *status, struct http_header *headers); 69 void websrv_output(struct websrv_context *web, void *data, size_t length); 70 NTSTATUS http_parse_header(struct websrv_context *web, const char *line); 63 71 64 #include "web_server/proto.h" 65 72 #endif /* __WEB_SERVER_H__ */ -
vendor/current/source4/web_server/wsgi.c
r414 r740 6 6 Implementation of the WSGI interface described in PEP0333 7 7 (http://www.python.org/dev/peps/pep-0333) 8 8 9 9 This program is free software; you can redistribute it and/or modify 10 10 it under the terms of the GNU General Public License as published by 11 11 the Free Software Foundation; either version 3 of the License, or 12 12 (at your option) any later version. 13 13 14 14 This program is distributed in the hope that it will be useful, 15 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 17 GNU General Public License for more details. 18 18 19 19 You should have received a copy of the GNU General Public License 20 20 along with this program. If not, see <http://www.gnu.org/licenses/>. 21 21 */ 22 22 23 #include <Python.h> 23 24 #include "includes.h" 24 25 #include "web_server/web_server.h" 25 26 #include "../lib/util/dlinklist.h" 26 #include "../lib/util/data_blob.h"27 27 #include "lib/tls/tls.h" 28 #include <Python.h> 29 30 #ifndef Py_RETURN_NONE 31 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None 28 #include "lib/tsocket/tsocket.h" 29 #include "scripting/python/modules.h" 30 31 /* There's no Py_ssize_t in 2.4, apparently */ 32 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5 33 typedef int Py_ssize_t; 34 typedef inquiry lenfunc; 35 typedef intargfunc ssizeargfunc; 32 36 #endif 33 37 … … 41 45 PyObject *response_header, *exc_info = NULL; 42 46 char *status; 43 int i;47 Py_ssize_t i; 44 48 const char *kwnames[] = { 45 49 "status", "response_header", "exc_info", NULL … … 109 113 .tp_methods = web_request_methods, 110 114 .tp_basicsize = sizeof(web_request_Object), 111 .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,115 .tp_flags = Py_TPFLAGS_DEFAULT, 112 116 }; 113 117 … … 166 170 .tp_basicsize = sizeof(error_Stream_Object), 167 171 .tp_methods = error_Stream_methods, 168 .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,172 .tp_flags = Py_TPFLAGS_DEFAULT, 169 173 }; 170 174 … … 193 197 ret = PyString_FromStringAndSize((char *)self->web->input.partial.data+self->offset, size); 194 198 self->offset += size; 195 199 196 200 return ret; 197 201 } … … 240 244 .tp_basicsize = sizeof(input_Stream_Object), 241 245 .tp_methods = input_Stream_methods, 242 .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,246 .tp_flags = Py_TPFLAGS_DEFAULT, 243 247 }; 244 248 … … 304 308 PyDict_SetItemString(env, "CONTENT_TYPE", PyString_FromString(hdr->value)); 305 309 } else { 306 asprintf(&name, "HTTP_%s", hdr->name); 310 if (asprintf(&name, "HTTP_%s", hdr->name) < 0) { 311 Py_DECREF(env); 312 Py_DECREF(inputstream); 313 PyErr_NoMemory(); 314 return NULL; 315 } 307 316 PyDict_SetItemString(env, name, PyString_FromString(hdr->value)); 308 317 free(name); … … 325 334 PyObject *py_environ, *result, *item, *iter; 326 335 PyObject *request_handler = (PyObject *)wdata->private_data; 327 struct socket_address *socket_address; 328 336 struct tsocket_address *my_address = web->conn->local_address; 337 const char *addr = "0.0.0.0"; 338 uint16_t port = 0; 329 339 web_request_Object *py_web = PyObject_New(web_request_Object, &web_request_Type); 330 340 py_web->web = web; 331 341 332 socket_address = socket_get_my_addr(web->conn->socket, web); 342 if (tsocket_address_is_inet(my_address, "ip")) { 343 addr = tsocket_address_inet_addr_string(my_address, wdata); 344 port = tsocket_address_inet_port(my_address); 345 } 346 333 347 py_environ = create_environ(tls_enabled(web->conn->socket), 334 348 web->input.content_length, 335 349 web->input.headers, 336 350 web->input.post_request?"POST":"GET", 337 socket_address->addr,338 socket_address->port,351 addr, 352 port, 339 353 Py_InputHttpStream(web), 340 354 web->input.url … … 368 382 bool wsgi_initialize(struct web_server_data *wdata) 369 383 { 370 PyObject *py_ swat;384 PyObject *py_web_server; 371 385 372 386 Py_Initialize(); 387 388 py_update_path(); /* Ensure that we have the Samba paths at 389 * the start of the sys.path() */ 373 390 374 391 if (PyType_Ready(&web_request_Type) < 0) … … 382 399 383 400 wdata->http_process_input = wsgi_process_http_input; 384 py_ swat = PyImport_Import(PyString_FromString("swat"));385 if (py_ swat== NULL) {386 DEBUG(0, ("Unable to find SWAT\n"));401 py_web_server = PyImport_ImportModule("samba.web_server"); 402 if (py_web_server == NULL) { 403 DEBUG(0, ("Unable to find web server\n")); 387 404 return false; 388 405 } 389 wdata->private_data = py_ swat;406 wdata->private_data = py_web_server; 390 407 return true; 391 408 }
Note:
See TracChangeset
for help on using the changeset viewer.