Ignore:
Timestamp:
27/06/06 11:50:08 (13 years ago)
Author:
spascoe
Message:

bbftpc.run() has been split into run(), docommand() and close().
Multiple commands per connection should now be possible.

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

Legend:

Unmodified
Added
Removed
  • TI05-delivery/trunk/src/python_ext/bbftpc.c

    r1238 r1246  
    1717extern char **environ; 
    1818 
    19 int bbftpc_main(int argc, char **argv, char **envp); 
     19int bbftpc_init(int argc, char **argv, char **envp); 
     20void bbftpc_final(void); 
     21int treatcommand(char *cmd); 
    2022 
    2123/** 
     
    6163 
    6264    if (!ndg_argv_add(&argv_s, arg)) { 
     65 
    6366      PyErr_SetString(PyExc_MemoryError, "ndg_argv_add failed"); 
    6467      ndg_argv_clear(&argv_s); ndg_argv_free(&argv_s); 
     
    7376  Py_DECREF(client_args); 
    7477 
    75   bbftpc_main(argv_s.argc, argv_s.argv, environ); 
     78  bbftpc_init(argv_s.argc, argv_s.argv, environ); 
    7679  ndg_argv_clear(&argv_s); ndg_argv_free(&argv_s); 
    7780 
    7881  Py_RETURN_NONE; 
    7982} 
     83 
     84/** 
     85 * Close the connection 
     86 */ 
     87static PyObject *bbftpc_close(PyObject *self, PyObject *args) { 
     88 
     89  // Check there are no arguments 
     90  if (!PyArg_ParseTuple(args, "", NULL)) { 
     91    return NULL; 
     92  } 
     93 
     94  bbftpc_final(); 
     95 
     96  Py_RETURN_NONE; 
     97} 
     98 
     99static PyObject *bbftpc_docommand(PyObject *self, PyObject *args) { 
     100  char *cmd; 
     101  PyObject *ret; 
     102 
     103  if (!PyArg_ParseTuple(args, "s", &cmd)) { 
     104    return NULL; 
     105  } 
     106 
     107  if ((ret = Py_BuildValue("i", treatcommand(cmd))) == NULL) { 
     108    return NULL; 
     109  } 
     110 
     111  return ret; 
     112} 
     113 
     114     
    80115 
    81116static PyMethodDef BbftpcMethods[] = { 
     
    86121    "@param args: command line arguments" 
    87122  }, 
     123  { 
     124    "close", bbftpc_close, METH_VARARGS, 
     125    "Close the bbftp client." 
     126  }, 
     127  { 
     128    "docommand", bbftpc_docommand, METH_VARARGS, 
     129    "Run a command in the client.\n" 
     130    "\n" 
     131    "@param cmd: The command string." 
     132  }, 
    88133  {NULL, NULL, 0, NULL} 
    89134}; 
  • TI05-delivery/trunk/src/python_ext/bbftpc_main.c

    r1242 r1246  
    174174 
    175175 
    176 static void close_connection(void) { 
     176void bbftpc_final(void) { 
    177177  char    minbuffer[MINMESSLEN] ; 
    178178  struct  message *msg ; 
     
    190190} 
    191191 
    192  
    193 int bbftpc_main(int argc, char **argv, char **envp) { 
     192static void bbftpc_connect(void) { 
     193  /* 
     194  ** Set the signals 
     195  */ 
     196  bbftp_setsignals() ; 
     197   
     198   
     199  if ( debug ) 
     200    printmessage(stdout,CASE_NORMAL,0,timestamp,"Connecting to server ----------------\n",localumask) ; 
     201  reconnecttoserver() ; 
     202  if ( debug ) 
     203    printmessage(stdout,CASE_NORMAL,0,timestamp,"Connecting end ---------------------\n",localumask) ; 
     204} 
     205 
     206int bbftpc_init(int argc, char **argv, char **envp) { 
    194207  bbftpc_reset_globals(); 
    195208   
     
    200213  */ 
    201214  char    *outputfile = NULL ; 
    202   char    *bbftpcmd   = NULL ; 
    203215  /* 
    204216  ** For hostname 
     
    293305      break ; 
    294306       
    295     case 'e' :  
    296       bbftpcmd = optarg ; 
    297       break ; 
    298              
    299307    case 'm' : 
    300308      statoutput = SETTOONE ; 
     
    453461    printmessage(stderr,CASE_FATAL_ERROR,19,timestamp,"Error while private authentication : %s\n",logmessage) ; 
    454462  }      
    455      
    456   /* 
    457   ** Set the signals 
    458   */ 
    459   bbftp_setsignals() ; 
    460    
    461    
    462   if ( debug ) 
    463     printmessage(stdout,CASE_NORMAL,0,timestamp,"Connecting to server ----------------\n",localumask) ; 
    464   reconnecttoserver() ; 
    465   if ( debug ) 
    466     printmessage(stdout,CASE_NORMAL,0,timestamp,"Connecting end ---------------------\n",localumask) ; 
    467    
    468   if ( treatcommand(bbftpcmd) == 0 ) { 
    469     if (!verbose && !statoutput) printmessage(stdout,CASE_NORMAL,0,timestamp,"%s OK\n",bbftpcmd); 
    470   } else { 
    471     if (!verbose && !statoutput) printmessage(stdout,CASE_NORMAL,0,timestamp,"%s FAILED\n",bbftpcmd); 
    472   } 
    473    
    474   close_connection(); 
    475 } 
    476  
     463   
     464  bbftpc_connect(); 
     465} 
     466 
Note: See TracChangeset for help on using the changeset viewer.