Hi everybody, first post to this list.

Thanks to Luca and all the others for Ntop, very nice tool.

Please find attached a patch to emitter.c , from v. 2.1.2, that adds Python 
support when accessing stats via Web.

It wasn't hard to do, and it's convenient not having to reparse the output.


-- 
Nicola Larosa
Direttore Tecnico - Araknos srl
[EMAIL PROTECTED]
--- emitter.c   Thu Jul  4 00:11:40 2002
+++ emitter.c.new       Fri Aug 30 16:25:18 2002
@@ -24,8 +24,9 @@
 #define PERL_LANGUAGE       1
 #define PHP_LANGUAGE        2
 #define XML_LANGUAGE        3
-#define NO_LANGUAGE         4
-#define NB_LANGUAGES        4
+#define PYTHON_LANGUAGE     4
+#define NO_LANGUAGE         5
+#define NB_LANGUAGES        5
 #define DEFAULT_LANGUAGE    NO_LANGUAGE
 
 
@@ -35,7 +36,7 @@
 
   Many thanks Philippe!
 */
-char *languages[] = { "", "perl", "php", "xml", "no" };
+char *languages[] = { "", "perl", "php", "xml", "python", "no" };
 
 /* *************************** */
 
@@ -66,6 +67,9 @@
     sendEmitterString(fDescr, "<rpc-reply 
xmlns:ntop=\"http://www.ntop.org/ntop.dtd\";>"
                      "\n<ntop-traffic-information>\n");
     break ;
+  case PYTHON_LANGUAGE:
+    sendEmitterString(fDescr, "ntopDict = {\n");
+    break ;
   case NO_LANGUAGE:
     break ;
   }
@@ -82,6 +86,9 @@
   case XML_LANGUAGE:
     sendEmitterString(fDescr, "</ntop-traffic-information>\n</rpc-reply>\n");
     break ;
+  case PYTHON_LANGUAGE:
+    sendEmitterString(fDescr, "}\n");
+    break ;
   case NO_LANGUAGE:
     sendEmitterString(fDescr, "\n");
     break ;
@@ -128,6 +135,11 @@
       BufferTooShort();
     sendEmitterString(fDescr, buf);
     break ;
+  case PYTHON_LANGUAGE:
+    if(snprintf(buf, sizeof(buf), "%s'%s': {\n",indent, keyName) < 0)
+      BufferTooShort();
+    sendEmitterString(fDescr, buf);
+    break ;
   case NO_LANGUAGE:
     if(snprintf(buf, sizeof(buf), "%s|",
                numEntriesSent == 0 ? "key" : keyName) < 0)
@@ -166,6 +178,11 @@
       BufferTooShort();
     sendEmitterString(fDescr, buf);
     break ;
+  case PYTHON_LANGUAGE:
+    if(snprintf(buf, sizeof(buf),"%s}%c\n",indent,last) < 0)
+      BufferTooShort();
+    sendEmitterString(fDescr, buf);
+    break ;
   case NO_LANGUAGE:
     if(strcmp(indent, "") == 0) sendEmitterString(fDescr, "\n");
     break ;
@@ -197,6 +214,13 @@
     if((value != NULL) && (value[0] != '\0'))
       {
        if(snprintf(buf, sizeof(buf), "%s<%s>%s</%s>\n", indent, name, value, name) < 
0)
+         BufferTooShort();  sendEmitterString(fDescr, buf);
+      }
+    break ;
+  case PYTHON_LANGUAGE:
+    if((value != NULL) && (value[0] != '\0'))
+      {
+       if(snprintf(buf, sizeof(buf), "%s'%s': '%s'%c\n", indent,name,value,last) < 0)
          BufferTooShort();  sendEmitterString(fDescr, buf);
       }
     break ;

Reply via email to