#include "mtr.h"
#include "asn.h"
-/*
-#ifndef IIDEBUG
-#define IIDEBUG
+//#define IIDEBUG
+
+#ifdef IIDEBUG
#include <syslog.h>
+#define DEB_syslog syslog
+#else
+#define DEB_syslog(...) do {} while (0)
#endif
-*/
+
#define IIHASH_HI 128
#define ITEMSMAX 15
memset(answer, 0, PACKETSZ);
if((len = res_query(domain, C_IN, T_TXT, answer, PACKETSZ)) < 0) {
-#ifdef IIDEBUG
if (iihash)
- syslog(LOG_INFO, "Malloc-txt: %s", UNKN);
-#endif
+ DEB_syslog(LOG_INFO, "Malloc-txt: %s", UNKN);
return (iihash)?strdup(UNKN):UNKN;
}
strncpy(txt, (char*) pt, txtlen);
txt[txtlen] = 0;
-#ifdef IIDEBUG
if (iihash)
- syslog(LOG_INFO, "Malloc-txt(%p): %s", txt, txt);
-#endif
+ DEB_syslog(LOG_INFO, "Malloc-txt(%p): %s", txt, txt);
return txt;
}
if (!txt_rec)
return NULL;
if (iihash) {
-#ifdef IIDEBUG
- syslog(LOG_INFO, "Malloc-tbl: %s", txt_rec);
-#endif
+ DEB_syslog(LOG_INFO, "Malloc-tbl: %s", txt_rec);
if (!(items = malloc(sizeof(*items)))) {
-#ifdef IIDEBUG
- syslog(LOG_INFO, "Free-txt(%p)", txt_rec);
-#endif
+ DEB_syslog(LOG_INFO, "Free-txt(%p)", txt_rec);
free(txt_rec);
return NULL;
}
ENTRY item;
if (iihash) {
-#ifdef IIDEBUG
- syslog(LOG_INFO, ">> Search: %s", key);
-#endif
+ DEB_syslog(LOG_INFO, ">> Search: %s", key);
item.key = key;;
ENTRY *found_item;
if ((found_item = hsearch(item, FIND))) {
if (!(val = (*((items_t*)found_item->data))[ipinfo_no]))
val = (*((items_t*)found_item->data))[0];
-#ifdef IIDEBUG
- syslog(LOG_INFO, "Found (hashed): %s", val);
-#endif
+ DEB_syslog(LOG_INFO, "Found (hashed): %s", val);
}
}
if (!val) {
-#ifdef IIDEBUG
- syslog(LOG_INFO, "Lookup: %s", key);
-#endif
+ DEB_syslog(LOG_INFO, "Lookup: %s", key);
if ((val = split_txtrec(ipinfo_lookup(lookup_key)))) {
-#ifdef IIDEBUG
- syslog(LOG_INFO, "Looked up: %s", key);
-#endif
+ DEB_syslog(LOG_INFO, "Looked up: %s", key);
if (iihash)
if ((item.key = strdup(key))) {
item.data = items;
hsearch(item, ENTER);
-#ifdef IIDEBUG
- syslog(LOG_INFO, "Insert into hash: %s", key);
-#endif
+ DEB_syslog(LOG_INFO, "Insert into hash: %s", key);
}
}
}
void asn_open(void) {
if (ipinfo_no >= 0) {
-#ifdef IIDEBUG
- syslog(LOG_INFO, "hcreate(%d)", IIHASH_HI);
-#endif
+ DEB_syslog(LOG_INFO, "hcreate(%d)", IIHASH_HI);
if (!(iihash = hcreate(IIHASH_HI)))
perror("ipinfo hash");
}
}
void asn_close(void) {
- if (iihash) {
-#ifdef IIDEBUG
- syslog(LOG_INFO, "hdestroy()");
-#endif
+ if ((ipinfo_no >= 0) && iihash) {
+ DEB_syslog(LOG_INFO, "hdestroy()");
hdestroy();
iihash = 0;
}
extern int DisplayMode;
#ifdef NO_CURSES
+// No support for curses mode, allow the calls to remain in the code.
#define mtr_curses_open()
#define mtr_curses_close()
#define mtr_curses_redraw()
#endif
#ifdef NO_GTK
+// No support for gtk mode, allow the calls to remain in the code.
#define gtk_open()
#define gtk_close()
#define gtk_redraw()
#endif
#ifdef NO_SPLIT
+// No support for split mode, allow the calls to remain in the code.
#define split_open()
#define split_close()
#define split_redraw()
#include "split.h"
#endif
-void display_detect(int *argc
-#ifdef NO_GTK
-UNUSED
+#ifndef IPINFO
+// No support for IPINFO allow the calls to remain in the main code.
+#define asn_open()
+#define asn_close()
#endif
- , char ***argv
-#ifdef NO_GTK
-UNUSED
+
+#ifdef NO_CURSES
+#define DEFAULT_DISPLAY DisplayReport
+#else
+#define DEFAULT_DISPLAY DisplayCurses
#endif
-) {
-#ifndef NO_CURSES
- DisplayMode = DisplayCurses;
+#ifdef NO_GTK
+#define UNUSED_IF_NO_GTK UNUSED
#else
- DisplayMode = DisplayReport;
+#define UNUSED_IF_NO_GTK
#endif
+void display_detect(int *argc UNUSED_IF_NO_GTK, char ***argv UNUSED_IF_NO_GTK)
+{
+ DisplayMode = DEFAULT_DISPLAY;
+
#ifndef NO_GTK
if(gtk_detect(argc, argv)) {
DisplayMode = DisplayGTK;
break;
case DisplayCurses:
mtr_curses_open();
-#ifdef IPINFO
- if (ipinfo_no >= 0)
- asn_open();
-#endif
+ asn_open();
break;
case DisplaySplit:
split_open();
break;
case DisplayGTK:
gtk_open();
-#ifdef IPINFO
- if (ipinfo_no >= 0)
- asn_open();
-#endif
+ asn_open();
break;
}
}
csv_close(now);
break;
case DisplayCurses:
-#ifdef IPINFO
- if (ipinfo_no >= 0)
- asn_close();
-#endif
+ asn_close();
mtr_curses_close();
break;
case DisplaySplit: