Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / apps / JAWS / clients / Caching / http_client.cpp
blob2a174f72a2f23d5d26c912a2fb1acc4fca7d0c1f
2 //=============================================================================
3 /**
4 * @file http_client.cpp
6 * This is a very simple client. It accepts URLs from a prompt, and
7 * will try to fetch them. Also accepts shell escapes.
9 * @author James Hu
11 //=============================================================================
14 #include "ace/OS_NS_stdio.h"
15 #include "ace/OS_NS_string.h"
16 #include "ace/OS_NS_ctype.h"
17 #include "http_handler.h"
19 int
20 ACE_TMAIN (int, ACE_TCHAR *[])
22 // Present a command line.
23 // * Accept a URL.
24 // Pass it to the HTTP_Connector.
25 // Connect.
26 // Report status.
27 // * Accept shell escape character.
29 char buf[BUFSIZ];
31 ACE_DEBUG ((LM_DEBUG, "* "));
33 while (ACE_OS::fgets (buf, sizeof (buf), stdin) != 0)
35 char *s = buf;
37 // get rid of trailing '\n'
38 int len = ACE_OS::strlen (s);
40 if (len > 0 && s[len - 1] == '\n')
41 s[len - 1] = 0;
43 while (ACE_OS::ace_isspace (*s))
44 s++;
46 if (*s == '!')
49 s++;
50 while (ACE_OS::ace_isspace (*s));
52 // Shell command.
53 if (ACE_OS::system (ACE_TEXT_CHAR_TO_TCHAR (s)) == -1)
54 ACE_ERROR ((LM_ERROR, ACE_TEXT (" ! Error executing: %C\n"), s));
56 else if (ACE_OS::strncmp (s, "http://", 7) == 0)
58 // URL
59 HTTP_Connector connector;
60 connector.connect (s);
62 else
63 ACE_ERROR ((LM_ERROR, ACE_TEXT (" ? I don't understand: %C\n"), s));
65 ACE_ERROR ((LM_ERROR, ACE_TEXT ("* ")));
68 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nBye!\n")));
70 return 0;