source: TI05-delivery/trunk/src/python_ext/bbftpd.c @ 1067

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/trunk/src/python_ext/bbftpd.c@1067
Revision 1067, 1.1 KB checked in by spascoe, 13 years ago (diff)

Moved the python bbftpd extension module source code to it's own file.

Line 
1#include <Python.h>
2
3extern char **environ;
4/* From bbftpd.c */
5int bbftpd_main(int argc, char **argv, char **envp);
6
7/*
8  When embedding in python main is replaced by a simple python function call.
9*/
10static PyObject *bbftpd_run(PyObject *self, PyObject *args) {
11  int argc, i;
12  char **argv, **arg_p;
13  int pid;
14
15  /*
16   * Convert arguments into a standard argv sequence.
17   */
18  argc = PyTuple_GET_SIZE(args);
19  if ((argv = (char*)malloc(argc*sizeof(char*))) == NULL) {
20    PyErr_SetString(PyExc_MemoryError, "malloc failed");
21    return NULL;
22  }
23
24  arg_p = argv;
25  for (i==0; i<argc; i++) {
26    if ((*arg_p = PyString_AsString(PyTuple_GET_ITEM(args, i))) == NULL) {
27      free(argv);
28      return NULL;
29    }
30    arg_p++;
31  }
32
33  pid = bbftpd_main(argc, argv, environ);
34
35  free(argv);
36  return Py_BuildValue("i", pid);
37}
38
39static PyMethodDef BbftpdMethods[] = {
40  {"run", bbftpd_run, METH_VARARGS, "Execute the bbftpd server.  Returns the PID of the server process"},
41  {NULL, NULL, 0, NULL}
42};
43
44PyMODINIT_FUNC initbbftpd(void) {
45  (void) Py_InitModule("bbftpd", BbftpdMethods);
46}
47
Note: See TracBrowser for help on using the repository browser.