©2004 by Marc J. Rochkind. All rights reserved. Portions marked "Open Source" may be copied under license.

 

Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

c8/minibr.c

Go to the documentation of this file.
00001 /*
00002     Mini Web Browser
00003     AUP2, Sec. 8.04.3
00004 
00005     Copyright 2003 by Marc J. Rochkind. All rights reserved.
00006     May be copied only for purposes and under conditions described
00007     on the Web page www.basepath.com/aup/copyright.htm.
00008 
00009     The Example Files are provided "as is," without any warranty;
00010     without even the implied warranty of merchantability or fitness
00011     for a particular purpose. The author and his publisher are not
00012     responsible for any damages, direct or incidental, resulting
00013     from the use or non-use of these Example Files.
00014 
00015     The Example Files may contain defects, and some contain deliberate
00016     coding mistakes that were included for educational reasons.
00017     You are responsible for determining if and how the Example Files
00018     are to be used.
00019 
00020 */
00021 #include "defs.h"
00022 #include "ssi.h"
00023 
00024 /*[pgm]*/
00025 int main(void)
00026 {
00027     char url[100], s[500], *path = "", *p;
00028     SSI *ssip;
00029     int fd;
00030     ssize_t nread;
00031 
00032     while (true) {
00033         printf("URL: ");
00034         if (fgets(url, sizeof(url), stdin) == NULL)
00035             break;
00036         if ((p = strrchr(url, '\n')) != NULL)
00037             *p = '\0';
00038         if ((p = strchr(url, '/')) != NULL) {
00039             path = p + 1;
00040             *p = '\0';
00041         }
00042         snprintf(s, sizeof(s), "//%s:80", url);
00043         ec_null( ssip = ssi_open(s, false) )
00044         ec_neg1( fd = ssi_get_server_fd(ssip) )
00045         snprintf(s, sizeof(s), "GET /%s HTTP/1.0\r\n\r\n", path);
00046         ec_neg1( writeall(fd, s, strlen(s)) )
00047         while (true) {
00048             switch (nread = read(fd, s, sizeof(s))) {
00049             case 0:
00050                 printf("EOF\n");
00051                 break;
00052             case -1:
00053                 EC_FAIL
00054             default:
00055                 ec_neg1( writeall(STDOUT_FILENO, s, nread) )
00056                 continue;
00057             }
00058             break;
00059         }
00060         ec_false( ssi_close(ssip) )
00061     }
00062     ec_false( !ferror(stdin) )
00063     exit(EXIT_SUCCESS);
00064 
00065 EC_CLEANUP_BGN
00066     exit(EXIT_FAILURE);
00067 EC_CLEANUP_END
00068 }
00069 /*[]*/

Generated on Fri Apr 23 10:57:01 2004 for AUP2 Example Source by doxygen 1.3.1