Exemplo n.º 1
0
int main (void)
{
    int year, i;
    apr_time_t guess;
    apr_time_t offset = 0;
 /* apr_time_t offset = 0; */
 /* apr_time_t offset = ((31 + 28) * 24 * 3600) - 1; */
    apr_time_t secstodate, newsecs;
    char datestr[50];

    for (year = 1970; year < 2038; ++year) {
        secstodate = year2secs[year - 1970] + offset;
        gm_timestr_822(datestr, secstodate);
        secstodate *= APR_USEC_PER_SEC;
        newsecs = apr_date_parse_http(datestr);
        if (secstodate == newsecs)
            printf("Yes %4d %19" APR_TIME_T_FMT " %s\n", year, secstodate, datestr);
        else if (newsecs == APR_DATE_BAD)
            printf("No  %4d %19" APR_TIME_T_FMT " %19" APR_TIME_T_FMT " %s\n",
                   year, secstodate, newsecs, datestr);
        else
            printf("No* %4d %19" APR_TIME_T_FMT " %19" APR_TIME_T_FMT " %s\n",
                   year, secstodate, newsecs, datestr);
    }
    
    srand48(978245L);

    for (i = 0; i < 10000; ++i) {
        guess = (time_t)mrand48();
        if (guess < 0) guess *= -1;
        secstodate = guess + offset;
        gm_timestr_822(datestr, secstodate);
        secstodate *= APR_USEC_PER_SEC;
        newsecs = apr_date_parse_http(datestr);
        if (secstodate == newsecs)
            printf("Yes %" APR_TIME_T_FMT " %s\n", secstodate, datestr);
        else if (newsecs == APR_DATE_BAD)
            printf("No  %" APR_TIME_T_FMT " %" APR_TIME_T_FMT " %s\n", 
                   secstodate, newsecs, datestr);
        else
            printf("No* %" APR_TIME_T_FMT " %" APR_TIME_T_FMT " %s\n", 
                   secstodate, newsecs, datestr);
    }
    exit(0);
}
Exemplo n.º 2
0
void send_http_header(per_request *reqInfo) 
{
    if(!reqInfo->status_line) {
       /* Special Cases */
        if(reqInfo->outh_location[0])
            reqInfo->status = SC_REDIRECT_TEMP;
	if(reqInfo->outh_www_auth[0])
	    reqInfo->status = SC_AUTH_REQUIRED;
	set_stat_line(reqInfo);
    }    
    rprintf(reqInfo,"%s %s%c%c",protocals[reqInfo->http_version],
	    reqInfo->status_line,CR,LF);
    rprintf(reqInfo,"Date: %s%c%c",gm_timestr_822(time(NULL)),CR,LF);
    rprintf(reqInfo,"Server: %s%c%c",SERVER_VERSION,CR,LF);
    if (reqInfo->hostInfo->annotation_server[0])
	rprintf(reqInfo,"Annotations-cgi: %s%c%c",
		reqInfo->hostInfo->annotation_server,CR,LF);

    if(reqInfo->outh_location[0])
        rprintf(reqInfo,"Location: %s%c%c",
		reqInfo->outh_location,CR,LF);
    if(reqInfo->outh_last_mod[0])
        rprintf(reqInfo,"Last-modified: %s%c%c",
		reqInfo->outh_last_mod,CR,LF);

    if(reqInfo->outh_content_type[0]) 
        rprintf(reqInfo,"Content-type: %s%c%c",
	        reqInfo->outh_content_type,CR,LF);

/* If we know the content_length, we can fulfill byte range requests */
    if(reqInfo->outh_content_length >= 0) {
/* Not yet, working on it */
/*	rprintf(reqInfo,"Accept-Ranges: bytes%c%c",CR,LF); */
        rprintf(reqInfo,"Content-length: %d%c%c",
		reqInfo->outh_content_length,CR,LF);
    }
    if(reqInfo->outh_content_encoding[0])
        rprintf(reqInfo,"Content-encoding: %s%c%c",
		reqInfo->outh_content_encoding,CR,LF);
#ifdef CONTENT_MD5
    if(reqInfo->outh_content_md5)
	rprintf(reqInfo,"Content-MD5: %s%c%c", 
		reqInfo->outh_content_md5,CR,LF);
#endif /* CONTENT_MD5 */

    if(reqInfo->outh_www_auth[0])
	rprintf(reqInfo,"WWW-Authenticate: %s%c%c", 
		reqInfo->outh_www_auth,CR,LF);

    if (reqInfo->bNotifyDomainRestricted && reqInfo->bSatisfiedDomain)
	rprintf(reqInfo,"Extension: Domain-Restricted%c%c",CR,LF);

    keep_alive.bKeepAlive = keep_alive.bKeepAlive && 
			    (reqInfo->outh_content_length >= 0);
    if (keep_alive.bKeepAlive && (!keep_alive.nMaxRequests ||
				  keep_alive.nCurrRequests + 1 < 
				  keep_alive.nMaxRequests)) {
	keep_alive.bKeepAlive = 1;
	rprintf(reqInfo,
		"Connection: Keep-Alive%c%cKeep-Alive: max=%d, timeout=%d%c%c",
		CR,LF, keep_alive.nMaxRequests, keep_alive.nTimeOut,CR,LF);
    }
    if(reqInfo->outh_cgi)
        rprintf(reqInfo,"%s",reqInfo->outh_cgi);

    rprintf(reqInfo,"%c%c",CR,LF);

/* CLF doesn't include the headers, I don't think, so clear the information
 * on what has been sent so far (byte count wise)
 */
    reqInfo->bytes_sent = 0;
/*    rflush(reqInfo);   */
}