📄 htline.c
字号:
/* HTLine.c** W3C COMMAND LINE TOOL**** (c) COPRIGHT MIT 1995.** Please first read the full copyright statement in the file COPYRIGH.** @(#) $Id: HTLine.c,v 1.55 1999/02/23 17:53:29 frystyk Exp $**** Authors:** HFN Henrik Frystyk Nielsen, (frystyk@w3.org)**** History:** Nov 24 95 First version*/#include "WWWLib.h" /* Global Library Include file */#include "WWWApp.h"#include "WWWMIME.h" /* MIME parser/generator */#include "WWWHTML.h" /* HTML parser/generator */#include "WWWNews.h" /* News access module */#include "WWWHTTP.h" /* HTTP access module */#include "WWWFTP.h"#include "WWWFile.h"#include "WWWGophe.h"#include "WWWStream.h"#include "WWWTrans.h"#include "WWWInit.h"#include "HTLine.h" /* Implemented here */#ifndef W3C_VERSION#define W3C_VERSION "unspecified"#endif#define APP_NAME "W3C-WebCon"#define APP_VERSION W3C_VERSION/* Default page for "-help" command line option */#define W3C_HELP "http://www.w3.org/ComLine/README"#define DEFAULT_OUTPUT_FILE "w3c.out"#define DEFAULT_RULE_FILE "w3c.conf"#define DEFAULT_LOG_FILE "w3c.log"#define MILLIES 1000#define DEFAULT_TIMEOUT 20 /* timeout in secs */#define DEFAULT_HOPS 0#define DEFAULT_FORMAT WWW_SOURCEtypedef enum _CLFlags { CL_FILTER = 0x1, CL_COUNT = 0x2, CL_QUIET = 0x4, CL_VALIDATE = 0x8, CL_END_VALIDATE = 0x10} CLFlags;#define SHOW_MSG (!(cl->flags & CL_QUIET))typedef struct _ComLine { HTRequest * request; HTParentAnchor * anchor; HTParentAnchor * dest; /* Destination for PUT etc. */ int timer; /* Timeout on socket */ char * cwd; /* Current dir URL */ char * rules; char * logfile; HTLog * log; char * outputfile; FILE * output; HTFormat format; /* Input format from console */ char * realm; /* For automated authentication */ char * user; char * password; CLFlags flags;} ComLine;HTChunk * post_result = NULL; /* ------------------------------------------------------------------------- */PRIVATE int printer (const char * fmt, va_list pArgs){ return (vfprintf(stdout, fmt, pArgs));}PRIVATE int tracer (const char * fmt, va_list pArgs){ return (vfprintf(stderr, fmt, pArgs));}/* Create a Command Line Object** ----------------------------*/PRIVATE ComLine * ComLine_new (void){ ComLine * me; if ((me = (ComLine *) HT_CALLOC(1, sizeof(ComLine))) == NULL) HT_OUTOFMEM("ComLine_new"); me->timer = DEFAULT_TIMEOUT*MILLIES; me->cwd = HTGetCurrentDirectoryURL(); me->output = OUTPUT; /* Bind the ConLine object together with the Request Object */ me->request = HTRequest_new(); HTRequest_setOutputFormat(me->request, DEFAULT_FORMAT); HTRequest_setContext (me->request, me); return me;}/* Delete a Command Line Object** ----------------------------*/PRIVATE BOOL ComLine_delete (ComLine * me){ if (me) { HTRequest_delete(me->request); if (me->log) HTLog_close(me->log); if (me->output && me->output != STDOUT) fclose(me->output); HT_FREE(me->cwd); HT_FREE(me); return YES; } return NO;}PRIVATE void Cleanup (ComLine * me, int status){ ComLine_delete(me); HTProfile_delete();#ifdef VMS exit(status ? status : 1);#else exit(status ? status : 0);#endif}PRIVATE void VersionInfo (const char * name){ HTPrint("\nW3C OpenSource Software"); HTPrint("\n-----------------------\n\n"); HTPrint("\tWebCon version %s\n", APP_VERSION); HTPrint("\tusing the W3C libwww library version %s.\n\n",HTLib_version()); HTPrint("\tTry \"%s -help\" for help\n\n", name ? name : APP_NAME); HTPrint("\tSee \"http://www.w3.org/ComLine/User/\" for user information\n"); HTPrint("\tSee \"http://www.w3.org/ComLine/\" for general information\n\n"); HTPrint("\tPlease send feedback to the <www-lib@w3.org> mailing list,\n"); HTPrint("\tsee \"http://www.w3.org/Library/#Forums\" for details\n\n");}/* terminate_handler** -----------------** This function is registered to handle the result of the request*/PRIVATE int terminate_handler (HTRequest * request, HTResponse * response, void * param, int status) { ComLine * cl = (ComLine *) HTRequest_context(request); if (status == HT_LOADED) { if (cl) { if (cl->flags & CL_COUNT) { HTPrint("Content Length found to be %ld\n", HTAnchor_length(cl->anchor)); } } } else { HTAlertCallback *cbf = HTAlert_find(HT_A_MESSAGE); if (cbf) (*cbf)(request, HT_A_MESSAGE, HT_MSG_NULL, NULL, HTRequest_error(request), NULL); } Cleanup(cl, (status/100 == 2) ? 0 : -1); return HT_OK;}PRIVATE BOOL PromptUsernameAndPassword (HTRequest * request, HTAlertOpcode op, int msgnum, const char * dfault, void * input, HTAlertPar * reply){ ComLine * cl = (ComLine *) HTRequest_context(request); char * realm = (char *) input; if (request && cl) { /* ** If we have a realm then check that it matches the realm ** that we got from the server. */ if (realm && cl->realm && !strcmp(cl->realm, realm)) { HTAlert_setReplyMessage(reply, cl->user ? cl->user : ""); HTAlert_setReplySecret(reply, cl->password ? cl->password : ""); return YES; } else { BOOL status = HTPrompt(request, op, msgnum, dfault, input, reply); return status ? HTPromptPassword(request, op, HT_MSG_PW, dfault, input, reply) : NO; } } return NO;}PRIVATE BOOL ParseCredentials (ComLine * cl, char * credentials){ if (cl && credentials) { char * start = credentials; char * end = credentials; /* Make sure we don't get inconsistent sets of information */ cl->realm = NULL; cl->user = NULL; cl->password = NULL; /* Find the username */ while (*end && *end!=':') end++; if (!*end) return NO; *end++ = '\0'; cl->user = start; start = end; /* Find the password */ while (*end && *end!='@') end++; if (!*end) return NO; *end++ = '\0'; cl->password = start; start = end; /* Find the realm */ cl->realm = start; } return YES;}/* ------------------------------------------------------------------------- *//* MAIN PROGRAM *//* ------------------------------------------------------------------------- */int main (int argc, char ** argv){ int status = 0; int arg; int tokencount = 0; BOOL formdata = NO; HTChunk * keywords = NULL; /* From command line */ HTAssocList*formfields = NULL; HTMethod method = METHOD_GET; /* Default value */ ComLine * cl = ComLine_new(); BOOL cache = NO; /* Use persistent cache */ BOOL flush = NO; /* flush the persistent cache */ char * cache_root = NULL; /* Starts Mac GUSI socket library */#ifdef GUSI GUSISetup(GUSIwithSIOUXSockets); GUSISetup(GUSIwithInternetSockets);#endif#ifdef __MWERKS__ /* STR */ InitGraf((Ptr) &qd.thePort); InitFonts(); InitWindows(); InitMenus(); TEInit(); InitDialogs(nil); InitCursor(); SIOUXSettings.asktosaveonclose = false; argc=ccommand(&argv);#endif /* Initiate W3C Reference Library with a client profile */ HTProfile_newNoCacheClient(APP_NAME, APP_VERSION); /* Need our own trace and print functions */ HTPrint_setCallback(printer); HTTrace_setCallback(tracer); /* ** Delete the default Username/password handler so that we can handle ** parameters handed to us from the command line. The default is set ** by the profile. */ HTAlert_deleteOpcode(HT_A_USER_PW); HTAlert_add(PromptUsernameAndPassword, HT_A_USER_PW); /* ** Add default content decoder. We insert a through line as it doesn't ** matter that we get an encoding that we don't know. */ HTFormat_addCoding("*", HTIdentityCoding, HTIdentityCoding, 0.3); /* Scan command Line for parameters */ for (arg=1; arg<argc; arg++) { if (*argv[arg] == '-') { /* - alone => filter */ if (argv[arg][1] == '\0') { cl->flags |= CL_FILTER; /* -? or -help: show the command line help page */ } else if (!strcmp(argv[arg],"-?") || !strcmp(argv[arg],"-help")) { cl->anchor = (HTParentAnchor *) HTAnchor_findAddress(W3C_HELP); tokencount = 1; /* non-interactive */ } else if (!strcmp(argv[arg], "-n")) { HTAlert_setInteractive(NO); /* Treat the keywords as form data with a <name> "=" <value> */ } else if (!strcmp(argv[arg], "-form")) { formdata = YES; /* from -- Initial represntation (only with filter) */ } else if (!strcmp(argv[arg], "-from")) { cl->format = (arg+1 < argc && *argv[arg+1] != '-') ? HTAtom_for(argv[++arg]) : WWW_HTML;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -