Ignore:
Timestamp:
31/05/06 17:03:55 (14 years ago)
Author:
spascoe
Message:

Python code can read an authorisation message from the client.

Test cases confirm message passing client->server->python is working.

Location:
TI05-delivery/trunk/src
Files:
2 edited

Legend:

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

    r1074 r1075  
    9797int bbftpd_private_auth(char *logmessage) 
    9898{ 
     99 
     100#ifdef NDG_PYTHON_EMBED 
    99101  char *username; 
     102 
     103  if (bbftpd_private_auth_callback(logmessage) == -1) { 
     104    return -1; 
     105  } 
     106  if ((username = bbftpd_private_auth_getusername(logmessage)) == NULL) { 
     107    return -1; 
     108  } 
     109    
     110  sprintf(currentusername, "%.*s", MAXLEN, username); 
     111#else 
    100112 
    101113  char msg[NDG_MESSAGE_LEN]; 
     
    108120  } 
    109121 
    110 #ifdef NDG_PYTHON_EMBED 
    111   if (bbftpd_private_auth_callback(logmessage) == -1) { 
    112     return -1; 
    113   } 
    114   if ((username = bbftpd_private_auth_getusername(logmessage)) == NULL) { 
    115     return -1; 
    116   } 
    117     
    118   sprintf(currentusername, "%.*s", MAXLEN, username); 
    119122#endif 
    120123 
  • TI05-delivery/trunk/src/python_ext/bbftpd.c

    r1073 r1075  
    1414extern char **environ; 
    1515/* 
    16  * variables and prototypes from bbftpd.c 
     16 * variables and prototypes from bbftpd source 
    1717 */ 
    1818 
     
    2121 
    2222int bbftpd_main(int argc, char **argv, char **envp); 
     23int bbftpd_private_send(char *buffertosend, int buffertosendlength, char *logmessage) ; 
     24int bbftpd_private_recv(char *buffertorecv, int lengthtorecv, char *logmessage) ; 
    2325 
    2426/* 
     
    100102 * 
    101103 */ 
     104 
     105/* send(string) */ 
     106static PyObject *bbftpd_send(PyObject *self, PyObject *args) { 
     107  char *buffer, logmessage[1024]; 
     108  int len; 
     109 
     110  if (!PyArg_ParseTuple(args, "s#", &buffer, &len)) { 
     111    return NULL; 
     112  } 
     113 
     114  if (authContext == NULL) { 
     115    PyErr_SetString(PyExc_RuntimeError, "Must be called within a bbftpd callback"); 
     116    return NULL; 
     117  } 
     118 
     119  if (bbftpd_private_send(buffer, len, logmessage) == -1) { 
     120    PyErr_SetString(PyExc_IOError, logmessage); 
     121    return NULL; 
     122  } 
     123 
     124  Py_RETURN_NONE; 
     125} 
     126 
     127/* recv(length) -> string */ 
     128static PyObject *bbftpd_recv(PyObject *self, PyObject *args) { 
     129  char *buffer, logmessage[1024]; 
     130  int len; 
     131 
     132  if (!PyArg_ParseTuple(args, "i", &len)) { 
     133    return NULL; 
     134  } 
     135 
     136  if (authContext == NULL) { 
     137    PyErr_SetString(PyExc_RuntimeError, "Must be called within a bbftpd callback"); 
     138    return NULL; 
     139  } 
     140  if ((buffer = (char*)malloc(len*sizeof(char))) == NULL) { 
     141    PyErr_NoMemory(); 
     142    return NULL; 
     143  } 
     144 
     145  if (bbftpd_private_recv(buffer, len, logmessage) == -1) { 
     146    PyErr_SetString(PyExc_IOError, logmessage); 
     147    free(buffer); 
     148    return NULL; 
     149  } 
     150 
     151  return Py_BuildValue("s#", buffer, len); 
     152} 
     153 
    102154 
    103155/** 
     
    174226    "@return: the PID of the server process\n" 
    175227  }, 
     228  { 
     229    "send", bbftpd_send, METH_VARARGS, 
     230    "Send an authentication message to the client.\n" 
     231    "\n" 
     232    "Equivilent to bbftpd_private_send() C call.\n" 
     233    "\n" 
     234    "@param buffer: A string containing the message\n" 
     235    "@raise IOError: if bbftpd_private_send() call fails\n" 
     236  }, 
     237  { 
     238    "recv", bbftpd_recv, METH_VARARGS, 
     239    "Receive an authentication message from the client.\n" 
     240    "\n" 
     241    "Equivilent to bbftpd_private_recv() C call.\n" 
     242    "\n" 
     243    "@param len: The length of message to expect\n" 
     244    "@return: A string containing the message\n" 
     245    "@raise IOError: if bbftpd_private_recv() call fails\n" 
     246  }, 
    176247  {NULL, NULL, 0, NULL} 
    177248}; 
Note: See TracChangeset for help on using the changeset viewer.