Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source4/web_server/wsgi.c

    r414 r745  
    66   Implementation of the WSGI interface described in PEP0333
    77   (http://www.python.org/dev/peps/pep-0333)
    8    
     8
    99   This program is free software; you can redistribute it and/or modify
    1010   it under the terms of the GNU General Public License as published by
    1111   the Free Software Foundation; either version 3 of the License, or
    1212   (at your option) any later version.
    13    
     13
    1414   This program is distributed in the hope that it will be useful,
    1515   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1616   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1717   GNU General Public License for more details.
    18    
     18
    1919   You should have received a copy of the GNU General Public License
    2020   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    2121*/
    2222
     23#include <Python.h>
    2324#include "includes.h"
    2425#include "web_server/web_server.h"
    2526#include "../lib/util/dlinklist.h"
    26 #include "../lib/util/data_blob.h"
    2727#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
     33typedef int Py_ssize_t;
     34typedef inquiry lenfunc;
     35typedef intargfunc ssizeargfunc;
    3236#endif
    3337
     
    4145        PyObject *response_header, *exc_info = NULL;
    4246        char *status;
    43         int i;
     47        Py_ssize_t i;
    4448        const char *kwnames[] = {
    4549                "status", "response_header", "exc_info", NULL
     
    109113        .tp_methods = web_request_methods,
    110114        .tp_basicsize = sizeof(web_request_Object),
    111         .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
     115        .tp_flags = Py_TPFLAGS_DEFAULT,
    112116};
    113117
     
    166170        .tp_basicsize = sizeof(error_Stream_Object),
    167171        .tp_methods = error_Stream_methods,
    168         .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
     172        .tp_flags = Py_TPFLAGS_DEFAULT,
    169173};
    170174
     
    193197        ret = PyString_FromStringAndSize((char *)self->web->input.partial.data+self->offset, size);
    194198        self->offset += size;
    195        
     199
    196200        return ret;
    197201}
     
    240244        .tp_basicsize = sizeof(input_Stream_Object),
    241245        .tp_methods = input_Stream_methods,
    242         .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
     246        .tp_flags = Py_TPFLAGS_DEFAULT,
    243247};
    244248
     
    304308                        PyDict_SetItemString(env, "CONTENT_TYPE", PyString_FromString(hdr->value));
    305309                } 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                        }
    307316                        PyDict_SetItemString(env, name, PyString_FromString(hdr->value));
    308317                        free(name);
     
    325334        PyObject *py_environ, *result, *item, *iter;
    326335        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;
    329339        web_request_Object *py_web = PyObject_New(web_request_Object, &web_request_Type);
    330340        py_web->web = web;
    331341
    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
    333347        py_environ = create_environ(tls_enabled(web->conn->socket),
    334348                                    web->input.content_length,
    335349                                    web->input.headers,
    336350                                    web->input.post_request?"POST":"GET",
    337                                     socket_address->addr,
    338                                     socket_address->port,
     351                                    addr,
     352                                    port,
    339353                                    Py_InputHttpStream(web),
    340354                                    web->input.url
     
    368382bool wsgi_initialize(struct web_server_data *wdata)
    369383{
    370         PyObject *py_swat;
     384        PyObject *py_web_server;
    371385
    372386        Py_Initialize();
     387
     388        py_update_path(); /* Ensure that we have the Samba paths at
     389                           * the start of the sys.path() */
    373390
    374391        if (PyType_Ready(&web_request_Type) < 0)
     
    382399
    383400        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"));
    387404                return false;
    388405        }
    389         wdata->private_data = py_swat;
     406        wdata->private_data = py_web_server;
    390407        return true;
    391408}
Note: See TracChangeset for help on using the changeset viewer.