source: TI05-delivery/trunk/src/python_ext/bbftpc.c @ 1187

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

Auto-generated documentation included for the python-server interface.

Some file clean up prior to alpha. Fixed some confusion between authentication
and authorisation in the API.

The embedded client test case is disabled because it doesn't work :-(.

Line 
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
12#include <Python.h>
13#include <stdio.h>
14
15#include "util.h"
16
17extern char **environ;
18
19int bbftpc_main(int argc, char **argv, char **envp);
20
21/**
22 * Main entry point into the bbftp client from python.
23 */
24static PyObject *bbftpc_run(PyObject *self, PyObject *args) {
25  int i, argc;
26  struct ndg_argv argv_s;
27  char *arg;
28  PyObject *client_args, *item;
29
30  if (!PyArg_ParseTuple(args, "O", &client_args)) {
31    return NULL;
32  }
33  Py_INCREF(client_args);
34
35  /*
36   * Convert arguments into a standard argv sequence.
37   */
38
39  if ((argc = PySequence_Size(client_args)) == -1) {
40    return NULL;
41  }
42  if (!ndg_argv_init(&argv_s, argc + 1)) {
43    PyErr_SetString(PyExc_MemoryError, "malloc failed");
44    Py_DECREF(client_args);
45    return NULL;
46  }
47
48  ndg_argv_add(&argv_s, "bbftpc_run");
49  for (i=0; i<argc; i++) {
50    if ((item = PySequence_GetItem(client_args, i)) == NULL) {
51      ndg_argv_clear(&argv_s); ndg_argv_free(&argv_s);
52      Py_DECREF(client_args);
53      return NULL;
54    }
55    if ((arg = PyString_AsString(item)) == NULL) {
56      ndg_argv_clear(&argv_s); ndg_argv_free(&argv_s);
57      Py_DECREF(item);
58      Py_DECREF(client_args);
59      return NULL;
60    }
61
62    if (!ndg_argv_add(&argv_s, arg)) {
63      PyErr_SetString(PyExc_MemoryError, "ndg_argv_add failed");
64      ndg_argv_clear(&argv_s); ndg_argv_free(&argv_s);
65      Py_DECREF(item);
66      Py_DECREF(client_args);
67      return NULL;
68    }
69
70    Py_DECREF(item);
71
72  }
73  Py_DECREF(client_args);
74
75  for (i=0; i<argv_s.argc; i++) {
76    fprintf(stderr, "delivery.bbftpc.run argument: %s\n", argv_s.argv[i]);
77  }
78 
79  bbftpc_main(argv_s.argc, argv_s.argv, environ);
80  ndg_argv_clear(&argv_s); ndg_argv_free(&argv_s);
81
82  Py_RETURN_NONE;
83}
84
85static PyMethodDef BbftpcMethods[] = {
86  {
87    "run", bbftpc_run, METH_VARARGS,
88    "Execute the bbftp client.\n"
89    "\n"
90    "@param args: command line arguments"
91  },
92  {NULL, NULL, 0, NULL}
93};
94
95PyMODINIT_FUNC initbbftpc(void) {
96  (void) Py_InitModule("bbftpc", BbftpcMethods);
97}
Note: See TracBrowser for help on using the repository browser.