Browse code

freshclam/manager.c: add machine/OS info to the default user agent string

git-svn: trunk@4097

Tomasz Kojm authored on 2008/08/11 00:59:45
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Sun Aug 10 17:46:12 CEST 2008 (tk)
2
+----------------------------------
3
+  * freshclam/manager.c: add machine/OS info to the default user agent string
4
+
1 5
 Thu Aug  7 14:27:44 CEST 2008 (tk)
2 6
 ----------------------------------
3 7
   * unit_tests/check_matchers.c: add tests for cli_(ac|bm)_scanbuff
... ...
@@ -56,6 +56,8 @@
56 56
 #include <errno.h>
57 57
 #include <zlib.h>
58 58
 
59
+#include "target.h"
60
+
59 61
 #include "manager.h"
60 62
 #include "notify.h"
61 63
 #include "dns.h"
... ...
@@ -474,7 +476,7 @@ static struct cl_cvd *remote_cvdhead(const char *file, const char *hostname, cha
474 474
 	unsigned int i, j;
475 475
 	char *remotename = NULL, *authorization = NULL;
476 476
 	struct cl_cvd *cvd;
477
-	char last_modified[36];
477
+	char last_modified[36], uastr[128];
478 478
 	struct stat sb;
479 479
 
480 480
 
... ...
@@ -506,15 +508,20 @@ static struct cl_cvd *remote_cvdhead(const char *file, const char *hostname, cha
506 506
 
507 507
     logg("Reading CVD header (%s): ", file);
508 508
 
509
+    if(uas)
510
+	strncpy(uastr, uas, sizeof(uastr));
511
+    else
512
+	snprintf(uastr, sizeof(uastr), PACKAGE"/%s (OS: "TARGET_OS_TYPE", ARCH: "TARGET_ARCH_TYPE", CPU: "TARGET_CPU_TYPE")", get_version());
513
+    uastr[sizeof(uastr) - 1] = 0;
514
+
509 515
     snprintf(cmd, sizeof(cmd),
510 516
 	"GET %s/%s HTTP/1.0\r\n"
511 517
 	"Host: %s\r\n%s"
512
-	"User-Agent: %s%s\r\n"
518
+	"User-Agent: %s\r\n"
513 519
 	"Connection: close\r\n"
514 520
 	"Range: bytes=0-511\r\n"
515 521
         "If-Modified-Since: %s\r\n"
516
-        "\r\n", (remotename != NULL) ? remotename : "", file, hostname, (authorization != NULL) ? authorization : "", 
517
-	uas ? uas : PACKAGE"/",uas ? "" : get_version(), last_modified);
522
+        "\r\n", (remotename != NULL) ? remotename : "", file, hostname, (authorization != NULL) ? authorization : "", uastr, last_modified);
518 523
 
519 524
     free(remotename);
520 525
     free(authorization);
... ...
@@ -627,7 +634,7 @@ static struct cl_cvd *remote_cvdhead(const char *file, const char *hostname, cha
627 627
 
628 628
 static int getfile(const char *srcfile, const char *destfile, const char *hostname, char *ip, const char *localip, const char *proxy, int port, const char *user, const char *pass, const char *uas, int ctimeout, int rtimeout, struct mirdat *mdat, int logerr, unsigned int can_whitelist)
629 629
 {
630
-	char cmd[512], buffer[FILEBUFF], *ch;
630
+	char cmd[512], uastr[128], buffer[FILEBUFF], *ch;
631 631
 	int bread, fd, totalsize = 0,  rot = 0, totaldownloaded = 0,
632 632
 	    percentage = 0, sd;
633 633
 	unsigned int i;
... ...
@@ -650,16 +657,21 @@ static int getfile(const char *srcfile, const char *destfile, const char *hostna
650 650
 	}
651 651
     }
652 652
 
653
+    if(uas)
654
+	strncpy(uastr, uas, sizeof(uastr));
655
+    else
656
+	snprintf(uastr, sizeof(uastr), PACKAGE"/%s (OS: "TARGET_OS_TYPE", ARCH: "TARGET_ARCH_TYPE", CPU: "TARGET_CPU_TYPE")", get_version());
657
+    uastr[sizeof(uastr) - 1] = 0;
658
+
653 659
     snprintf(cmd, sizeof(cmd),
654 660
 	"GET %s/%s HTTP/1.0\r\n"
655 661
 	"Host: %s\r\n%s"
656
-	"User-Agent: %s%s\r\n"
662
+	"User-Agent: %s\r\n"
657 663
 #ifdef FRESHCLAM_NO_CACHE
658 664
 	"Cache-Control: no-cache\r\n"
659 665
 #endif
660 666
 	"Connection: close\r\n"
661
-	"\r\n", (remotename != NULL) ? remotename : "", srcfile, hostname, (authorization != NULL) ? authorization : "",
662
-	uas ? uas : PACKAGE"/", uas ? "" : get_version());
667
+	"\r\n", (remotename != NULL) ? remotename : "", srcfile, hostname, (authorization != NULL) ? authorization : "", uastr);
663 668
 
664 669
     memset(ipaddr, 0, sizeof(ipaddr));
665 670
     if(ip[0]) /* use ip to connect */