⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htwais.c

📁 www工具包. 这是W3C官方支持的www支撑库. 其中提供通用目的的客户端的WebAPI: complete HTTP/1.1 (with caching, pipelining, PUT, POS
💻 C
📖 第 1 页 / 共 3 页
字号:
/*        *z++ = *p++ - '0';	q = strchr(p , '=');	if (!q) return 0;*/	s = strchr(q, ';');	/* (Check only) */	if (!s) return 0;	/* Bad! No ';';	*/        sor = z;		/* Remember where the size field was */	z++;			/* Skip record size for now	*/	for(p=q+1; *p!=';' ; ) {	   if (*p == HEX_ESCAPE) {	        char c;		unsigned int b;		p++;	        c = *p++;		b =   HTAsciiHexToChar(c);		c = *p++;		if (!c) break;	/* Odd number of chars! */		*z++ = (b<<4) + HTAsciiHexToChar(c);	    } else {	        *z++ = *p++;	/* Record */	    }	}	*sor = (z-sor-1);	/* Fill in size -- not counting size itself */	p++;			/* After semicolon: start of next record */    }#endif /* OLD_CODE */#ifdef HTDEBUG    if (PROT_TRACE) {	char *p;	HTTRACE(PROT_TRACE, "WAIS........ id (%d bytes) is " _ (int)docid->size);	for(p=docid->bytes; p<docid->bytes+docid->size; p++) {	    if ((*p >= ' ') && (*p<= '~')) /* Assume ASCII! */		HTTRACE(PROT_TRACE, "%c" _ *p);	    else		HTTRACE(PROT_TRACE, "<%x>" _ (unsigned)*p);	}	HTTRACE(PROT_TRACE, "\n");    }#endif /* HTDEBUG */    return docid;		/* Ok */    } /* WAIS_from_WWW *//*	Send a plain text record to the client		output_text_record()**	--------------------------------------*/PRIVATE void output_text_record (    HTStream *			target,    WAISDocumentText *		record,    boolean			quote_string_quotes,    boolean                    binary){  long count;  if (binary) {    (*target->isa->put_block)(target,			      record->DocumentText->bytes,			      record->DocumentText->size);    return;  }  for(count = 0; count < record->DocumentText->size; count++){    long ch = (unsigned char)record->DocumentText->bytes[count];    if (ch == 27) {	/* What is this in for? Tim */	    /* then we have an escape code */	    /* if the next letter is '(' or ')', then ignore two letters */	    if('(' == record->DocumentText->bytes[count + 1] ||		')' == record->DocumentText->bytes[count + 1])	    count += 1;             /* it is a term marker */	    else count += 4;		/* it is a paragraph marker */    } else if (ch == '\n' || ch == '\r') {	    PUTC('\n');    } else if ((ch=='\t') || isprint(ch)){	    PUTC(ch);    }   }} /* output text record *//*	Format A Search response for the client		display_search_response**	---------------------------------------** modified from tracy shen's version in wutil.c** displays either a text record or a set of headlines.*/void display_search_response (HTStructured *		target,			      SearchResponseAPDU *	response,			      char *			database,			      char *	 		keywords){  WAISSearchResponse  *info;  long i, k;  char line[LINE_BUFFER_SIZE];	/* For building strings to display */    BOOL archie =  strstr(database, "archie")!=0;	/* Specical handling */    HTTRACE(PROT_TRACE, "WAIS........ Displaying search response\n");  sprintf(line,	  "Index %s contains the following %d item%s relevant to '%s'.\n",	  database,	  (int)(response->NumberOfRecordsReturned),	  response->NumberOfRecordsReturned ==1 ? "" : "s",	  keywords);  PUTS(line);  PUTS("The first figure for each entry is its relative score, ");  PUTS("the second the number of lines in the item.");  START(HTML_MENU);  if ( response->DatabaseDiagnosticRecords != 0 ) {    info = (WAISSearchResponse *)response->DatabaseDiagnosticRecords;    i =0;     if (info->Diagnostics != NULL)      HTshowDiags((HTStream*)target, info->Diagnostics);    if ( info->DocHeaders != 0 ) {      for (k=0; info->DocHeaders[k] != 0; k++ ) {	WAISDocumentHeader* head = info->DocHeaders[k];	char * headline = trim_junk(head->Headline);	any * docid = head->DocumentID;	char * docname;			/* printable version of docid */	i++;/*	Make a printable string out of the document id.*/	HTTRACE(PROT_TRACE, "HTWAIS:  %2ld: Score: %4ld, lines:%4ld '%s'\n" _ i _ 		    (long int)(info->DocHeaders[k]->Score) _ 		    (long int)(info->DocHeaders[k]->Lines) _ 		    headline);	START(HTML_LI);	sprintf(line, "%4ld  %4ld  ",	    head->Score,	    head->Lines);	PUTS(line);	if (archie) {	    char * www_name = WWW_from_archie(headline);	    if (www_name) {		HTStartAnchor(target, NULL, www_name);		PUTS(headline);				END(HTML_A);		HT_FREE(www_name);	    } else {		 PUTS(headline);		 PUTS(" (bad file name)");	    }	} else { /* Not archie */	    docname =  WWW_from_WAIS(docid);	    if (docname) {		char * dbname = HTEscape(database, URL_XPALPHAS);                char types_array[1000]; /* bad */                char *type_escaped;                types_array[0] = 0;                if (head->Types) {                    int i;                    for (i = 0; head->Types[i]; i++)                      {                        if (i)                          strcat (types_array, ",");                        type_escaped = HTEscape (head->Types[i], URL_XALPHAS);                        strcat (types_array, type_escaped);                        HT_FREE(type_escaped);                      }                    HTTRACE(PROT_TRACE, "WAIS........ Types_array `%s\'\n" _ 			       types_array);		} else {                    strcat (types_array, "TEXT");		}		sprintf(line, "%s/%s/%d/%s",                        dbname,                        types_array,                        (int)(head->DocumentLength),                        docname);#ifdef OLD_CODE		sprintf(line, "%s/%s/%d/%s",		/* W3 address */				    dbname,		    head->Types ? head->Types[0] : "TEXT",		    (int)(head->DocumentLength),		    docname);#endif /* OLD_CODE */		HTStartAnchor(target, NULL, ( (head->Types) 		      && (!strcmp(head->Types[0], "URL"))) ? 			      headline : line); /* NT, Sep 93 */		PUTS(headline);		END(HTML_A);		HT_FREE(dbname);		HT_FREE(docname);	    } else {		 PUTS("(bad doc id)");	    }	  }      } /* next document header */    } /* if there were any document headers */        if ( info->ShortHeaders != 0 ) {      k =0;      while (info->ShortHeaders[k] != 0 ) {	i++;	PUTS( "(Short Header record, can't display)");      }    }    if ( info->LongHeaders != 0 ) {      k =0;      while (info->LongHeaders[k] != 0) {	i++;	PUTS( "\nLong Header record, can't display\n");      }    }    if ( info->Text != 0 ) {      k =0;      while (info->Text[k] != 0) {	i++;	PUTS( "\nText record\n");	output_text_record((HTStream*)target, info->Text[k++], false, false);      }    }    if ( info->Headlines != 0 ) {      k =0;      while (info->Headlines[k] != 0) {	i++;	PUTS( "\nHeadline record, can't display\n");	/* dsply_headline_record( info->Headlines[k++]); */      }    }    if ( info->Codes != 0 ) {      k =0;      while (info->Codes[k] != 0) {	i++;	PUTS( "\nCode record, can't display\n");	/* dsply_code_record( info->Codes[k++]); */      }    }  }				/* Loop: display user info */  END(HTML_MENU);  PUTC('\n'); ;}/*	HTWAISCleanup**	-----------**      This function closes the connection and frees memory.**      Returns YES on OK, else NO*/PRIVATE int HTWAISCleanup (HTRequest *req, int status){ HTNet* net; HTStream* input; wais_info* theWAISinfo = NULL; if (req)   {    net = HTRequest_net(req);    input = HTRequest_inputStream(req);    /* Free stream with data TO network */    if (HTRequest_isDestination(req))      HTRequest_removeDestination(req);     else      if (input)	{	 if (status == HT_INTERRUPTED)	   (*input->isa->abort)(input, NULL);	  else	   (*input->isa->_free)(input);	 HTRequest_setInputStream(req, NULL);	}    if (net)      {       if ((theWAISinfo = (wais_info*)HTNet_context(net)))	 {	  theWAISinfo->state = HTWAIS_CLEANUP;	  if (theWAISinfo->connection)	    close_connection_to_server(theWAISinfo->connection);	  if (theWAISinfo->wais_database)	    HT_FREE(theWAISinfo->wais_database);	  if (theWAISinfo->request_message)	    s_free(theWAISinfo->request_message);	  if (theWAISinfo->response_message)	    s_free(theWAISinfo->response_message);	  HT_FREE(theWAISinfo->names);	  HT_FREE(theWAISinfo->basetitle);	  if (status < 0)	    {	     HTParentAnchor* anchor;	     char* unescaped = NULL;	     void* err_par;	     unsigned int err_par_length;	     if ((anchor = HTRequest_anchor(req)))   /* Be robust */	       {		char* arg;		if ((arg = HTAnchor_physical(anchor)))		  {		   StrAllocCopy(unescaped, arg);		   HTUnEscape(unescaped);		  }	       }	     if (unescaped)	       {		err_par = (void*)unescaped;		err_par_length = (unsigned int)(strlen(unescaped));	       }	      else	       {		err_par = (void*)"???";		err_par_length = 3;	       }	     HTRequest_addError(req, ERR_FATAL, NO, HTERR_INTERNAL,				err_par, err_par_length, "HTLoadWAIS");	     if (unescaped) HT_FREE(unescaped);	    }	  /* Free and remove our own context structure for wais */	  HT_FREE(theWAISinfo);	  HTNet_setContext(net, NULL);	 }       /* End ``if (theWAISinfo)'' */       /* Remove the request object */       HTNet_delete(net, status);      }    return YES;   }  else   return NO;}/*	Load Document from WAIS Server				HTLoadWAIS()**	------------------------------**** On entry,**	request		This is the request structure** On exit,**	returns		<0		Error has occured**			HT_LOADED	OK*/#define MAX_KEYWORDS_LENGTH 4000#define MAX_SERVER_LENGTH   1000#define MAX_DATABASE_LENGTH 1000#define MAX_SERVICE_LENGTH  1000PRIVATE int HTWAISEvent(SOCKET soc, void * pVoid, HTEventType type){ wais_info* theWAISinfo;  /* Specific protocol information */ HTNet* net;              /* Generic protocol information */ HTRequest* request; HTParentAnchor* anchor; const char * arg; HTStream* sink; HTFormat format_out;#if 0 static const char * error_header = "<h1>Access error</h1>\n<p>The following error occured in accesing a WAIS server:\n</p>\n";#endif char* key;			  /* pointer to keywords in URL */ long request_buffer_length;	/* how of the request is left */ SearchResponseAPDU* retrieval_response = 0; char keywords[MAX_KEYWORDS_LENGTH + 1]; char* server_name = NULL; char* service; char* docname = NULL; char* doctype = NULL; long document_length = -1; BOOL ok = NO; int status = HT_ERROR;#if 0 FILE* connection = 0; char* names;		/* Copy of arg to be hacked up */ char* basetitle = NULL; char* wais_database = NULL;    /* name of current database */ char*  www_database = NULL;    /* Same name escaped */ char*  request_message = NULL; /* arbitrary message limit */ char* response_message = NULL; /* arbitrary message limit */#endif    #if 0 extern FILE * connect_to_server();#endif if ((theWAISinfo = (wais_info*)pVoid))   /* Be robust */   {    if ((net = theWAISinfo->net) == NULL) return HT_ERROR;    if ((request = HTNet_request(net)) == NULL) return HT_ERROR;    if ((anchor = HTRequest_anchor(request)))      arg = HTAnchor_physical(anchor);     else      return HT_ERROR;    sink = HTRequest_outputStream(request);    format_out = HTRequest_outputFormat(request);   }  else   return HT_ERROR;     if (type == HTEvent_BEGIN)   {    theWAISinfo->state  = HTWAIS_BEGIN;    theWAISinfo->result = HT_ERROR;   }  else   if (type == HTEvent_CLOSE)     {     /* Interrupted */      char interrupted[] = "request interruption";      HTRequest_addError(request, ERR_FATAL, NO, HTERR_INTERRUPTED,			 (void*)interrupted, (unsigned int)strlen(interrupted),			 "HTLoadWAIS");      HTWAISCleanup(request, HT_INTERRUPTED);      return HT_OK;     }    else     if (type == HTEvent_END)       {	HTWAISCleanup(request, (theWAISinfo ? theWAISinfo->result : HT_ERROR));	return HT_OK;       } /*	Decipher and check syntax of WWW address: **	---------------------------------------- ** **	First we remove the "wais:" if it was spcified.  920110 */ if (!acceptable_inited) init_acceptable(); theWAISinfo->state = HTWAIS_PARSING_URL; HTTRACE(PROT_TRACE, "HTLoadWAIS.. Looking for \"%s\"\n" _ arg); theWAISinfo->names = HTParse(arg, "",			      PARSE_HOST | PARSE_PATH | PARSE_PUNCTUATION); key = strchr(theWAISinfo->names, '?'); if (key)   {    char* p;    *key++ = 0;	/* Split off keywords */    for (p=key; *p; p++) if (*p == '+') *p = ' ';    HTUnEscape(key);   } if (theWAISinfo->names[0] == '/')   {    server_name = theWAISinfo->names+1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -