Changeset 1070


Ignore:
Timestamp:
31/05/06 12:57:18 (13 years ago)
Author:
spascoe
Message:

Slight modifications to bbftpd module and a new test case for testing
the embedded server.

Location:
TI05-delivery/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd.c

    r1067 r1070  
    10851085                state = S_PROTWAIT ; 
    10861086                sprintf(logmessage,"bbftpd version %s : OK",VERSION) ; 
    1087                 syslog(BBFTPD_DEBUG, "Lets send the auth reply ..."); 
    10881087                reply(MSG_OK,logmessage) ; 
    10891088            } else { 
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_daemon.c

    r1065 r1070  
    139139#ifdef NDG_PYTHON_EMBED 
    140140    /* Return the daemon's PID */ 
    141     if (retcode > 0) return retcode; 
     141    if (retcode > 0) { 
     142      close(controlsock); 
     143      return retcode; 
     144    } 
    142145#else 
    143146    /* No need for the parent any more */ 
  • TI05-delivery/trunk/src/python_ext/bbftpd.c

    r1067 r1070  
     1/** 
     2 * NDG python embedded bbftp daemon module. 
     3 * 
     4 * @author Stephen Pascoe 
     5 * 
     6 * Copyright (C) 2006 CCLRC & NERC 
     7 * 
     8 * This software may be distributed under the terms of the Q Public Licence, version 1.0 or later. 
     9 * 
     10 */ 
     11 
    112#include <Python.h> 
    213 
    314extern char **environ; 
    4 /* From bbftpd.c */ 
     15/* 
     16 * variables and prototypes from bbftpd.c 
     17 */ 
     18 
     19extern int be_daemon; 
     20extern int newcontrolport; 
     21 
    522int bbftpd_main(int argc, char **argv, char **envp); 
    623 
    7 /* 
    8   When embedding in python main is replaced by a simple python function call. 
    9 */ 
    1024static PyObject *bbftpd_run(PyObject *self, PyObject *args) { 
    1125  int argc, i; 
    1226  char **argv, **arg_p; 
    1327  int pid; 
     28  char preargs[2][20] = { "bbftpd_embedded", "-b" }; 
     29  PyObject *daemon_args, *item; 
     30 
     31  if (!PyArg_ParseTuple(args, "O", &daemon_args)) { 
     32    return NULL; 
     33  } 
     34  Py_INCREF(daemon_args); 
    1435 
    1536  /* 
    1637   * Convert arguments into a standard argv sequence. 
    1738   */ 
    18   argc = PyTuple_GET_SIZE(args); 
    19   if ((argv = (char*)malloc(argc*sizeof(char*))) == NULL) { 
     39  argc = PySequence_Size(daemon_args); 
     40  if ((argv = (char**)malloc((argc + 2)*sizeof(char*))) == NULL) { 
    2041    PyErr_SetString(PyExc_MemoryError, "malloc failed"); 
     42    Py_DECREF(daemon_args); 
    2143    return NULL; 
    2244  } 
    2345 
     46  // Add fixed arguments to daemon's argv 
    2447  arg_p = argv; 
    25   for (i==0; i<argc; i++) { 
    26     if ((*arg_p = PyString_AsString(PyTuple_GET_ITEM(args, i))) == NULL) { 
     48  *arg_p = preargs[0]; arg_p++; 
     49  *arg_p = preargs[1]; arg_p++; 
     50 
     51  for (i=0; i<argc; i++) { 
     52    if ((item = PySequence_GetItem(daemon_args, i)) == NULL) { 
     53      Py_DECREF(daemon_args); 
     54      return NULL; 
     55    } 
     56    if ((*arg_p = PyString_AsString(item)) == NULL) { 
    2757      free(argv); 
     58      Py_DECREF(item); 
     59      Py_DECREF(daemon_args); 
    2860      return NULL; 
    2961    } 
    3062    arg_p++; 
     63    Py_DECREF(item); 
    3164  } 
    3265 
    33   pid = bbftpd_main(argc, argv, environ); 
     66  /* 
     67   * We must reset some global variables so that bbftpd_run can be executed multiple times. 
     68   */ 
     69  be_daemon = 0; 
     70 
     71  pid = bbftpd_main(argc+2, argv, environ); 
    3472 
    3573  free(argv); 
     74  Py_DECREF(daemon_args); 
    3675  return Py_BuildValue("i", pid); 
    3776} 
    3877 
    3978static PyMethodDef BbftpdMethods[] = { 
    40   {"run", bbftpd_run, METH_VARARGS, "Execute the bbftpd server.  Returns the PID of the server process"}, 
     79  { 
     80    "run", bbftpd_run, METH_VARARGS,  
     81    "Execute the bbftpd server.\n" 
     82    "\n" 
     83    "Forks an embedded bbftpd process as if it were executed\n" 
     84    "with the command line $ bbftpd -b <args>." 
     85    "\n" 
     86    "@param args: command line arguments to pass to the server\n" 
     87    "@return: the PID of the server process\n" 
     88  }, 
    4189  {NULL, NULL, 0, NULL} 
    4290}; 
Note: See TracChangeset for help on using the changeset viewer.