Ignore:
Timestamp:
30/05/06 16:49:09 (14 years ago)
Author:
spascoe
Message:

A python module which provides a function to start the daemon can be
built using the setup.py script. This method of invoking the server
has been briefly tested but no test cases yet.

I've taken out the initialisation/finalisation hooks from the auth API because
we shouldn't need them now. They were written assuming the python interpretter
was going to be embedded within bbftpd, but I've inverted the embedding by
wrapping bbftpd.c:main in a python extension function.

File:
1 edited

Legend:

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

    r973 r1064  
    116116#define OPTIONS    "bd:e:fl:m:R:suvw:" 
    117117#endif 
     118 
     119#ifdef NDG_PYTHON_EMBED 
     120#include <Python.h> 
     121extern char **environ; 
     122 
     123#endif // NDG_PYTHON_EMBED 
     124 
    118125/* 
    119126** Common variables for BBFTP protocole version 1 and 2 
     
    383390struct  timeval  tstart; 
    384391 
     392#ifdef NDG_PYTHON_EMBED 
     393bbftpd_main (argc, argv, envp) 
     394#else 
    385395main (argc,argv,envp) 
     396#endif //NDG_PYTHON_EMBED 
    386397    int     argc ; 
    387398    char    **argv ; 
     
    790801    } 
    791802#endif 
    792 #ifdef NDG_AUTH 
    793     if ( bbftpd_private_initialise(logmessage) == -1) {       
    794       syslog(BBFTPD_ERR, "bbftpd_private_init failure: %s", logmessage); 
    795       //!TODO: Should I write to stderr in all daemon modes (be_daemon)? 
    796       fprintf(stderr, "bbftpd_private_init failure: %s", logmessage); 
    797       exit(1); 
    798     } 
    799 #endif // NDG_AUTH 
    800803    if ( be_daemon == 2 ) { 
    801804        /* 
     
    10841087                state = S_PROTWAIT ; 
    10851088                sprintf(logmessage,"bbftpd version %s : OK",VERSION) ; 
     1089                syslog(BBFTPD_DEBUG, "Lets send the auth reply ..."); 
    10861090                reply(MSG_OK,logmessage) ; 
    10871091            } else { 
     
    14021406#endif 
    14031407 
     1408#ifdef NDG_PYTHON_EMBED 
     1409/* 
     1410  When embedding in python main is replaced by a simple python function call. 
     1411*/ 
     1412static PyObject *bbftpd_run(PyObject *self, PyObject *args) { 
     1413  int argc, i; 
     1414  char **argv, **arg_p; 
     1415 
     1416  /* 
     1417   * Convert arguments into a standard argv sequence. 
     1418   */ 
     1419  argc = PyTuple_GET_SIZE(args); 
     1420  if ((argv = (char*)malloc(argc*sizeof(char*))) == NULL) { 
     1421    PyErr_SetString(PyExc_MemoryError, "malloc failed"); 
     1422    return NULL; 
     1423  } 
     1424 
     1425  arg_p = argv; 
     1426  for (i==0; i<argc; i++) { 
     1427    if ((*arg_p = PyString_AsString(PyTuple_GET_ITEM(args, i))) == NULL) { 
     1428      free(argv); 
     1429      return NULL; 
     1430    } 
     1431    arg_p++; 
     1432  } 
     1433 
     1434  bbftpd_main(argc, argv, environ); 
     1435 
     1436  // I'm not sure we ever get here. 
     1437  free(argv); 
     1438  Py_RETURN_NONE; 
     1439} 
     1440 
     1441static PyMethodDef BbftpdMethods[] = { 
     1442  {"run", bbftpd_run, METH_VARARGS, "Execute the bbftpd server"}, 
     1443  {NULL, NULL, 0, NULL} 
     1444}; 
     1445 
     1446PyMODINIT_FUNC initbbftpd(void) { 
     1447  (void) Py_InitModule("bbftpd", BbftpdMethods); 
     1448} 
     1449 
     1450#endif // NDG_PYTHON_EMBED 
Note: See TracChangeset for help on using the changeset viewer.