printf("%d: %s\n", type, errorstring);
break;
}
-
+ fflush(stdout);
}
return result;
dbdatalistinfo datainfo;
if (!db_getdata(&datalist, &datainfo, interface->name, tablename, -1)) {
- /* TODO: match with other output style */
- printf("Error: failed to fetch %s data\n", tablename);
+ printf("Error: Failed to fetch %s data.\n", tablename);
return;
}
}
if (!db_getdata(&datalist, &datainfo, interface->name, "month", 2)) {
- /* TODO: match with other output style */
- printf("Error: failed to fetch monthly data\n");
+ printf("Error: Failed to fetch month data.\n");
return;
}
strftime(yesterdaystr, DATEBUFFLEN, cfg.dformat, d);
if (!db_getdata(&datalist, &datainfo, interface->name, "day", 2)) {
- /* TODO: match with other output style */
- printf("Error: failed to fetch daily data\n");
+ printf("Error: Failed to fetch day data.\n");
return;
}
}
if (!db_getdata(&datalist, &datainfo, interface->name, listname, limit)) {
- /* TODO: match with other output style */
- printf("Error: failed to fetch %s data\n", titlename);
+ printf("Error: Failed to fetch %s data.\n", titlename);
return;
}
printf(";");
if (!db_getdata(&datalist, &datainfo, interface->name, "day", 1)) {
- /* TODO: match with other output style */
- printf("\nError: failed to fetch daily data\n");
+ printf("\nError: Failed to fetch day data.\n");
return;
}
dbdatalistfree(&datalist);
if (!db_getdata(&datalist, &datainfo, interface->name, "month", 1)) {
- /* TODO: match with other output style */
- printf("\nError: failed to fetch monthly data\n");
+ printf("\nError: Failed to fetch month data.\n");
return;
}
}
if (!db_getdata(&datalist, &datainfo, interface->name, "hour", 24)) {
- /* TODO: match with other output style */
- printf("\nError: failed to fetch hourly data\n");
+ printf("Error: Failed to fetch hour data.\n");
return;
}
for (i=0; i<5; i++) {
if (!db_getdata(&datalist, &datainfo, interface->name, datatables[i], -1)) {
- printf("\nError: failed to fetch %s data\n", datatables[i]);
+ printf("Error: Failed to fetch %s data.\n", datatables[i]);
return;
}
datalist_i = datalist;
int db_getdata(dbdatalist **dbdata, dbdatalistinfo *listinfo, const char *iface, const char *table, const uint32_t resultlimit)
{
- int ret = 1;
+ int ret = 1, i;
+ char *datatables[] = {"fiveminute", "hour", "day", "month", "year", "top"};
char sql[512], limit[64];
sqlite3_int64 ifaceid = 0;
sqlite3_stmt *sqlstmt;
return 0;
}
- /* TODO: add table validation here */
+ ret = 0;
+ for (i=0; i<6; i++) {
+ if (strcmp(table, datatables[i]) == 0) {
+ ret = 1;
+ break;
+ }
+ }
+ if (!ret) {
+ return 0;
+ }
if (resultlimit > 0) {
snprintf(limit, 64, "limit %"PRIu32"", resultlimit);
dbdatalistinfo datainfo;
if (!db_getdata(&datalist, &datainfo, interface->name, tablename, -1)) {
- /* TODO: match with other output style */
- printf("Error: failed to fetch %s data\n", tablename);
+ printf("Error: Failed to fetch %s data.\n", tablename);
return;
}
printf("Error: Locale for %s missing.\n", argv[currentarg]);
return 1;
}
- } else if (strcmp(argv[currentarg],"--create")==0) {
- p.create=1;
+ } else if (strcmp(argv[currentarg],"--add")==0) {
+ p.addiface=1;
p.query=0;
} else if ((strcmp(argv[currentarg],"-u")==0) || (strcmp(argv[currentarg],"--update")==0)) {
printf("Error: The \"%s\" parameter is not supported in this version.\n", argv[currentarg]);
} else if (strcmp(argv[currentarg],"--showconfig")==0) {
printcfgfile();
return 0;
- } else if (strcmp(argv[currentarg],"--delete")==0) {
- p.delete=1;
+ } else if (strcmp(argv[currentarg],"--remove")==0) {
+ p.removeiface=1;
p.query=0;
} else if (strcmp(argv[currentarg],"--iflist")==0) {
getiflist(&p.ifacelist, 1);
p.interface[31]='\0';
/* parameter handlers */
- handledelete(&p);
- handlecreate(&p);
+ handleremoveinterface(&p);
+ handleaddinterface(&p);
handlesetalias(&p);
handleshowdatabases(&p);
handletrafficmeters(&p);
/* give more help if there's no database */
if (p.ifcount == 0) {
getiflist(&p.ifacelist, 1);
- printf("No database found, nothing to do. Use --help for help.\n\n");
- printf("A new database can be created with the following command:\n");
- printf(" %s --create -i eth0\n\n", argv[0]);
+ printf("No interfaces found in the database, nothing to do. Use --help for help.\n\n");
+ printf("Interfaces can be added to the database with the following command:\n");
+ printf(" %s --add -i eth0\n\n", argv[0]);
printf("Replace 'eth0' with the interface that should be monitored.\n\n");
if (strlen(cfg.cfgfile)) {
printf("The default interface can be changed by updating the \"Interface\" keyword\n");
debug = 0; /* debug disabled by default */
disableprints = 0; /* let prints be visible */
- p->create = 0;
+ p->addiface = 0;
p->query = 1;
p->setalias = 0;
p->ifcount = 0;
p->traffic = 0;
p->livetraffic = 0;
p->defaultiface = 1;
- p->delete=0;
+ p->removeiface=0;
p->livemode = 0;
p->ifacelist = NULL;
p->cfgfile[0] = '\0';
void showlonghelp(PARAMS *p)
{
- /* TODO: update */
- /* --create could be replaced with --add as it adds the interface to the database */
- /* --delete could be similarly replaced with --remove */
-
printf(" vnStat %s by Teemu Toivola <tst at iki dot fi>\n\n", getversion());
printf(" Query:\n");
printf(" --xml show database in xml format\n");
printf(" Modify:\n");
- printf(" --create create database\n");
- printf(" --delete delete database\n");
+ printf(" --add add interface to database\n");
+ printf(" --remove remove interface from database\n");
printf(" --setalias set alias for interface\n");
printf(" Misc:\n");
printf("See also \"man vnstat\".\n");
}
-void handledelete(PARAMS *p)
+void handleremoveinterface(PARAMS *p)
{
- if (!p->delete) {
+ if (!p->removeiface) {
return;
}
}
if (!p->force) {
- printf("Warning:\nThe current option would delete all data\nabout interface \"%s\" from the database.\n", p->interface);
+ printf("Warning:\nThe current option would remove all data\nabout interface \"%s\" from the database.\n", p->interface);
printf("Use --force in order to really do that.\n");
exit(EXIT_FAILURE);
}
if (db_removeinterface(p->interface)) {
- printf("Interface \"%s\" deleted from database.\n", p->interface);
- printf("The interface will no longer be monitored. Use --create\n");
+ printf("Interface \"%s\" removed from database.\n", p->interface);
+ printf("The interface will no longer be monitored. Use --add\n");
printf("if monitoring the interface is again needed.\n");
exit(EXIT_SUCCESS);
} else {
- printf("Error: Deleting interface \"%s\" from database failed.\n", p->interface);
+ printf("Error: Removing interface \"%s\" from database failed.\n", p->interface);
exit(EXIT_FAILURE);
}
}
-void handlecreate(PARAMS *p)
+void handleaddinterface(PARAMS *p)
{
char dbfile[512];
- if (!p->create) {
+ if (!p->addiface) {
return;
}
typedef struct {
int query, setalias;
- int create, ifcount, force, traffic;
- int livetraffic, defaultiface, delete, livemode;
+ int addiface, ifcount, force, traffic;
+ int livetraffic, defaultiface, removeiface, livemode;
char interface[32], dirname[512], alias[32], filename[512];
char definterface[32], cfgfile[512], *ifacelist, jsonmode, xmlmode;
} PARAMS;
void initparams(PARAMS *p);
void showhelp(PARAMS *p);
void showlonghelp(PARAMS *p);
-void handledelete(PARAMS *p);
-void handlecreate(PARAMS *p);
+void handleremoveinterface(PARAMS *p);
+void handleaddinterface(PARAMS *p);
void handlesetalias(PARAMS *p);
void handleshowdatabases(PARAMS *p);
void showoneinterface(PARAMS *p, const char *interface);