~ubuntu-branches/ubuntu/precise/ncbi-tools6/precise

« back to all changes in this revision

Viewing changes to network/wwwblast/Src/viewgif.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <signal.h>
 
2
#include <fcntl.h>
 
3
#include <stdio.h>
 
4
 
 
5
static void SigAlrmHandler(int);
 
6
static void SigTermHandler(int);
 
7
 
 
8
static char FileName[128];
 
9
 
 
10
main(void) 
 
11
{
 
12
    FILE *pp;
 
13
    char tmp_buff[1024];
 
14
    char *PidFile;
 
15
 
 
16
    int  bytes;
 
17
    char *ContentGif  =  "Content-type: image/gif\r\n\r\n";
 
18
    struct sigaction sa;
 
19
    sigset_t sigset;
 
20
 
 
21
    sigfillset(&sigset);
 
22
    sa.sa_mask = sigset;
 
23
 
 
24
    sa.sa_flags = SA_RESETHAND | SA_RESTART;
 
25
    sa.sa_handler = SigAlrmHandler;
 
26
    sigaction(SIGALRM, &sa, NULL);
 
27
 
 
28
    sa.sa_handler = SigTermHandler;
 
29
    sigaction(SIGTERM, &sa, NULL);
 
30
    sigaction(SIGPIPE, &sa, NULL);
 
31
    
 
32
    PidFile = (char *) getenv("QUERY_STRING"); 
 
33
    
 
34
    sprintf(FileName, "TmpGifs/%s", PidFile);
 
35
    
 
36
    if((pp = fopen(FileName, "r")) == NULL) {
 
37
 
 
38
        /* Just do nothing */
 
39
        sprintf(tmp_buff, "HTTP/1.0 204 Not Modified\n");
 
40
        write(1, tmp_buff, strlen(tmp_buff));
 
41
        sprintf(tmp_buff, "Server: %s\n", (char *) getenv("SERVER_SOFTWARE"));
 
42
        write(1, tmp_buff, strlen(tmp_buff));
 
43
        sprintf(tmp_buff, "MIME-Version: 1.0\n");
 
44
        write(1, tmp_buff, strlen(tmp_buff));
 
45
        write(1, ContentGif, strlen(ContentGif)); 
 
46
    } else {
 
47
        sprintf(tmp_buff, "HTTP/1.0 200 OK\r\n");
 
48
        write(1, tmp_buff, strlen(tmp_buff));
 
49
        sprintf(tmp_buff, "Server: %s\n", (char *) getenv("SERVER_SOFTWARE"));
 
50
        write(1, tmp_buff, strlen(tmp_buff));
 
51
        sprintf(tmp_buff, "MIME-Version: 1.0\r\n");
 
52
        write(1, tmp_buff, strlen(tmp_buff));
 
53
        write(1, ContentGif, strlen(ContentGif)); 
 
54
        
 
55
        while ((bytes =fread(tmp_buff, 1, 256, pp)) >0)
 
56
            write(1, tmp_buff, bytes); 
 
57
    }
 
58
    remove(FileName); 
 
59
    return 0;
 
60
}
 
61
static void SigAlrmHandler(int id)
 
62
{
 
63
    
 
64
    char tmp_buff[1024];
 
65
    char *ContentGif  =  "Content-type: image/gif\r\n\r\n";
 
66
    
 
67
    sprintf(tmp_buff, "HTTP/1.0 204 Not Modified\n");
 
68
    write(1, tmp_buff, strlen(tmp_buff));
 
69
    sprintf(tmp_buff, "Server: %s\n", (char *) getenv("SERVER_SOFTWARE"));
 
70
    write(1, tmp_buff, strlen(tmp_buff));
 
71
    sprintf(tmp_buff, "MIME-Version: 1.0\n");
 
72
    write(1, tmp_buff, strlen(tmp_buff));
 
73
    write(1, ContentGif, strlen(ContentGif)); 
 
74
    remove(FileName); 
 
75
    exit(1);   
 
76
}
 
77
 
 
78
static void SigTermHandler(int id)
 
79
{
 
80
    remove(FileName); 
 
81
    exit(1);
 
82
}
 
83
 
 
84
 
 
85
 
 
86
 
 
87
 
 
88
 
 
89
 
 
90
 
 
91
 
 
92
 
 
93
 
 
94
 
 
95
 
 
96
 
 
97