Changeset 1444 for TI05-delivery


Ignore:
Timestamp:
22/08/06 17:00:57 (13 years ago)
Author:
spascoe
Message:

BROKEN!

I'm in the middle of implementing a logging callback in the server.

Location:
TI05-delivery/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/trunk/examples/deliveryd.py

    r1441 r1444  
    1616NDG_HANDSHAKE = "NDG-Delivery-server %s" % VERSION 
    1717 
     18import logging 
     19logging.basicConfig(level=logging.DEBUG) 
    1820 
    1921import ndg.delivery.server.pybbftp as server 
     
    7274''' 
    7375 
     76# Assuming logging 
     77sys.exit(0) 
     78 
    7479logfile = './bbftpd.log' 
    7580n = len(open(logfile).readlines()) 
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_private_log.c

    r1369 r1444  
    3434#include <errno.h> 
    3535 
     36 
     37#ifdef NDG_PYTHON_EMBED 
     38 
     39void bbftpd_openlog(const char *ident, int option, int facility) { 
     40  return; 
     41} 
     42 
     43void bbftpd_closelog(void) { 
     44  return; 
     45} 
     46 
     47void bbftpd_log(int priority, const char *format, ...) { 
     48  va_list ap; 
     49 
     50  va_start(ap, format); 
     51  ndg_log(priority, format, ap); 
     52  va_end(ap); 
     53} 
     54 
     55#else // NDG_PYTHON_EMBED 
     56 
    3657static const char *log_ident; 
    3758static FILE *logfh = NULL; 
    3859 
    3960#define LOGFILE "bbftpd.log" 
     61 
    4062 
    4163/** 
     
    85107} 
    86108 
     109#endif // NDG_PYTHON_EMBED 
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/includes/ndg.h

    r1428 r1444  
    3636int ndg_authz_retr(char *path, char *logmessage); 
    3737int ndg_authz_store(char *path, char *logmessage); 
     38void ndg_log(int priority, const char *format, va_list vargs); 
    3839 
    3940 
  • TI05-delivery/trunk/src/python_ext/bbftpd.c

    r1358 r1444  
    1212 
    1313#include <Python.h> 
     14#include <stdlib.h> 
     15#include <stdarg.h> 
    1416#include <ndg.h> 
    1517#include "util.h" 
     
    3436static PyObject *authHandler = NULL; 
    3537static PyObject *authzHandler = NULL; 
     38static PyObject *serverLogger = NULL; 
     39 
     40 
     41/** 
     42 * Get a logger object from the logging module. 
     43 * 
     44 * @param loggerName the name of the logger passed to logging.getLogger() 
     45 * @return a new reference to the logger object 
     46 */ 
     47static PyObject *getLogger(char *loggerName) { 
     48  PyObject *logging, *logger; 
     49 
     50  if ((logging = PyImport_ImportModule("logging")) == NULL) { 
     51    return NULL; 
     52  } 
     53  if ((logger = PyObject_CallMethod(logging, "getLogger", "s", loggerName)) == NULL) { 
     54    return NULL; 
     55  } 
     56 
     57  return logger; 
     58} 
     59 
    3660 
    3761/*--------------------------------------------------------------------------------------------------- 
     
    4064 * 
    4165 */ 
     66 
    4267 
    4368 
     
    194219} 
    195220  
    196  
     221/** 
     222 * Make a callback to log a message to the ndg.delivery.server logger. 
     223 * 
     224 * @param priority syslog-style priority 
     225 * @param format the message with printf-style format specifiers 
     226 * @param vargs argument list for inclusion in the message. 
     227 */ 
     228void ndg_log(int priority, const char *format, va_list vargs) { 
     229  PyObject *message; 
     230  char *priority_method; 
     231 
     232  /* Just in case this is somehow called outsite pybbftpd_run() */ 
     233  if (serverLogger == NULL) return; 
     234   
     235  if ((message = PyString_FromFormatV(format, vargs)) == NULL) { 
     236    if ((message = PyString_FromString("ndg_log: PyString_FromFormatV error")) == NULL) { 
     237      /* Desperate measures! */ 
     238      abort(); 
     239    } 
     240  } 
     241 
     242  switch (priority) { 
     243  case LOG_DEBUG: 
     244    priority_method = "debug"; break; 
     245  case LOG_INFO: 
     246    priority_method = "info"; break; 
     247  case LOG_NOTICE: 
     248    priority_method = "info"; break; 
     249  case LOG_WARNING: 
     250    priority_method = "warning"; break; 
     251  case LOG_ERR: 
     252    priority_method = "error"; break; 
     253  default: 
     254    priority_method = "critical"; break; 
     255  } 
     256 
     257  if ((PyObject_CallMethod(serverLogger, priority_method, "O", message)) == NULL) { 
     258    /*!TODO: Work out how better to recover from this error */ 
     259    abort(); 
     260  } 
     261 
     262  Py_DECREF(message); 
     263  return; 
     264} 
    197265      
    198266/*------------------------------------------------------------------------------------------------- 
     
    263331  return ret; 
    264332} 
    265  
    266  
    267333 
    268334/** 
     
    324390  } 
    325391 
     392  /* Initialise logger */ 
     393  if (serverLogger != NULL) { 
     394    Py_DECREF(serverLogger); 
     395  } 
     396  if ((serverLogger = getLogger("ndg.delivery.server")) == NULL) { 
     397    return NULL; 
     398  } 
     399 
    326400  /* 
    327401   * We must reset some global variables so that bbftpd_run can be executed multiple times. 
     
    402476  ADDCONST(mod, TROPT_RFIO_O); 
    403477  ADDCONST(mod, TROPT_QBSS); 
    404    
    405 } 
    406  
     478} 
     479 
Note: See TracChangeset for help on using the changeset viewer.