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

📄 htvms_waisprot.c

📁 用于linux和其他unix下面的
💻 C
📖 第 1 页 / 共 5 页
字号:
/*							HTVMS_WAISProt.c****	Adaptation for Lynx by F.Macrides (macrides@sci.wfeb.edu)****	31-May-1994 FM	Initial version.****----------------------------------------------------------------------*//***	Routines originally from WProt.c -- FM****----------------------------------------------------------------------*//* WIDE AREA INFORMATION SERVER SOFTWARE:   No guarantees or restrictions.  See the readme file for the full standard   disclaimer.	     3.26.90	Harry Morris, morris@think.com   3.30.90  Harry Morris    -	removed chunk code from WAISSearchAPDU,   -	added makeWAISQueryType1Query() and readWAISType1Query() which replace   makeWAISQueryTerms() and makeWAISQueryDocs().   4.11.90  HWM - generalized conditional includes (see c-dialect.h)   - renamed makeWAISType1Query() to makeWAISTextQuery()   renamed readWAISType1Query() to readWAISTextQuery()   5.29.90  TS - fixed bug in makeWAISQueryDocs   added CSTFreeWAISFoo functions*/#define _C_WAIS_protocol_/*	This file implements the Z39.50 extensions required for WAIS */#include <HTUtils.h>#include <HTVMS_WaisUI.h>#include <HTVMS_WaisProt.h>#include <LYLeaks.h>/* very rough estimates of the size of an object */#define DefWAISInitResponseSize		(size_t)200#define DefWAISSearchSize			(size_t)3000#define DefWAISSearchResponseSize	(size_t)6000#define DefWAISPresentSize			(size_t)1000#define DefWAISPresentResponseSize	(size_t)6000#define DefWAISDocHeaderSize		(size_t)500#define DefWAISShortHeaderSize		(size_t)200#define DefWAISLongHeaderSize		(size_t)800#define DefWAISDocTextSize			(size_t)6000#define DefWAISDocHeadlineSize		(size_t)500#define DefWAISDocCodeSize			(size_t)500#define RESERVE_SPACE_FOR_WAIS_HEADER(len)	\     if (*len > 0)				\     	*len -= header_len;/*----------------------------------------------------------------------*/static unsigned long userInfoTagSize PARAMS((data_tag tag,					  unsigned long length));static unsigned longuserInfoTagSize(tag,length)data_tag tag;unsigned long length;/* return the number of bytes required to write the user info tag and   length  */{  unsigned long size;  /* calculate bytes required to represent tag.  max tag is 16K */  size = writtenCompressedIntSize(tag);  size += writtenCompressedIntSize(length);        return(size);}   /*----------------------------------------------------------------------*/static char* writeUserInfoHeader PARAMS((data_tag tag,long infoSize,					      long estHeaderSize,char* buffer,				      long* len));static char*writeUserInfoHeader(tag,infoSize,estHeaderSize,buffer,len)data_tag tag;long infoSize;long estHeaderSize;char* buffer;long* len;/* write the tag and size, making sure the info fits.  return the true end   of the info (after adjustment) note that the argument infoSize includes   estHeaderSize.  Note that the argument len is the number of bytes remaining   in the buffer.  Since we write the tag and size at the begining of the   buffer (in space that we reserved) we don't want to pass len the calls which   do that writing.  */{  long dummyLen = 100;		/* plenty of space for a tag and size */  char* buf = buffer;  long realSize = infoSize - estHeaderSize;  long realHeaderSize = userInfoTagSize(tag,realSize);  if (buffer == NULL || *len == 0)    return(NULL);    /* write the tag */  buf = writeTag(tag,buf,&dummyLen);    /* see if the if the header size was correct. if not,     we have to shift the info to fit the real header size */  if (estHeaderSize != realHeaderSize)    {				/* make sure there is enough space */      CHECK_FOR_SPACE_LEFT(realHeaderSize - estHeaderSize,len);      memmove(buffer + realHeaderSize,buffer + estHeaderSize,(size_t)(realSize));    }     /* write the size */  writeCompressedInteger(realSize,buf,&dummyLen);    /* return the true end of buffer */  return(buffer + realHeaderSize + realSize);}/*----------------------------------------------------------------------*/static char* readUserInfoHeader PARAMS((data_tag* tag,unsigned long* num,				     char* buffer));static char*readUserInfoHeader(tag,num,buffer)data_tag* tag;unsigned long* num;char* buffer;/* read the tag and size */{  char* buf = buffer;  buf = readTag(tag,buf);  buf = readCompressedInteger(num,buf);  return(buf); }/*----------------------------------------------------------------------*/WAISInitResponse* makeWAISInitResponse(chunkCode,		     chunkIDLen,		     chunkMarker,		     highlightMarker,		     deHighlightMarker,		     newLineChars)long chunkCode;long chunkIDLen;char* chunkMarker;char* highlightMarker;char* deHighlightMarker;char* newLineChars;/* create a WAIS init response object */{  WAISInitResponse* init = (WAISInitResponse*)s_malloc((size_t)sizeof(WAISInitResponse));  init->ChunkCode = chunkCode;	/* note: none are copied! */  init->ChunkIDLength = chunkIDLen;  init->ChunkMarker = chunkMarker;  init->HighlightMarker = highlightMarker;  init->DeHighlightMarker = deHighlightMarker;  init->NewlineCharacters = newLineChars;    return(init);}/*----------------------------------------------------------------------*/void freeWAISInitResponse(init)WAISInitResponse* init;/* free an object made with makeWAISInitResponse */{  s_free(init->ChunkMarker);  s_free(init->HighlightMarker);  s_free(init->DeHighlightMarker);  s_free(init->NewlineCharacters);  s_free(init);}/*----------------------------------------------------------------------*/char*writeInitResponseInfo(init,buffer,len)InitResponseAPDU* init;char* buffer;long* len;/* write an init response object */{  unsigned long header_len = userInfoTagSize(DT_UserInformationLength,					     DefWAISInitResponseSize);  char* buf = buffer + header_len;  WAISInitResponse* info = (WAISInitResponse*)init->UserInformationField;  unsigned long size;    RESERVE_SPACE_FOR_WAIS_HEADER(len);      buf = writeNum(info->ChunkCode,DT_ChunkCode,buf,len);  buf = writeNum(info->ChunkIDLength,DT_ChunkIDLength,buf,len);  buf = writeString(info->ChunkMarker,DT_ChunkMarker,buf,len);  buf = writeString(info->HighlightMarker,DT_HighlightMarker,buf,len);  buf = writeString(info->DeHighlightMarker,DT_DeHighlightMarker,buf,len);  buf = writeString(info->NewlineCharacters,DT_NewlineCharacters,buf,len);    /* now write the header and size */  size = buf - buffer;   buf = writeUserInfoHeader(DT_UserInformationLength,size,header_len,buffer,len);    return(buf);}/*----------------------------------------------------------------------*/char*readInitResponseInfo(info,buffer)void** info;char* buffer;/* read an init response object */{  char* buf = buffer;  unsigned long size;   unsigned long headerSize;  long chunkCode,chunkIDLen;  data_tag tag1;  char* chunkMarker = NULL;  char* highlightMarker = NULL;  char* deHighlightMarker = NULL;  char* newLineChars = NULL;    chunkCode = chunkIDLen = UNUSED;    buf = readUserInfoHeader(&tag1,&size,buf);  headerSize = buf - buffer;      while (buf < (buffer + size + headerSize))    { data_tag tag = peekTag(buf);      switch (tag)	{ case DT_ChunkCode:	    buf = readNum(&chunkCode,buf);	    break;	  case DT_ChunkIDLength:	    buf = readNum(&chunkIDLen,buf);	    break;	  case DT_ChunkMarker:	    buf = readString(&chunkMarker,buf);	    break;	  case DT_HighlightMarker:	    buf = readString(&highlightMarker,buf);	    break;	  case DT_DeHighlightMarker:	    buf = readString(&deHighlightMarker,buf);	    break;	  case DT_NewlineCharacters:	    buf = readString(&newLineChars,buf);	    break;	  default:	    s_free(highlightMarker);	    s_free(deHighlightMarker);	    s_free(newLineChars);	    REPORT_READ_ERROR(buf);	    break;	  }    }  	    *info = (void *)makeWAISInitResponse(chunkCode,chunkIDLen,chunkMarker,			       highlightMarker,deHighlightMarker,			       newLineChars);  return(buf);}/*----------------------------------------------------------------------*/WAISSearch* makeWAISSearch(seedWords,	       docs,	       textList,	       dateFactor,	       beginDateRange,	       endDateRange,	       maxDocsRetrieved)char* seedWords;DocObj** docs;char** textList;long dateFactor;char* beginDateRange;char* endDateRange;long maxDocsRetrieved;/* create a type 3 query object */{   WAISSearch* query = (WAISSearch*)s_malloc((size_t)sizeof(WAISSearch));  query->SeedWords = seedWords;	/* not copied! */  query->Docs = docs;		/* not copied! */  query->TextList = textList;	/* not copied! */  query->DateFactor = dateFactor;  query->BeginDateRange = beginDateRange;  query->EndDateRange = endDateRange;  query->MaxDocumentsRetrieved = maxDocsRetrieved;    return(query);}/*----------------------------------------------------------------------*/void freeWAISSearch(query)WAISSearch* query;/* destroy an object made with makeWAISSearch() */{  void* ptr = NULL;  long i;    s_free(query->SeedWords);    if (query->Docs != NULL)    for (i = 0,ptr = (void *)query->Docs[i]; ptr != NULL; ptr = (void *)query->Docs[++i])      freeDocObj((DocObj*)ptr);  s_free(query->Docs);     if (query->TextList != NULL)	/* XXX revisit when textlist is fully defined */    for (i = 0,ptr = (void *)query->TextList[i]; ptr != NULL; ptr = (void *)query->TextList[++i])      s_free(ptr);  s_free(query->TextList);  s_free(query->BeginDateRange);  s_free(query->EndDateRange);  s_free(query);}/*----------------------------------------------------------------------*/DocObj* makeDocObjUsingWholeDocument(docID,type)any* docID;char* type;/* construct a document object using byte chunks - only for use by   servers */{  DocObj* doc = (DocObj*)s_malloc((size_t)sizeof(DocObj));  doc->DocumentID = docID;		/* not copied! */  doc->Type = type;		/* not copied! */  doc->ChunkCode = CT_document;  return(doc);}/*----------------------------------------------------------------------*/DocObj* makeDocObjUsingLines(docID,type,start,end)any* docID;char* type;long start;long end;/* construct a document object using line chunks - only for use by   servers */{  DocObj* doc = (DocObj*)s_malloc((size_t)sizeof(DocObj));  doc->ChunkCode = CT_line;  doc->DocumentID = docID;		/* not copied */  doc->Type = type;		/* not copied! */  doc->ChunkStart.Pos = start;  doc->ChunkEnd.Pos = end;  return(doc);}/*----------------------------------------------------------------------*/DocObj* makeDocObjUsingBytes(docID,type,start,end)any* docID;char* type;long start;long end;/* construct a document object using byte chunks - only for use by   servers */{  DocObj* doc = (DocObj*)s_malloc((size_t)sizeof(DocObj));  doc->ChunkCode = CT_byte;  doc->DocumentID = docID;		/* not copied */  doc->Type = type;		/* not copied! */  doc->ChunkStart.Pos = start;  doc->ChunkEnd.Pos = end;  return(doc);}/*----------------------------------------------------------------------*/DocObj* makeDocObjUsingParagraphs(docID,type,start,end)any* docID;char* type;any* start;any* end;/* construct a document object using byte chunks - only for use by   servers */{  DocObj* doc = (DocObj*)s_malloc((size_t)sizeof(DocObj));  doc->ChunkCode = CT_paragraph;  doc->DocumentID = docID;		/* not copied */  doc->Type = type;  doc->ChunkStart.ID = start;   doc->ChunkEnd.ID = end;   return(doc);}/*----------------------------------------------------------------------*/voidfreeDocObj(doc)DocObj* doc;/* free a docObj */{  freeAny(doc->DocumentID);  s_free(doc->Type);  if (doc->ChunkCode == CT_paragraph)    { freeAny(doc->ChunkStart.ID);      freeAny(doc->ChunkEnd.ID);    }  s_free(doc);}/*----------------------------------------------------------------------*/static char* writeDocObj PARAMS((DocObj* doc,char* buffer,long* len));static char*writeDocObj(doc,buffer,len)DocObj* doc;char* buffer;long* len;/* write as little as we can about the doc obj */{  char* buf = buffer;    /* we alwasy have to write the id, but its tag depends on if its a chunk */  if (doc->ChunkCode == CT_document)    buf = writeAny(doc->DocumentID,DT_DocumentID,buf,len);  else    buf = writeAny(doc->DocumentID,DT_DocumentIDChunk,buf,len);    if (doc->Type != NULL)    buf = writeString(doc->Type,DT_TYPE,buf,len);    switch (doc->ChunkCode)

⌨️ 快捷键说明

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