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

📄 htvms_waisui.c

📁 用于linux和其他unix下面的
💻 C
📖 第 1 页 / 共 4 页
字号:
/*							HTVMS_WAISUI.c****	Adaptation for Lynx by F.Macrides (macrides@sci.wfeb.edu)****	30-May-1994 FM	Initial version.****----------------------------------------------------------------------*//***	Routines originally from UI.c -- FM****----------------------------------------------------------------------*//* WIDE AREA INFORMATION SERVER SOFTWARE:   No guarantees or restrictions.  See the readme file for the full standard   disclaimer.   Brewster@think.com*//* * this is a simple ui toolkit for building other ui's on top. * -brewster * * top level functions: *   generate_search_apdu *   generate_retrieval_apdu *   interpret_message * *//* to do: *   generate multiple queries for long documents. *     this will crash if the file being retrieved is larger than 100k. *   do log_write() * */#include <HTUtils.h>#include <HTVMS_WaisUI.h>#include <HTVMS_WaisProt.h>#include <HTTCP.h>#undef MAXINT	/* we don't need it here, and www_tcp.h may conflict */#include <math.h>#include <LYexit.h>#include <LYLeaks.h>voidlog_write(char *s GCC_UNUSED){    return;}/*----------------------------------------------------------------------*//* returns a pointer in the buffer of the first free byte.   if it overflows, then NULL is returned */char *generate_search_apdu(char* buff,     /* buffer to hold the apdu */long *buff_len,    /* length of the buffer changed to reflect new data written */char *seed_words,    /* string of the seed words */char *database_name,DocObj** docobjs,long maxDocsRetrieved){  /* local variables */  SearchAPDU *search3;  char  *end_ptr;  static char *database_names[2] = {"", 0};  any refID;  WAISSearch *query;  refID.size = 1;  refID.bytes = "3";  database_names[0] = database_name;  query = makeWAISSearch(seed_words,                         docobjs, /* DocObjsPtr */                         0,                         1,     /* DateFactor */                         0,     /* BeginDateRange */                         0,     /* EndDateRange */                         maxDocsRetrieved                         );  search3 = makeSearchAPDU(30,			   5000, /* should be large */			   30,                           1,	/* replace indicator */                           "",	/* result set name */                           database_names, /* database name */                           QT_RelevanceFeedbackQuery, /* query_type */                           0,   /* element name */                           NULL, /* reference ID */                           query);  end_ptr = writeSearchAPDU(search3, buff, buff_len);  CSTFreeWAISSearch(query);  freeSearchAPDU(search3);  return(end_ptr);}/*----------------------------------------------------------------------*//* returns a pointer into the buffer of the next free byte.   if it overflowed, then NULL is returned */char *generate_retrieval_apdu(char *buff,long *buff_len,    /* length of the buffer changed to reflect new data written */any *docID,long chunk_type,long start,long end,char *type,char *database_name){  SearchAPDU *search;  char  *end_ptr;  static char *database_names[2];  static char *element_names[3];  any refID;  DocObj *DocObjs[2];  any *query;			/* changed from char* by brewster */  if(NULL == type)    type = s_strdup("TEXT");  database_names[0] = database_name;  database_names[1] = NULL;  element_names[0] = " ";  element_names[1] = ES_DocumentText;  element_names[2] = NULL;  refID.size = 1;  refID.bytes = "3";  switch(chunk_type){  case CT_line:    DocObjs[0] = makeDocObjUsingLines(docID, type, start, end);    break;  case CT_byte:    DocObjs[0] = makeDocObjUsingBytes(docID, type, start, end);    break;  }  DocObjs[1] = NULL;  query = makeWAISTextQuery(DocObjs);  search = makeSearchAPDU( 10, 16, 15,			  1,	/* replace indicator */			  "FOO", /* result set name */			  database_names, /* database name */			  QT_TextRetrievalQuery, /* query_type */			  element_names, /* element name */			  &refID, /* reference ID */			  query);  end_ptr = writeSearchAPDU(search, buff, buff_len);  CSTFreeWAISTextQuery(query);  freeSearchAPDU(search);  return(end_ptr);}/*----------------------------------------------------------------------*//* this is a safe version of unix 'read' it does all the checking * and looping necessary * to those trying to modify the transport code to use non-UNIX streams: *  This is the function to modify! */PRIVATE long read_from_stream(int d, char *buf, long nbytes){  long didRead;  long toRead = nbytes;  long totalRead = 0;		/* paranoia */  while (toRead > 0){    didRead = NETREAD (d, buf, (int)toRead);    if(didRead == HT_INTERRUPTED)      return(HT_INTERRUPTED);    if(didRead == -1)		/* error*/      return(-1);    if(didRead == 0)		/* eof */      return(-2);		/* maybe this should return 0? */    toRead -= didRead;    buf += didRead;    totalRead += didRead;  }  if(totalRead != nbytes)	/* we overread for some reason */    return(- totalRead);	/* bad news */  return(totalRead);}/*----------------------------------------------------------------------*//* returns the length of the response, 0 if an error */PRIVATE longtransport_message(	long connection,	char *request_message,	long request_length,	char *response_message,	long response_buffer_length){  WAISMessage header;  long response_length;  int rv;  /* Write out message.  Read back header.  Figure out response length. */  if( request_length + HEADER_LENGTH !=      NETWRITE(connection,request_message,		  (int)( request_length +HEADER_LENGTH)) )    return 0;  /* read for the first '0' */  while(1){    rv = read_from_stream(connection, response_message, 1);    if (rv == HT_INTERRUPTED)      return HT_INTERRUPTED;    if (rv < 0)      return 0;    if('0' == response_message[0])      break;  }  rv = read_from_stream(connection, response_message + 1, HEADER_LENGTH -1);  if (rv == HT_INTERRUPTED)    return HT_INTERRUPTED;  if (rv < 0)    return 0;  readWAISPacketHeader(response_message, &header);  {    char length_array[11];    strncpy(length_array, header.msg_len, 10);    length_array[10] = '\0';    response_length = atol(length_array);    /*      if(verbose){      printf("WAIS header: '%s' length_array: '%s'\n",      response_message, length_array);      }      */    if(response_length > response_buffer_length){      /* we got a message that is too long, therefore empty the message out,	 and return 0 */      long i;      for(i = 0; i < response_length; i++){	rv = read_from_stream(connection,			      response_message + HEADER_LENGTH,			      1);	if (rv == HT_INTERRUPTED)	  return HT_INTERRUPTED;	if (rv < 0)	  return 0;      }      return(0);    }  }  rv = read_from_stream(connection,			response_message + HEADER_LENGTH,			response_length);  if (rv == HT_INTERRUPTED)    return HT_INTERRUPTED;  if (rv < 0)    return 0;  return(response_length);}/*----------------------------------------------------------------------*//* returns the number of bytes written.  0 if an error */longinterpret_message(	char *request_message,	long request_length, /* length of the buffer */	char *response_message,	long response_buffer_length,	long connection,	boolean verbose GCC_UNUSED){  long response_length;  /* ?  if(verbose){    printf ("sending");    if(hostname_internal && strlen(hostname_internal) > 0)      printf(" to host %s", hostname_internal);    if(service_name && strlen(service_name) > 0)      printf(" for service %s", service_name);    printf("\n");    twais_dsply_rsp_apdu(request_message + HEADER_LENGTH,			 request_length);  }  */  writeWAISPacketHeader(request_message,			request_length,			(long)'z',	/* Z39.50 */			"wais      ", /* server name */			(long)NO_COMPRESSION,	/* no compression */			(long)NO_ENCODING,(long)HEADER_VERSION);  if(connection != 0) {    response_length = transport_message(connection, request_message,					request_length,					response_message,					response_buffer_length);    if (response_length == HT_INTERRUPTED)      return(HT_INTERRUPTED);  }  else      return(0);  return(response_length);}/*----------------------------------------------------------------------*//* modifies the string to exclude all seeker codes. sets length to   the new length. */PRIVATE char *delete_seeker_codes(char *string, long *length){  long original_count; /* index into the original string */  long new_count = 0; /* index into the collapsed string */  for(original_count = 0; original_count < *length; original_count++){    if(27 == string[original_count]){      /* then we have an escape code */      /* if the next letter is '(' or ')', then ignore two letters */      if('(' == string[original_count + 1] ||    ')' == string[original_count + 1])     original_count += 1;    /* it is a term marker */      else original_count += 4; /* it is a paragraph marker */    }    else string[new_count++] = string[original_count];  }  *length = new_count;  return(string);}/*----------------------------------------------------------------------*/#if defined(VMS) && defined(__GNUC__)			/* 10-AUG-1995 [pr] *//*  Workaround for an obscure bug in gcc's 2.6.[123] and 2.7.0 vax/vms port;  sometimes global variables will end up not being defined properly,  causing first gas to assume they're routines, then the linker to complain  about unresolved symbols, and finally the program to reference the wrong  objects (provoking ACCVIO).  It's triggered by the specific ordering of  variable usage in the source code, hence rarely appears.  This bug is  fixed in gcc 2.7.1, and was not present in 2.6.0 and earlier.   Make a reference to VAXCRTL's _ctype_[], and also one to this dummy   variable itself to prevent any "defined but not used" warning. */static __const void *__const ctype_dummy[] = { &_ctype_, &ctype_dummy };#endif /* VMS && __GNUC__ *//* returns a pointer to a string with good stuff */char *trim_junk(char *headline){  long length = strlen(headline) + 1; /* include the trailing null */  size_t i;  headline = delete_seeker_codes(headline, &length);  /* delete leading spaces */  for(i=0; i < strlen(headline); i++){    if(isprint(headline[i])){      break;    }  }  headline = headline + i;  /* delete trailing stuff */  for(i=strlen(headline) - 1 ; i > 0; i--){    if(isprint(headline[i])){      break;    }    headline[i] = '\0';  }  return(headline);}/*----------------------------------------------------------------------*//***	Routines originally from ZProt.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 - Changed any->bits to any->bytes   4.11.90  HWM - generalized conditional includes (see c-dialect.h)*/#define RESERVE_SPACE_FOR_HEADER(spaceLeft)		\	*spaceLeft -= HEADER_LEN;#define RELEASE_HEADER_SPACE(spaceLeft)			\	if (*spaceLeft > 0)				\	  *spaceLeft += HEADER_LEN;/*----------------------------------------------------------------------*/InitResponseAPDU*makeInitResponseAPDU(boolean result,boolean search,boolean present,boolean deleteIt,boolean accessControl,boolean resourceControl,long prefSize,long maxMsgSize,char* auth,char* id,char* name,char* version,any* refID,void* userInfo)/* build an initResponse APDU with user specified information */{  InitResponseAPDU* init = (InitResponseAPDU*)s_malloc((size_t)sizeof(InitResponseAPDU));  init->PDUType = initResponseAPDU;  init->Result = result;  init->willSearch = search;  init->willPresent = present;  init->willDelete = deleteIt;  init->supportAccessControl = accessControl;  init->supportResourceControl = resourceControl;  init->PreferredMessageSize = prefSize;  init->MaximumRecordSize = maxMsgSize;  init->IDAuthentication = s_strdup(auth);  init->ImplementationID = s_strdup(id);  init->ImplementationName = s_strdup(name);  init->ImplementationVersion = s_strdup(version);  init->ReferenceID = duplicateAny(refID);  init->UserInformationField = userInfo; /* not copied! */  return(init);}/*----------------------------------------------------------------------*/voidfreeInitResponseAPDU(InitResponseAPDU* init)/* free an initAPDU */{  s_free(init->IDAuthentication);  s_free(init->ImplementationID);  s_free(init->ImplementationName);  s_free(init->ImplementationVersion);  freeAny(init->ReferenceID);  s_free(init);}/*----------------------------------------------------------------------*/char*writeInitResponseAPDU(InitResponseAPDU* init, char* buffer, long* len)/* write the initResponse to a buffer, adding system information */{  char* buf = buffer + HEADER_LEN; /* leave room for the header-length-indicator */  long size;  bit_map* optionsBM = NULL;  RESERVE_SPACE_FOR_HEADER(len);  buf = writePDUType(init->PDUType,buf,len);  buf = writeBoolean(init->Result,buf,len);  buf = writeProtocolVersion(buf,len);  optionsBM = makeBitMap((unsigned long)5,init->willSearch,init->willPresent,                         init->willDelete,init->supportAccessControl,                         init->supportResourceControl);  buf = writeBitMap(optionsBM,DT_Options,buf,len);  freeBitMap(optionsBM);  buf = writeNum(init->PreferredMessageSize,DT_PreferredMessageSize,buf,len);  buf = writeNum(init->MaximumRecordSize,DT_MaximumRecordSize,buf,len);  buf = writeString(init->IDAuthentication,DT_IDAuthentication,buf,len);  buf = writeString(init->ImplementationID,DT_ImplementationID,buf,len);  buf = writeString(init->ImplementationName,DT_ImplementationName,buf,len);  buf = writeString(init->ImplementationVersion,DT_ImplementationVersion,buf,len);  buf = writeAny(init->ReferenceID,DT_ReferenceID,buf,len);  /* go back and write the header-length-indicator */  RELEASE_HEADER_SPACE(len);  size = buf - buffer - HEADER_LEN;  writeBinaryInteger(size,HEADER_LEN,buffer,len);  if (init->UserInformationField != NULL)    buf = writeInitResponseInfo(init,buf,len);  return(buf);}/*----------------------------------------------------------------------*/char*readInitResponseAPDU(InitResponseAPDU** init, char* buffer){  char* buf = buffer;  boolean search,present,delete,accessControl,resourceControl;  long prefSize,maxMsgSize;  char *auth,*id,*name,*version;  long size;  pdu_type pduType;  bit_map* versionBM = NULL;  bit_map* optionsBM = NULL;  boolean result;  any *refID = NULL;  void* userInfo = NULL;  auth = id = name = version = NULL;  refID = NULL;  /* read required part */  buf = readBinaryInteger(&size,HEADER_LEN,buf);  buf = readPDUType(&pduType,buf);  buf = readBoolean(&result,buf);  buf = readBitMap(&versionBM,buf);  buf = readBitMap(&optionsBM,buf);  buf = readNum(&prefSize,buf);  buf = readNum(&maxMsgSize,buf);  /* decode optionsBM */  search = bitAtPos(0,optionsBM);  present = bitAtPos(1,optionsBM);  delete = bitAtPos(2,optionsBM);  accessControl = bitAtPos(3,optionsBM);  resourceControl = bitAtPos(4,optionsBM);  /* read optional part */  while (buf < (buffer + size + HEADER_LEN))    { data_tag tag = peekTag(buf);      switch (tag)	{ case DT_IDAuthentication:	    buf = readString(&auth,buf);	    break;	  case DT_ImplementationID:	    buf = readString(&id,buf);	    break;	  case DT_ImplementationName:	    buf = readString(&name,buf);	    break;	  case DT_ImplementationVersion:	    buf = readString(&version,buf);

⌨️ 快捷键说明

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