]>
git.saurik.com Git - apt.git/blob - methods/file.cc
fc42c296833c154798641ace3ce701eec7d0b201
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: file.cc,v 1.3 1998/10/23 00:50:02 jgg Exp $
4 /* ######################################################################
6 File URI method for APT
8 This simply checks that the file specified exists, if so the relevent
9 information is returned. If a .gz filename is specified then the file
10 name with .gz removed will also be checked and information about it
11 will be returned in Alt-*
13 ##################################################################### */
15 // Include Files /*{{{*/
16 #include <apt-pkg/fileutl.h>
24 // Fail - Generate a failure message /*{{{*/
25 // ---------------------------------------------------------------------
29 printf("400 URI Failure\n"
31 "Message: File does not exist\n\n",URI
.c_str());
38 SetNonBlock(STDIN_FILENO
,true);
40 printf("100 Capabilities\n"
42 "Pipeline: true\n\n");
44 vector
<string
> Messages
;
47 if (WaitFd(STDIN_FILENO
) == false ||
48 ReadMessages(STDIN_FILENO
,Messages
) == false)
51 while (Messages
.empty() == false)
53 string Message
= Messages
.front();
54 Messages
.erase(Messages
.begin());
56 // Fetch the message number
58 int Number
= strtol(Message
.c_str(),&End
,10);
59 if (End
== Message
.c_str())
61 cerr
<< "Malformed message!" << endl
;
65 // We only understand 600 URI Fetch messages
70 string URI
= LookupTag(Message
,"URI");
73 string::size_type Pos
= URI
.find(':');
74 if (Pos
== string::npos
)
79 string File
= string(URI
,Pos
+1);
81 // Grab the modification time
83 string LTime
= LookupTag(Message
,"Last-Modified");
84 if (LTime
.empty() == false && StrToTime(LTime
,LastMod
) == false)
87 // Start the reply message
88 string Result
= "201 URI Done";
89 Result
+= "\nURI: " + URI
;
91 // See if the file exists
94 if (stat(File
.c_str(),&Buf
) == 0)
97 sprintf(S
,"\nSize: %ld",Buf
.st_size
);
99 Result
+= "\nFilename: " + File
;
101 Result
+= "\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
102 if (LTime
.empty() == false && LastMod
== Buf
.st_mtime
)
103 Result
+= "\nIMS-Hit: true";
108 // See if we can compute a file without a .gz exentsion
109 Pos
= File
.rfind(".gz");
110 if (Pos
+ 3 == File
.length())
112 File
= string(File
,0,Pos
);
113 if (stat(File
.c_str(),&Buf
) == 0)
116 sprintf(S
,"\nAlt-Size: %ld",Buf
.st_size
);
118 Result
+= "\nAlt-Filename: " + File
;
120 Result
+= "\nAlt-Last-Modified: " + TimeRFC1123(Buf
.st_mtime
);
121 if (LTime
.empty() == false && LastMod
== Buf
.st_mtime
)
122 Result
+= "\nAlt-IMS-Hit: true";
128 // Did we find something?
137 if (write(STDOUT_FILENO
,Result
.begin(),Result
.length()) !=
138 (signed)Result
.length())