cgi_search.c File Reference

#include "cgi.h"

Include dependency graph for cgi_search.c:

Go to the source code of this file.

Functions

char * strn2istr (char *s1, char *s2, size_t l2)
char * stristr (char *s1, char *s2)
int DatabaseFindNextRecord (FILE *database, CGINameValue *header, CGINameValue *cgidata, char *query)
int Matches (CGINameValue *header, CGINameValue *query)
int DatabaseFindFast (FILE *database, CGINameValue *header, CGINameValue *query, int *pos)
int DatabaseSearchRecord (FILE *database, char *querystr, int casesensitive)


Function Documentation

int DatabaseFindFast FILE *  database,
CGINameValue header,
CGINameValue query,
int *  pos
 

Returns 1 on success.

Definition at line 72 of file cgi_search.c.

References DatabaseReadRecord(), Matches(), and NULL.

Referenced by DeleteOldRecords(), and FindUserRecordASC().

00075 {
00076  while (1)
00077    {
00078     int flags = 0;
00079     if (pos) *pos = ftell(database);
00080     if (DatabaseReadRecord(database, header,&flags) == 0) break;
00081     if (flags != 0) continue; /* indicates a deleted record */
00082 
00083     if (query == NULL) return 1;
00084 
00085     if (Matches(header,query)) return 1;
00086    }
00087  return 0; /* ran out */
00088 }

int DatabaseFindNextRecord FILE *  database,
CGINameValue header,
CGINameValue cgidata,
char *  query
 

Returns 1 on success. Query logic is the same as for scripted IF statements.

Definition at line 31 of file cgi_search.c.

References CGIFREE, DatabaseReadRecord(), EvaluateLogic(), NULL, and strdup().

Referenced by CGImain(), EZSReport(), and JSHasRecord().

00035 {
00036  int ret = 0;
00037  char * Comparison = strdup(query);
00038 
00039  while (1)
00040    {
00041     int flags = 0;
00042 
00043     if (DatabaseReadRecord(database, header,&flags) == 0) break;
00044     if (flags != 0) continue; /* indicates a deleted record */
00045 
00046     if (query == NULL) {ret = 1; break;}
00047 
00048     if (EvaluateLogic(Comparison,header,cgidata)) {ret = 1; break;}
00049     strcpy(Comparison,query);
00050   }
00051  CGIFREE(Comparison);
00052  return ret; /* ran out */
00053 }

int DatabaseSearchRecord FILE *  database,
char *  find,
int  casesensitive
 

Searches the current record for any instance of a substring. If found, it returns 1 and positions the database pointer to the beginning of the record. If a substring is not found, it advances the pointer to the next record.

Definition at line 156 of file cgi_search.c.

References CGIFREE, MAXDATA, ReadUntilChar(), and stristr().

00157 {
00158  int c;
00159  char *name = malloc(MAXDATA);
00160  long int fpos;
00161  int column=0;
00162 
00163  fpos = ftell(database);
00164  if (fpos < 0)
00165   {
00166    CGIFREE(name);
00167    return -1;
00168   }
00169  do {
00170     c = ReadUntilChar(database,name,MAXDATA,"\t\n",'\r');
00171     if (column++ == 0 && name[0] == '#')
00172      { /* skip comment lines and deleted records */
00173       ReadUntilChar(database,name,MAXDATA,"\n",'\r');
00174       CGIFREE(name);
00175       return 0;
00176      }
00177 
00178     if (name[0] == 0)  continue; /* skip blank fields */
00179     if (casesensitive)
00180      {
00181       if (strstr(name,querystr))
00182        {
00183         fseek(database,fpos,0);
00184         CGIFREE(name);
00185         return 1;
00186        }
00187      }
00188     else
00189      {
00190       if (stristr(name,querystr))
00191        {
00192         fseek(database,fpos,0);
00193         CGIFREE(name);
00194         return 1;
00195        }
00196      }
00197    } while (c != '\r' && c != '\n' && c != EOF);
00198 
00199  CGIFREE(name);
00200  return 0;
00201 }

int Matches CGINameValue header,
CGINameValue query
 

Definition at line 55 of file cgi_search.c.

References GetField(), NULL, and CGINameValue::value.

Referenced by DatabaseFindFast().

00057 {
00058  int x;
00059 
00060     for (x=0; query[x].name != NULL ;x++)
00061     {
00062      CGINameValue* f;
00063      if (!query[x].name[0]) continue;
00064      f = GetField(header,query[x].name);
00065      if (!f) continue;
00066      if (strcmp(f->value?f->value:"",query[x].value)) return 0;
00067     }
00068 
00069     return 1; /* ha! found it */
00070 }

char* stristr char *  s1,
char *  s2
 

Definition at line 1462 of file cgi_util.c.

References strn2istr().

01463 {
01464  return strn2istr(s1,s2,strlen(s2));
01465 }

char* strn2istr char *  s1,
char *  s2,
size_t  l2
 

Definition at line 1452 of file cgi_util.c.

References strnicmp().

01453 {
01454  while (*s1)
01455  {
01456   if (strnicmp(s1,s2,l2) == 0) return s1;
01457   s1++;
01458  }
01459  return 0;
01460 }



Raosoft, Inc.
Raosoft EZReport, EZSurvey, InterForm, RapidReport, Raosoft, and SurveyWin are registered trademarks of Raosoft, Inc. Page contents © 1996-2007 by Raosoft, Inc. You may use and modify this file for your own use, but may not distribute it or derivative works without the prior written consent of Raosoft, Inc. This software is provided "as is," and Raosoft makes no warranty, express or implied, of fitness for a particular application. Every measure has been taken to anticipate risks inherent to computer networks, but we cannot guarantee safety or reliability of this program in every situation.
Tel: 206-525-4025 (US) Email: raosoft@raosoft.com
http://www.raosoft.com/