"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/vnstati.c" between
vnstat-2.8.tar.gz and vnstat-2.9.tar.gz

About: vnStat is a console-based network traffic monitor (using the /proc filesystem).

vnstati.c  (vnstat-2.8):vnstati.c  (vnstat-2.9)
/* /*
vnStat image output - Copyright (C) 2007-2021 Teemu Toivola <tst@iki.fi> vnStat image output - Copyright (C) 2007-2022 Teemu Toivola <tst@iki.fi>
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 dated June, 1991. the Free Software Foundation; version 2 dated June, 1991.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
skipping to change at line 67 skipping to change at line 67
return 1; return 1;
} }
cfg.qmode = 0; cfg.qmode = 0;
configlocale(); configlocale();
strncpy_nt(p.interface, cfg.iface, 32); strncpy_nt(p.interface, cfg.iface, 32);
ic.current = time(NULL); ic.current = time(NULL);
parseargs(&p, &ic, argc, argv); parseargs(&p, &ic, argc, argv);
validateinput(&p); validateinput(&p);
validateoutput(&p);
handlecaching(&p, &ic); handlecaching(&p, &ic);
handledatabase(&p, &ic); handledatabase(&p, &ic);
openoutput(&p);
if (debug) if (debug)
printf("Qmode: %d\n", cfg.qmode); printf("Qmode: %d\n", cfg.qmode);
drawimage(&ic); drawimage(&ic);
db_close(); db_close();
if (ic.im == NULL) { if (ic.im == NULL) {
return 1; return 1;
} }
skipping to change at line 359 skipping to change at line 359
if (currentarg + 1 < argc && isdigit(argv[currentarg + 1] [0])) { if (currentarg + 1 < argc && isdigit(argv[currentarg + 1] [0])) {
cfg.listfivemins = atoi(argv[currentarg + 1]); cfg.listfivemins = atoi(argv[currentarg + 1]);
if (cfg.listfivemins < 0) { if (cfg.listfivemins < 0) {
printf("Error: Invalid limit parameter \" %s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); printf("Error: Invalid limit parameter \" %s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
currentarg++; currentarg++;
} }
} else if ((strcmp(argv[currentarg], "-s") == 0) || (strcmp(argv[ currentarg], "--summary")) == 0) { } else if ((strcmp(argv[currentarg], "-s") == 0) || (strcmp(argv[ currentarg], "--summary")) == 0) {
cfg.qmode = 5; cfg.qmode = 5;
} else if ((strcmp(argv[currentarg], "-hg") == 0) || (strcmp(argv [currentarg], "--hoursgraph")) == 0) { } else if ((strcmp(argv[currentarg], "-hg") == 0) || (strcmp(argv [currentarg], "--hoursgraph") == 0) || (strcmp(argv[currentarg], "--hourlygraph" )) == 0) {
cfg.qmode = 7; cfg.qmode = 7;
if (currentarg + 1 < argc && (strlen(argv[currentarg + 1]
) == 1 || ishelprequest(argv[currentarg + 1]))) {
if (!isdigit(argv[currentarg + 1][0]) || atoi(arg
v[currentarg + 1]) > 1 || atoi(argv[currentarg + 1]) < 0) {
if (!ishelprequest(argv[currentarg + 1]))
printf("Error: Invalid mode selec
tion \"%s\".\n", argv[currentarg + 1]);
printf(" Valid modes for %s:\n", argv[cur
rentarg]);
printf(" 0 - 24 hour sliding windows\n
");
printf(" 1 - graph start from midnight
\n");
exit(EXIT_FAILURE);
}
cfg.hourlygmode = atoi(argv[currentarg + 1]);
if (debug)
printf("Hourly graph mode changed: %d\n",
cfg.hourlygmode);
currentarg++;
}
} else if ((strcmp(argv[currentarg], "-5g") == 0) || (strcmp(argv [currentarg], "--fivegraph")) == 0) { } else if ((strcmp(argv[currentarg], "-5g") == 0) || (strcmp(argv [currentarg], "--fivegraph")) == 0) {
cfg.qmode = 10; cfg.qmode = 10;
if (currentarg + 1 < argc && isdigit(argv[currentarg + 1] [0])) { if (currentarg + 1 < argc && isdigit(argv[currentarg + 1] [0])) {
cfg.fivegresultcount = atoi(argv[currentarg + 1]) ; cfg.fivegresultcount = atoi(argv[currentarg + 1]) ;
if (cfg.fivegresultcount < FIVEGMINRESULTCOUNT) { if (cfg.fivegresultcount < FIVEGMINRESULTCOUNT) {
printf("Error: Invalid limit parameter \" %s\" for %s. A value equal or over %d is expected.\n", argv[currentarg + 1], arg v[currentarg], FIVEGMINRESULTCOUNT); printf("Error: Invalid limit parameter \" %s\" for %s. A value equal or over %d is expected.\n", argv[currentarg + 1], arg v[currentarg], FIVEGMINRESULTCOUNT);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} else if (cfg.fivegresultcount > cfg.fiveminuteh ours * 12) { } else if (cfg.fivegresultcount > cfg.fiveminuteh ours * 12) {
printf("Error: Invalid limit parameter \" %s\" for %s. Value cannot be larger than configured data retention (5MinuteHours %d * 12 = %d).\n", argv[currentarg + 1], argv[currentarg], cfg.fiveminutehours, cfg.fiveminutehours * 12); printf("Error: Invalid limit parameter \" %s\" for %s. Value cannot be larger than configured data retention (5MinuteHours %d * 12 = %d).\n", argv[currentarg + 1], argv[currentarg], cfg.fiveminutehours, cfg.fiveminutehours * 12);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
skipping to change at line 442 skipping to change at line 456
printf("Rateunit changed: %d\n", cfg.rate unit); printf("Rateunit changed: %d\n", cfg.rate unit);
currentarg++; currentarg++;
} else { } else {
cfg.rateunit = !cfg.rateunit; cfg.rateunit = !cfg.rateunit;
if (debug) if (debug)
printf("Rateunit changed: %d\n", cfg.rate unit); printf("Rateunit changed: %d\n", cfg.rate unit);
} }
} else if ((strcmp(argv[currentarg], "-b") == 0) || (strcmp(argv[ currentarg], "--begin") == 0)) { } else if ((strcmp(argv[currentarg], "-b") == 0) || (strcmp(argv[ currentarg], "--begin") == 0)) {
if (currentarg + 1 < argc) { if (currentarg + 1 < argc) {
if (!validatedatetime(argv[currentarg + 1])) { if (!validatedatetime(argv[currentarg + 1])) {
printf("Error: Invalid date format, expec ted YYYY-MM-DD HH:MM or YYYY-MM-DD.\n"); printf("Error: Invalid date format, expec ted YYYY-MM-DD HH:MM, YYYY-MM-DD or \"today\".\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
strncpy_nt(ic->databegin, argv[currentarg + 1], 1 8); strncpy_nt(ic->databegin, argv[currentarg + 1], 1 8);
currentarg++; currentarg++;
} else { } else {
printf("Error: Date of format YYYY-MM-DD HH:MM or YYYY-MM-DD for %s missing.\n", argv[currentarg]); printf("Error: Date of format YYYY-MM-DD HH:MM, Y YYY-MM-DD or \"today\" for %s missing.\n", argv[currentarg]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else if ((strcmp(argv[currentarg], "-e") == 0) || (strcmp(argv[ currentarg], "--end") == 0)) { } else if ((strcmp(argv[currentarg], "-e") == 0) || (strcmp(argv[ currentarg], "--end") == 0)) {
if (currentarg + 1 < argc) { if (currentarg + 1 < argc) {
if (!validatedatetime(argv[currentarg + 1])) { if (!validatedatetime(argv[currentarg + 1])) {
printf("Error: Invalid date format, expec ted YYYY-MM-DD HH:MM or YYYY-MM-DD.\n"); printf("Error: Invalid date format, expec ted YYYY-MM-DD HH:MM or YYYY-MM-DD.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
strncpy_nt(ic->dataend, argv[currentarg + 1], 18) ; strncpy_nt(ic->dataend, argv[currentarg + 1], 18) ;
currentarg++; currentarg++;
skipping to change at line 548 skipping to change at line 562
/* abort if error is something else than file not found */ /* abort if error is something else than file not found */
if (errno != ENOENT) { if (errno != ENOENT) {
printf("Error: Getting status for file \"%s\" failed: %s (%d)\n", p->filename, strerror(errno), errno); printf("Error: Getting status for file \"%s\" failed: %s (%d)\n", p->filename, strerror(errno), errno);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
} }
void handledatabase(IPARAMS *p, IMAGECONTENT *ic) void handledatabase(IPARAMS *p, IMAGECONTENT *ic)
{ {
int i, found = 0;
iflist *dbifl = NULL; iflist *dbifl = NULL;
if (!db_open_ro()) { if (!db_open_ro()) {
printf("Error: Failed to open database \"%s/%s\" in read-only mod e.\n", cfg.dbdir, DATABASEFILE); printf("Error: Failed to open database \"%s/%s\" in read-only mod e.\n", cfg.dbdir, DATABASEFILE);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (strlen(p->interface)) { if (strlen(p->interface)) {
if (!db_getinterfacecountbyname(p->interface)) { if (!db_getinterfacecountbyname(p->interface)) {
if (strchr(p->interface, '+') == NULL) { if (strchr(p->interface, '+') == NULL) {
printf("Error: Interface \"%s\" not found in data for (i = 1; i <= cfg.ifacematchmethod; i++) {
base.\n", p->interface); found = db_setinterfacebyalias(p->interfa
ce, p->interface, i);
if (found) {
if (debug) {
printf("Found \"%s\" with
method %d\n", p->interface, i);
}
break;
}
}
if (!found) {
printf("Error: No interface matching \"%s
\" found in database.\n", p->interface);
exit(EXIT_FAILURE);
}
} else { } else {
printf("Error: Not all requested interfaces found in database or given interfaces aren't unique.\n"); printf("Error: Not all requested interfaces found in database or given interfaces aren't unique.\n");
exit(EXIT_FAILURE);
} }
exit(EXIT_FAILURE);
} }
} else { } else {
if (db_getiflist_sorted(&dbifl, 1) <= 0) { if (db_getiflist_sorted(&dbifl, 1) <= 0) {
printf("Error: Unable to discover suitable interface from database.\n"); printf("Error: Unable to discover suitable interface from database.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
strncpy_nt(p->interface, dbifl->interface, 32); strncpy_nt(p->interface, dbifl->interface, 32);
iflistfree(&dbifl); iflistfree(&dbifl);
if (debug) if (debug)
printf("Automatically selected interface: \"%s\"\n", p->i nterface); printf("Automatically selected interface: \"%s\"\n", p->i nterface);
} }
if (!db_getinterfaceinfo(p->interface, &ic->interface)) { if (!db_getinterfaceinfo(p->interface, &ic->interface)) {
printf("Error: Failed to fetch interface \"%s\" details from data base.\n", p->interface); printf("Error: Failed to fetch interface \"%s\" details from data base.\n", p->interface);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
void openoutput(IPARAMS *p) void validateoutput(IPARAMS *p)
{
#if HAVE_DECL_GDIMAGEFILE
/* not output to stdout */
if (!(strlen(p->filename) == 1 && p->filename[0] == '-')) {
if (!gdSupportsFileType(p->filename, 1)) {
printf("Error: Image format file extension for \"%s\" is
not supported or recognized\n\n", p->filename);
showsupportedfileextensions();
exit(EXIT_FAILURE);
}
}
#else
/* show warning if given filename doesn't end with .png when gdImageFile(
) isn't available */
if (!(strlen(p->filename) >= 4 && strcmp(p->filename + strlen(p->filename
) - 4, ".png") == 0)) {
printf("Warning: Image format selection based on file extension i
s not available in used LibGD %d.%d.%d, \"%s\" will be written as png.\n", GD_MA
JOR_VERSION, GD_MINOR_VERSION, GD_RELEASE_VERSION, p->filename);
}
#endif
}
void writeoutput(IPARAMS *p, IMAGECONTENT *ic)
{ {
if (ic->im == NULL) {
return;
}
/* output to stdout is always png */
if (strlen(p->filename) == 1 && p->filename[0] == '-') { if (strlen(p->filename) == 1 && p->filename[0] == '-') {
/* output to stdout */
if ((p->pngout = fdopen(1, "w")) == NULL) { if ((p->pngout = fdopen(1, "w")) == NULL) {
printf("Error: Opening stdout for output failed: %s\n", s trerror(errno)); printf("Error: Opening stdout for output failed: %s\n", s trerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
gdImagePng(ic->im, p->pngout);
fclose(p->pngout);
} else { } else {
#if HAVE_DECL_GDIMAGEFILE
/* avoid "Palette image not supported by webp" */
if (strlen(p->filename) >= 5 && strcmp(p->filename + strlen(p->fi
lename) - 5, ".webp") == 0) {
gdImagePaletteToTrueColor(ic->im);
}
if (!gdImageFile(ic->im, p->filename)) {
printf("Error: Writing output to \"%s\" failed: %s\n", p-
>filename, strerror(errno));
exit(EXIT_FAILURE);
}
#else
if ((p->pngout = fopen(p->filename, "w")) == NULL) { if ((p->pngout = fopen(p->filename, "w")) == NULL) {
printf("Error: Opening file \"%s\" for output failed: %s\ n", p->filename, strerror(errno)); printf("Error: Opening file \"%s\" for output failed: %s\ n", p->filename, strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
gdImagePng(ic->im, p->pngout);
fclose(p->pngout);
#endif
} }
gdImageDestroy(ic->im);
} }
void writeoutput(IPARAMS *p, IMAGECONTENT *ic) #if HAVE_DECL_GDIMAGEFILE
void showsupportedfileextensions(void)
{ {
if (ic->im == NULL) { int i;
return; const char *extensions[] = {".avif", ".bmp", ".gif", ".heif", ".heix", ".
} jpeg", ".jpg", ".png", ".tga", ".tif", ".tiff", ".wbmp", ".webp", ".xbm", ".xpm"
};
gdImagePng(ic->im, p->pngout); printf("Supported image format file extensions in current environment:\n"
fclose(p->pngout); );
gdImageDestroy(ic->im);
for (i = 0; i < 15; i++) {
if (gdSupportsFileType(extensions[i], 1)) {
printf("%s ", extensions[i]);
}
}
printf("\n");
} }
#endif
 End of changes. 22 change blocks. 
17 lines changed or deleted 108 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)