Forum

RunOnDownload Option

Prit
27 August 2009, 22:34
Hi Hugo,

Can you give more info about the RunOnDownload option? Can we pass the name/path of the file being downloaded to the script?

Hiawatha version: 6.16
Operating System: CentOS
Hugo Leisink
28 August 2009, 10:22
Information about the request is passed on via the environment, just like when executing a CGI program. I use the following program to log the download of the Hiawatha source code.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>

#define TIMESTAMP_SIZE 40

int main(void) {
char *ip_address, timestamp[TIMESTAMP_SIZE], *request_uri;
time_t t;
struct tm *s;
FILE *fp;

if ((ip_address = getenv("REMOTE_ADDR")) == NULL) {
ip_address = "unknown";
}

time(&t);
s = localtime(&t);
timestamp[TIMESTAMP_SIZE - 1] = '\0';
strftime(timestamp, TIMESTAMP_SIZE - 1, "%Y-%m-%d %H:%M:%S", s);

if ((request_uri = getenv("REQUEST_URI")) == NULL) {
request_uri = "unknown";
} else if (strlen(request_uri) > 7) {
request_uri += 7;
}

if ((fp = fopen("download.log", "a")) != NULL) {
fprintf(fp, "%s|%s|%s\n", ip_address, timestamp, request_uri);
fclose(fp);
}

return EXIT_SUCCESS;
}
Prit
28 August 2009, 10:31
Thanks Hugo. I will try this out.
Prit
29 August 2009, 06:49
Hugo,

When I log a download using the RunOnDownload option, it logs for every thread of download. To make it clear, when using some kind of download manager which splits the download into multiple ones, the log program that runs during download, logs each of these threads., But the Hiawatha access log shows only one occurrence per download. Is there anyway, I would be able to handle the RunOnDownload logs similar to how it goes to the access log.
Hugo Leisink
29 August 2009, 09:42
If a download manager opens multiple connections to Hiawatha, there should also be multiple logs in the access logfile written by Hiawatha. Please, check that you really only see one. Those logs probably contain a Range HTTP header.
Prit
29 August 2009, 17:22
You are right Hugo. I was reading the access.log incorrectly. It indeed has multiple entries for multiple connections. Maybe I should add some logic within the log program to detect the multiple thread and log only once.
Hugo Leisink
29 August 2009, 17:58
I just added the Range HTTP header line, which will be available in the official 6.17 release. Maybe you can use it for detecting partial uploads.
Prit
29 August 2009, 18:13
Will this enable us to count the split downloads caused by download managers as 1? Also, can you let me know how to use this header?
Hugo Leisink
29 August 2009, 18:27
How the Range HTTP header works can be read in the HTTP RFC [www.w3.org]. What you can do is, if the header is not present, just log. If it is present, only log if the value of the header contains "1-". In other words, only log if the first part of the file is requested.
Prit
31 August 2009, 07:41
I downloaded the latest version (6.17) and below is a sample output of what I see from the range header. The 2nd field on each record is the range header. This output is produced when downloading this one file using a download manager.

devx-4.3beta1-k2.6.29.6_423.sfs|
devx-4.3beta1-k2.6.29.6_423.sfs|
devx-4.3beta1-k2.6.29.6_423.sfs|bytes=70702081-
devx-4.3beta1-k2.6.29.6_423.sfs|bytes=23567361-
devx-4.3beta1-k2.6.29.6_423.sfs|bytes=47134721-
devx-4.3beta1-k2.6.29.6_423.sfs|bytes=43839151-
devx-4.3beta1-k2.6.29.6_423.sfs|bytes=45637348-
devx-4.3beta1-k2.6.29.6_423.sfs|bytes=46529589-
This topic has been closed.