| 1 | /* ------------------------------ serc.c ---------------------------------- */ |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | /* Copyright (c) 1990 - 1994 Adalberto Otranto Tardelli. All rights reserved. |
|---|
| 5 | * Written by A.O.Tardelli 7/90 |
|---|
| 6 | * Redistribution and use in source and binary forms are freely permitted |
|---|
| 7 | * provided that the above copyright notice and attribution and date of work |
|---|
| 8 | * and this paragraph are duplicated in all such forms. |
|---|
| 9 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
|---|
| 10 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
|---|
| 11 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 12 | * This program performs a MicroISIS master file dump, formatted display, |
|---|
| 13 | * search and record limits, pattern changes, data base join, field update, |
|---|
| 14 | * master file update and ISO-2709 processing. Input can also be a plain file. |
|---|
| 15 | * A description of this program is available in CISIS Interface Application - |
|---|
| 16 | * MX Program. Sao Paulo, BIREME - Latin American and Caribbean Center on |
|---|
| 17 | * Health Sciences Information/PAHO-WHO, April 1991. 12p. See also: |
|---|
| 18 | * - http://www.bireme.br (IsisFamily/CisisUtilities) |
|---|
| 19 | * - ftp://ftp.bireme.br/cisis |
|---|
| 20 | * Currently works with CISIS Interface 4.01 and BorlandC 5.02 or |
|---|
| 21 | * MSVC 6.0 for win32/console application, and for Linux/gcc, HPUX/CC and |
|---|
| 22 | * Sun/CC, among other platforms. AOT, 21/02/2001. |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | /* |
|---|
| 26 | ..Client program that makes a connection for a byte stream socket in the Internet namespace. |
|---|
| 27 | */ |
|---|
| 28 | /* |
|---|
| 29 | */ |
|---|
| 30 | |
|---|
| 31 | #include <stdio.h> |
|---|
| 32 | #include <ctype.h> |
|---|
| 33 | #include <string.h> |
|---|
| 34 | |
|---|
| 35 | #include "cisis.h" /* CISIS Interface header file */ |
|---|
| 36 | #include "cirun.h" /* CISIS Interface runtime declarations */ |
|---|
| 37 | |
|---|
| 38 | #define PORT 1417 |
|---|
| 39 | #define MESSAGE "wtrig2 ... text=..." |
|---|
| 40 | #define SERVERHOST "serverofi.bireme.br" |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | #define TAG1 1 |
|---|
| 44 | #define TAG2 2 |
|---|
| 45 | #define TAG23 2 |
|---|
| 46 | |
|---|
| 47 | #define FATRAP__WT 1 |
|---|
| 48 | |
|---|
| 49 | void serc_syntax(void); |
|---|
| 50 | void serc_syntax() |
|---|
| 51 | { |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | #if MX_SERX |
|---|
| 55 | int |
|---|
| 56 | mainserx(int argc, char *argv[]) |
|---|
| 57 | #else //MX_SERX |
|---|
| 58 | int |
|---|
| 59 | main(int argc, char *argv[]) |
|---|
| 60 | #endif //MX_SERX |
|---|
| 61 | { |
|---|
| 62 | RECSTRU *recp; /* mandatory for defines REC RDB MF0 MFR DIR, FIELDP */ |
|---|
| 63 | LONGX irec=0; |
|---|
| 64 | |
|---|
| 65 | LONGX maxmfrl=MAXMFRL; // default |
|---|
| 66 | |
|---|
| 67 | char serverhost[CIMPL]; //=SERVERHOST; |
|---|
| 68 | uint16_t port=PORT; |
|---|
| 69 | LONGX xval; |
|---|
| 70 | |
|---|
| 71 | char *wwwcgip=NULL; // allocated in cicgi0 |
|---|
| 72 | char cipfilearea[CIMPL+1]; |
|---|
| 73 | #if MX_SERX |
|---|
| 74 | char *cipfile="mx.cip"; |
|---|
| 75 | #else //MX_SERX |
|---|
| 76 | char *cipfile="serx.cip"; |
|---|
| 77 | #endif //MX_SERX |
|---|
| 78 | |
|---|
| 79 | char *parmwtmsg=NULL; // wtrig2 command line - calling argument wtrig2 |
|---|
| 80 | char *wtmsg=NULL; // wtrig2 command line - allocated if not parmwtmsg |
|---|
| 81 | |
|---|
| 82 | char *parmhtmsg=NULL; // http command line - calling argument http |
|---|
| 83 | char *htmsg=NULL; // http command line - allocated if not parmhtmsg |
|---|
| 84 | |
|---|
| 85 | char *parmxtmsg=NULL; // xttt command line - calling argument xttt |
|---|
| 86 | char *xtmsg=NULL; // xttt command line - allocated if not parmxtmsg |
|---|
| 87 | |
|---|
| 88 | int debug=0; |
|---|
| 89 | char force[BUFSIZ+CIMPL] = { '\0' }; |
|---|
| 90 | int outfmthtml=0; |
|---|
| 91 | |
|---|
| 92 | char *txtvp=""; // text parameter |
|---|
| 93 | int txtvlen=0; // text parameter |
|---|
| 94 | char *txt1vp=""; // text1 parameter |
|---|
| 95 | int txt1vlen=0; // text1 parameter |
|---|
| 96 | |
|---|
| 97 | char *p,*q,*x; |
|---|
| 98 | char *hhp; |
|---|
| 99 | // char *hdatap; |
|---|
| 100 | |
|---|
| 101 | int len,y; |
|---|
| 102 | char *np,*vp; |
|---|
| 103 | int nlen,vlen; |
|---|
| 104 | int npairs; //=0; |
|---|
| 105 | |
|---|
| 106 | char *buffer;//=NULL // reply from mainserver/wtrig2 |
|---|
| 107 | int buffersize; |
|---|
| 108 | |
|---|
| 109 | char *cgimsg=NULL; // reply from mainserver/wtrig2 |
|---|
| 110 | LONGX cgimsgsize; |
|---|
| 111 | |
|---|
| 112 | char *databuff;//=NULL // reply from mainserver/wtrig2 |
|---|
| 113 | int databuffsize; |
|---|
| 114 | |
|---|
| 115 | char *textbuff;//=NULL // reply from mainserver/wtrig2 |
|---|
| 116 | int textbuffsize; |
|---|
| 117 | char *tbp; |
|---|
| 118 | |
|---|
| 119 | char *pcmdp; |
|---|
| 120 | char *procp; |
|---|
| 121 | char *pftxp; |
|---|
| 122 | |
|---|
| 123 | LONGX dbmfn=1; |
|---|
| 124 | int dbtag=0; |
|---|
| 125 | int dbocc=0; |
|---|
| 126 | int dboc2=0; |
|---|
| 127 | char dbname[CIMPL+1] = { '\0' }; |
|---|
| 128 | |
|---|
| 129 | int rc; //=0; |
|---|
| 130 | int i; |
|---|
| 131 | |
|---|
| 132 | int mustclose=0; |
|---|
| 133 | |
|---|
| 134 | time_t secs_now; |
|---|
| 135 | time_t secs_start,secs_end; |
|---|
| 136 | struct tm *tp; |
|---|
| 137 | |
|---|
| 138 | #if FATRAP__WT |
|---|
| 139 | int z_xerrno; |
|---|
| 140 | int z_errcod; |
|---|
| 141 | char z_iomsg[MAXFATML+1]; |
|---|
| 142 | jmp_buf z_jumper; |
|---|
| 143 | int z_jumprc; |
|---|
| 144 | #endif |
|---|
| 145 | |
|---|
| 146 | #if FATRAP__WT |
|---|
| 147 | /* save/notrap */ |
|---|
| 148 | strcpy(z_iomsg,fatal_iomsg); memcpy(z_jumper,fatal_jumper,sizeof(fatal_jumper)); z_errcod=fatal_errcod; |
|---|
| 149 | z_xerrno=dbxopt_errno; |
|---|
| 150 | /* trap cisis fatal() */ |
|---|
| 151 | strcpy(fatal_iomsg,"trap"); |
|---|
| 152 | /* disable dbxopen msg */ |
|---|
| 153 | dbxopt_errno=0; |
|---|
| 154 | z_jumprc = setjmp(fatal_jumper); |
|---|
| 155 | if (z_jumprc != 0) { |
|---|
| 156 | /* error */ |
|---|
| 157 | if (outfmthtml) { |
|---|
| 158 | printf("error type=\"fatal\" in=\"serx\" code=\"%d\" error=\"%s\"\n",fatal_errcod,fatal_iomsg); |
|---|
| 159 | if (mustclose) printf("</pre></body></html>\n"); |
|---|
| 160 | } |
|---|
| 161 | else { |
|---|
| 162 | printf("<error type=\"fatal\" in=\"serx\" code=\"%d\">%s</error>\n",fatal_errcod,fatal_iomsg); |
|---|
| 163 | if (mustclose) { |
|---|
| 164 | printf("</request>\n"); |
|---|
| 165 | printf("</serc>\n"); |
|---|
| 166 | } |
|---|
| 167 | } |
|---|
| 168 | /* restore/notrap */ //strcpy(fatal_iomsg,""); |
|---|
| 169 | memcpy(fatal_jumper,z_jumper,sizeof(fatal_jumper)); strcpy(fatal_iomsg,z_iomsg); |
|---|
| 170 | fatal_errcod=z_errcod; |
|---|
| 171 | dbxopt_errno=z_xerrno; |
|---|
| 172 | return (-1); |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | #endif |
|---|
| 176 | |
|---|
| 177 | /* init |
|---|
| 178 | */ |
|---|
| 179 | strcpy(serverhost,SERVERHOST); |
|---|
| 180 | |
|---|
| 181 | /* get secs_ for elapsed */ |
|---|
| 182 | secs_start=time(&secs_now); |
|---|
| 183 | tp=localtime(&secs_start); |
|---|
| 184 | |
|---|
| 185 | /* go |
|---|
| 186 | */ |
|---|
| 187 | for (i=1; i < argc; i++) { |
|---|
| 188 | p=argv[i]; |
|---|
| 189 | if (strcmp(p,"hello") == 0) { |
|---|
| 190 | //serc_syntax(); |
|---|
| 191 | printf("%s",cicopyr("Utility SERC")); |
|---|
| 192 | printf("\n"); |
|---|
| 193 | printf("serc [hello] [debug] [cipar=<file>] \n"); |
|---|
| 194 | printf(" [port=1417|<port>] \n"); |
|---|
| 195 | printf(" [host=localhost|<host>] \n"); |
|---|
| 196 | // [^c<file>] |
|---|
| 197 | printf(" \"wtrig2 c=col[^p<port>] [maxrel=n] [minsim=0.n] [text1=x] [text=x]\" \n"); |
|---|
| 198 | printf(" [db=x] [mfn=n] [tag=n] [occ=n] [oc2=n] [proc.n=text] [pft.n=text] [pcmd.n=text] \n"); |
|---|
| 199 | printf("\n"); |
|---|
| 200 | exit(1); |
|---|
| 201 | } |
|---|
| 202 | if (strncmp(p,"force=",6) == 0) { |
|---|
| 203 | int len=strlen(force); |
|---|
| 204 | if (len) force[len]='&'; |
|---|
| 205 | else strcpy(force,"QUERY_STRING=\""); |
|---|
| 206 | strcat(force,p+6); |
|---|
| 207 | strcat(force,"\""); |
|---|
| 208 | continue; |
|---|
| 209 | } |
|---|
| 210 | if (strcmp(p,"debug") == 0) { |
|---|
| 211 | debug=1; |
|---|
| 212 | continue; |
|---|
| 213 | } |
|---|
| 214 | if (strncmp(p,"cipar=",6) == 0) { |
|---|
| 215 | cipfile=p+6; |
|---|
| 216 | continue; |
|---|
| 217 | } |
|---|
| 218 | if (strncmp(p,"port=",5) == 0) { |
|---|
| 219 | if (sscanf(p+5,"%"_LD_,&xval) != 1) fatal(p); |
|---|
| 220 | port=(uint16_t)xval; |
|---|
| 221 | continue; |
|---|
| 222 | } |
|---|
| 223 | if (strncmp(p,"host=",5) == 0) { |
|---|
| 224 | if (!*(p+5)) fatal(p); |
|---|
| 225 | strcpy(serverhost,p+5); |
|---|
| 226 | continue; |
|---|
| 227 | } |
|---|
| 228 | if (strncmp(p,"wtrig2 ",6) == 0) { |
|---|
| 229 | parmwtmsg=p; |
|---|
| 230 | continue; |
|---|
| 231 | } |
|---|
| 232 | if (strncmp(p,"xttp ",5) == 0) { |
|---|
| 233 | parmxtmsg=p; |
|---|
| 234 | continue; |
|---|
| 235 | } |
|---|
| 236 | parmhtmsg=p; |
|---|
| 237 | //if (strncmp(p,"http ",5) == 0) { |
|---|
| 238 | // continue; |
|---|
| 239 | //} |
|---|
| 240 | //printf("Content-type: text/plain\n\n"); |
|---|
| 241 | //fatal(p); |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | if (*force) { |
|---|
| 245 | putenv("REQUEST_METHOD=GET"); |
|---|
| 246 | putenv(force); |
|---|
| 247 | } |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | /* get CGI data |
|---|
| 251 | */ |
|---|
| 252 | p=getenv("REQUEST_METHOD"); if (debug) if (p) printf("<debug getenv=\"REQUEST_METHOD\"><![CDATA[ %s ]]></debug>\n",p); |
|---|
| 253 | q=getenv("QUERY_STRING"); if (debug) if (q) printf("<debug getenv=\"QUERY_STRING\"><![CDATA[ %s ]]></debug>\n",q); |
|---|
| 254 | if (p) cicgi0(NULL, NULL, &wwwcgip, (UWORD)2000, "tag"); // H1 10 ^ndbn^vcdsH1 10 ^ncount^v2H1 7 ^nnow^vH1 10 ^nbtell^v0H1 20 ^nbool^vplants*waterH1 15 ^npft^vmfn/v24/ |
|---|
| 255 | if (debug) if (!wwwcgip) printf("+++ wwwcgip=%s<br />\n","void"); |
|---|
| 256 | |
|---|
| 257 | //internal parms - execute |
|---|
| 258 | if (wwwcgip) { |
|---|
| 259 | np=strstr(wwwcgip,"^ndebug^v"); |
|---|
| 260 | if (np) { |
|---|
| 261 | for (xval=0,p=np+9; *p && isdigit(*p); p++) xval=xval*10+(int)(*p)-(int)'0'; |
|---|
| 262 | debug=(int)xval; |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | np=strstr(wwwcgip,"^ncipar^v"); |
|---|
| 266 | if (np) { |
|---|
| 267 | for (vlen=0,vp=p=np+9; *p; p++) if (strncmp(p,"H2000 ",6) == 0) break; else vlen++; |
|---|
| 268 | if (vlen) { char c; if (vlen>CIMPL) vlen=CIMPL; c=vp[vlen]; vp[vlen]='\0'; strcpy(cipfile=cipfilearea,vp); vp[vlen]=c; } |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | np=strstr(wwwcgip,"^nport^v"); |
|---|
| 272 | if (np) { |
|---|
| 273 | for (xval=0,p=np+8; *p && isdigit(*p); p++) xval=xval*10+(int)(*p)-(int)'0'; |
|---|
| 274 | port=(uint16_t)xval; |
|---|
| 275 | } |
|---|
| 276 | np=strstr(wwwcgip,"^nhost^v"); |
|---|
| 277 | if (np) { |
|---|
| 278 | for (vlen=0,vp=p=np+8; *p; p++) if (strncmp(p,"H2000 ",6) == 0) break; else vlen++; |
|---|
| 279 | if (vlen) { memcpy(serverhost,vp,vlen); serverhost[vlen]='\0'; } |
|---|
| 280 | } |
|---|
| 281 | } // end wwwcgip |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | /* setup wtfnew |
|---|
| 285 | */ |
|---|
| 286 | if (!ciawtfp) if (dbxciset(cipfile)) fatal(cipfile); |
|---|
| 287 | |
|---|
| 288 | /* setup alloc |
|---|
| 289 | */ |
|---|
| 290 | maxmfrl=rec_maxmfrl; |
|---|
| 291 | |
|---|
| 292 | cgimsgsize=maxmfrl; |
|---|
| 293 | buffersize=(int)maxmfrl; |
|---|
| 294 | |
|---|
| 295 | // alloc reply buffer / move nul to 1st byte |
|---|
| 296 | buffer=loadfile(NULL,'@',"",NULL,(LONGX)buffersize,'\0'); |
|---|
| 297 | if (!buffer) fatal("serc/alloc/buffer"); |
|---|
| 298 | |
|---|
| 299 | // alloc reply databuff / move nul to 1st byte |
|---|
| 300 | databuffsize=buffersize; |
|---|
| 301 | databuff=loadfile(NULL,'@',"",NULL,databuffsize,'\0'); |
|---|
| 302 | if (!databuff) fatal("serc/alloc/databuff"); |
|---|
| 303 | |
|---|
| 304 | // alloc reply textbuff / move nul to 1st byte |
|---|
| 305 | textbuffsize=buffersize; |
|---|
| 306 | textbuff=loadfile(NULL,'@',"",NULL,textbuffsize,'\0'); |
|---|
| 307 | if (!textbuff) fatal("serc/alloc/textbuff"); |
|---|
| 308 | |
|---|
| 309 | /* reply header |
|---|
| 310 | */ |
|---|
| 311 | if (outfmthtml) { |
|---|
| 312 | printf("Content-type: text/html\n\n"); |
|---|
| 313 | printf("<html><body><pre>\n"); |
|---|
| 314 | } |
|---|
| 315 | else { |
|---|
| 316 | //printf("Content-type: text/plain\n\n"); |
|---|
| 317 | printf("Content-type: text/xml\n\n"); |
|---|
| 318 | printf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n"); |
|---|
| 319 | printf("<serc cisis=\"CIFFI\" version=\"4.4a\" date=\"%04d%02d%02d\" time=\"%02d%02d%02d\">\n", |
|---|
| 320 | 1900+tp->tm_year,tp->tm_mon+1,tp->tm_mday,tp->tm_hour,tp->tm_min,tp->tm_sec); |
|---|
| 321 | printf("<request>\n"); |
|---|
| 322 | } |
|---|
| 323 | mustclose=1; |
|---|
| 324 | |
|---|
| 325 | /* setup wtrig2 parms |
|---|
| 326 | */ |
|---|
| 327 | if (!parmwtmsg) { |
|---|
| 328 | |
|---|
| 329 | //drive mainserver to procs |
|---|
| 330 | if (wwwcgip) if (strstr(wwwcgip,"^nprocs^von") || strstr(wwwcgip,"^ntagtext^v") || strstr(wwwcgip,"^ntagtext1^v") |
|---|
| 331 | || strstr(wwwcgip,"^ndb^v") || strstr(wwwcgip,"^nmfn^v") || strstr(wwwcgip,"^ntag^v") |
|---|
| 332 | || strstr(wwwcgip,"^nocc^v") || strstr(wwwcgip,"^noc2^v") |
|---|
| 333 | || strstr(wwwcgip,"^npcmd^v") || strstr(wwwcgip,"^nproc^v") || strstr(wwwcgip,"^npft^v") ) { |
|---|
| 334 | |
|---|
| 335 | if (debug) printf("+++ wwwcgip=%s<br />\n",wwwcgip); |
|---|
| 336 | |
|---|
| 337 | np=strstr(wwwcgip,"^ndb^v"); |
|---|
| 338 | if (np) { |
|---|
| 339 | for (vlen=0,p=np+6; *p; p++) if (strncmp(p,"H2000 ",6) == 0) break; else vlen++; |
|---|
| 340 | memcpy(dbname,np+6,vlen); dbname[vlen]='\0'; |
|---|
| 341 | } |
|---|
| 342 | np=strstr(wwwcgip,"^nmfn^v"); |
|---|
| 343 | if (np) { |
|---|
| 344 | for (dbmfn=0,p=np+7; *p && isdigit(*p); p++) dbmfn=dbmfn*10+(int)(*p)-(int)'0'; |
|---|
| 345 | } |
|---|
| 346 | np=strstr(wwwcgip,"^ntag^v"); |
|---|
| 347 | if (np) { |
|---|
| 348 | for (dbtag=0,p=np+7; *p && isdigit(*p); p++) dbtag=dbtag*10+(int)(*p)-(int)'0'; |
|---|
| 349 | } |
|---|
| 350 | np=strstr(wwwcgip,"^nocc^v"); |
|---|
| 351 | if (np) { |
|---|
| 352 | for (dbocc=0,p=np+7; *p && isdigit(*p); p++) dbocc=dbocc*10+(int)(*p)-(int)'0'; |
|---|
| 353 | } |
|---|
| 354 | np=strstr(wwwcgip,"^noc2^v"); |
|---|
| 355 | if (np) { |
|---|
| 356 | for (dboc2=0,p=np+7; *p && isdigit(*p); p++) dboc2=dboc2*10+(int)(*p)-(int)'0'; |
|---|
| 357 | } |
|---|
| 358 | |
|---|
| 359 | //read |
|---|
| 360 | if (!dbname[0]) strcpy(dbname,"null"); |
|---|
| 361 | if (dbmfn <= 0) dbmfn=1; |
|---|
| 362 | RECORD(irec,dbname,dbmfn); |
|---|
| 363 | // if (RECrc != RCNORMAL || MFRstatus != ACTIVE) { |
|---|
| 364 | // RECrc=RCNORMAL; MFRstatus=ACTIVE; MFRnvf=0; |
|---|
| 365 | // } |
|---|
| 366 | |
|---|
| 367 | #if 0 |
|---|
| 368 | //sort dir entries |
|---|
| 369 | if (fldupdat(irec,"S")) fatal("mxget/read/S"); |
|---|
| 370 | |
|---|
| 371 | //convert entities |
|---|
| 372 | if (fldupdat(irec,"Gserxgiz0")) fatal("mxget/read/Gserxgiz0"); |
|---|
| 373 | #endif |
|---|
| 374 | //add cgi data |
|---|
| 375 | if (fldupdat(irec,wwwcgip)) fatal("mxget/read/wwwcgip"); |
|---|
| 376 | |
|---|
| 377 | np=strstr(wwwcgip,"^nproc^v"); |
|---|
| 378 | if (np) { |
|---|
| 379 | for (vlen=0,p=vp=np+8; *p; p++) if (strncmp(p,"H2000 ",6) == 0) break; else vlen++; |
|---|
| 380 | if (vlen) { |
|---|
| 381 | char k=vp[vlen]; |
|---|
| 382 | vp[vlen]='\0'; |
|---|
| 383 | rc=recfmt(irec,databuffsize,vp,databuff,databuffsize); |
|---|
| 384 | vp[vlen]=k; |
|---|
| 385 | if (rc < 0) fatal("mxget/procs/proc/recfmt"); |
|---|
| 386 | if (fldupdat(irec,databuff)) fatal("mxget/procs/proc/fldupdat"); |
|---|
| 387 | } |
|---|
| 388 | } |
|---|
| 389 | np=strstr(wwwcgip,"^npcmd^v"); |
|---|
| 390 | if (np) { |
|---|
| 391 | for (vlen=0,p=vp=np+8; *p; p++) if (strncmp(p,"H2000 ",6) == 0) break; else vlen++; |
|---|
| 392 | if (vlen) { |
|---|
| 393 | char k=vp[vlen]; |
|---|
| 394 | vp[vlen]='\0'; |
|---|
| 395 | if (fldupdat(irec,vp)) fatal("mxget/procs/pcmd"); |
|---|
| 396 | vp[vlen]=k; |
|---|
| 397 | } |
|---|
| 398 | } |
|---|
| 399 | |
|---|
| 400 | textbuff[0]='\0'; tbp=textbuff; |
|---|
| 401 | np=strstr(wwwcgip,"^ntagtext^v"); |
|---|
| 402 | if (np) { |
|---|
| 403 | for (vlen=0,p=vp=np+11; *p; p++) if (strncmp(p,"H2000 ",6) == 0) break; else vlen++; |
|---|
| 404 | if (isdigit(*vp)) { |
|---|
| 405 | int iocc=1,tag=atoi(vp); |
|---|
| 406 | for (; *recfield(tbp+strlen(tbp),irec,tag,iocc,""); iocc++) { |
|---|
| 407 | strcat(tbp,". "); |
|---|
| 408 | } |
|---|
| 409 | } |
|---|
| 410 | else { |
|---|
| 411 | char k=vp[vlen]; |
|---|
| 412 | vp[vlen]='\0'; |
|---|
| 413 | rc=recfmt(irec,textbuffsize,vp,tbp,textbuffsize); |
|---|
| 414 | vp[vlen]=k; |
|---|
| 415 | if (rc < 0) fatal("mxget/tagtext/recfmt"); |
|---|
| 416 | } |
|---|
| 417 | txtvlen=strlen(tbp); |
|---|
| 418 | if (txtvlen) { txtvp=tbp; tbp+=txtvlen; } |
|---|
| 419 | *++tbp='\0'; |
|---|
| 420 | } |
|---|
| 421 | np=strstr(wwwcgip,"^ntagtext1^v"); |
|---|
| 422 | if (np) { |
|---|
| 423 | for (vlen=0,p=vp=np+12; *p; p++) if (strncmp(p,"H2000 ",6) == 0) break; else vlen++; |
|---|
| 424 | if (isdigit(*txt1vp)) { |
|---|
| 425 | int iocc=1,tag=atoi(txt1vp); |
|---|
| 426 | for (; *recfield(tbp+strlen(tbp),irec,tag,iocc,""); iocc++) { |
|---|
| 427 | strcat(tbp,"\n"); |
|---|
| 428 | } |
|---|
| 429 | } |
|---|
| 430 | else { |
|---|
| 431 | int rc; |
|---|
| 432 | char k=vp[vlen]; |
|---|
| 433 | vp[vlen]='\0'; |
|---|
| 434 | rc=recfmt(irec,textbuffsize,vp,tbp,textbuffsize); |
|---|
| 435 | vp[vlen]=k; |
|---|
| 436 | if (rc < 0) fatal("mxget/tagtext/recfmt"); |
|---|
| 437 | } |
|---|
| 438 | txt1vlen=strlen(tbp); |
|---|
| 439 | if (txt1vlen) { txt1vp=tbp; tbp+=txt1vlen; } |
|---|
| 440 | *++tbp='\0'; |
|---|
| 441 | } |
|---|
| 442 | |
|---|
| 443 | pcmdp=strstr(wwwcgip,"^npcmd^v"); |
|---|
| 444 | procp=strstr(wwwcgip,"^nproc^v"); |
|---|
| 445 | pftxp=strstr(wwwcgip,"^npft^v"); |
|---|
| 446 | |
|---|
| 447 | *buffer='\0'; |
|---|
| 448 | |
|---|
| 449 | //default is dump field 1 |
|---|
| 450 | if (!txtvlen) if (!txt1vlen) |
|---|
| 451 | if (!pcmdp) if (!procp) if (!pftxp) { |
|---|
| 452 | int tag=dbtag; |
|---|
| 453 | int occ=dbocc; |
|---|
| 454 | int oc2=dboc2; |
|---|
| 455 | #if 0 |
|---|
| 456 | for (; occ <= oc2; occ++) { |
|---|
| 457 | int xdir,len=0; |
|---|
| 458 | xdir=fieldx(irec,tag,occ); |
|---|
| 459 | if (xdir < 0) break; |
|---|
| 460 | memcpy(buffer,FIELDP(xdir),len=DIRlen(xdir)); buffer[len]='\0'; |
|---|
| 461 | } |
|---|
| 462 | #endif |
|---|
| 463 | int xdir,loop; |
|---|
| 464 | int xocc=0,lastag=0; |
|---|
| 465 | |
|---|
| 466 | if (tag<0) tag=0; |
|---|
| 467 | if (occ<0) occ=0; |
|---|
| 468 | if (oc2<0) oc2=0; |
|---|
| 469 | if (oc2<occ) oc2=occ; |
|---|
| 470 | |
|---|
| 471 | sprintf(buffer+strlen(buffer),"<file name=\"%s\">\n",dbname); |
|---|
| 472 | sprintf(buffer+strlen(buffer),"<record mfn=\"%"_LD_"\" mfrl=\"%"_LD_"\" nvf=\"%d\" status=\"%s\">\n", |
|---|
| 473 | MFRmfn,(LONGX)MFRmfrl,MFRnvf,(MFRstatus == ACTIVE) ? "active" : "deleted"); |
|---|
| 474 | if (MFRstatus == ACTIVE) { |
|---|
| 475 | sprintf(buffer+strlen(buffer),"<fields>\n"); |
|---|
| 476 | for (xdir=0, loop=MFRnvf; loop--; xdir++) { |
|---|
| 477 | int xtag=DIRtag(xdir); |
|---|
| 478 | if (!debug) if (xtag == 2000) continue; |
|---|
| 479 | if (xtag == lastag) xocc++; else { lastag=xtag; xocc=1; } |
|---|
| 480 | if (tag) if (xtag != tag) continue; |
|---|
| 481 | if (occ) if (xocc < occ) continue; |
|---|
| 482 | if (oc2) if (xocc > oc2) continue; |
|---|
| 483 | sprintf(buffer+strlen(buffer),"<field tag=\"%u\" occ=\"%d\">",DIRtag(xdir),xocc); |
|---|
| 484 | memcpy(buffer+strlen(buffer),FIELDP(xdir),DIRlen(xdir)); |
|---|
| 485 | sprintf(buffer+strlen(buffer),"</field>\n"); |
|---|
| 486 | } |
|---|
| 487 | sprintf(buffer+strlen(buffer),"</fields>\n"); |
|---|
| 488 | } |
|---|
| 489 | sprintf(buffer+strlen(buffer),"</record>\n"); |
|---|
| 490 | sprintf(buffer+strlen(buffer),"</file>\n"); |
|---|
| 491 | |
|---|
| 492 | printf("%s",buffer); |
|---|
| 493 | } |
|---|
| 494 | |
|---|
| 495 | np=strstr(wwwcgip,"^npft^v"); |
|---|
| 496 | if (np) { |
|---|
| 497 | for (vlen=0,p=vp=np+7; *p; p++) if (strncmp(p,"H2000 ",6) == 0) break; else vlen++; |
|---|
| 498 | *buffer='\0'; |
|---|
| 499 | if (strncmp(vp,"all",3) == 0) { |
|---|
| 500 | int xdir,loop; |
|---|
| 501 | int xocc=0,lastag=0; |
|---|
| 502 | sprintf(buffer+strlen(buffer),"<file name=\"%s\">\n",dbname); |
|---|
| 503 | sprintf(buffer+strlen(buffer),"<record mfn=\"%"_LD_"\" mfrl=\"%"_LD_"\" nvf=\"%d\" status=\"%s\">\n", |
|---|
| 504 | MFRmfn,(LONGX)MFRmfrl,MFRnvf,(MFRstatus == ACTIVE) ? "active" : "deleted"); |
|---|
| 505 | if (MFRstatus == ACTIVE) { |
|---|
| 506 | sprintf(buffer+strlen(buffer),"<fields>\n"); |
|---|
| 507 | for (xdir=0, loop=MFRnvf; loop--; xdir++) { |
|---|
| 508 | int xtag=DIRtag(xdir); |
|---|
| 509 | if (!debug) if (xtag == 2000) continue; |
|---|
| 510 | if (xtag == lastag) xocc++; else { lastag=xtag; xocc=1; } |
|---|
| 511 | sprintf(buffer+strlen(buffer),"<field tag=\"%u\" occ=\"%d\">",DIRtag(xdir),xocc); |
|---|
| 512 | memcpy(buffer+strlen(buffer),FIELDP(xdir),DIRlen(xdir)); |
|---|
| 513 | sprintf(buffer+strlen(buffer),"</field>\n"); |
|---|
| 514 | } |
|---|
| 515 | sprintf(buffer+strlen(buffer),"</fields>\n"); |
|---|
| 516 | } |
|---|
| 517 | sprintf(buffer+strlen(buffer),"</record>\n"); |
|---|
| 518 | sprintf(buffer+strlen(buffer),"</file>\n"); |
|---|
| 519 | } |
|---|
| 520 | else |
|---|
| 521 | if (isdigit(*vp)) { |
|---|
| 522 | int iocc=1,tag=atoi(vp); |
|---|
| 523 | for (; *recfield(buffer+strlen(buffer),irec,tag,iocc,""); iocc++) { |
|---|
| 524 | strcat(buffer,"\n"); |
|---|
| 525 | } |
|---|
| 526 | } |
|---|
| 527 | else { |
|---|
| 528 | char k=vp[vlen]; |
|---|
| 529 | vp[vlen]='\0'; |
|---|
| 530 | rc=recfmt(irec,buffersize,vp,buffer,buffersize); |
|---|
| 531 | vp[vlen]=k; |
|---|
| 532 | if (rc < 0) fatal("mxget/procs/pft/recfmt"); |
|---|
| 533 | } |
|---|
| 534 | printf("%s\n",buffer); |
|---|
| 535 | } |
|---|
| 536 | |
|---|
| 537 | //check proc.n parms |
|---|
| 538 | |
|---|
| 539 | /* loop throught cgi data pairs ^nproc.n^v[fldupdat_cmds] |
|---|
| 540 | */ |
|---|
| 541 | |
|---|
| 542 | } //end drive mainserver to procs |
|---|
| 543 | |
|---|
| 544 | |
|---|
| 545 | //drive mainserver to wtrig2 |
|---|
| 546 | if (wwwcgip) if (strstr(wwwcgip,"^nwtrig2^von")) { |
|---|
| 547 | |
|---|
| 548 | if (debug) printf("+++ wwwcgip=%s<br />\n",wwwcgip); |
|---|
| 549 | |
|---|
| 550 | // alloc cgi message |
|---|
| 551 | cgimsg=loadfile(NULL,'@',"",NULL,cgimsgsize,'\0'); |
|---|
| 552 | if (!cgimsg) fatal("serc/alloc/cgimsg"); |
|---|
| 553 | x=cgimsg; |
|---|
| 554 | |
|---|
| 555 | /* loop throught cgi data pairs ^nNam^v[Val] |
|---|
| 556 | */ |
|---|
| 557 | // H1.len.^nNam^v[Val] |
|---|
| 558 | // <--y--><---len----> |
|---|
| 559 | for (p=wwwcgip, npairs=0; strncmp(p,"H2000 ",6) == 0; ) { |
|---|
| 560 | |
|---|
| 561 | hhp=p; |
|---|
| 562 | p+=6; y=6; |
|---|
| 563 | for (len=0; isdigit(*p); p++, y++) |
|---|
| 564 | len=10*len+(int)(*p)-(int)'0'; |
|---|
| 565 | p++; y++; |
|---|
| 566 | // ^nNam^v[Val] |
|---|
| 567 | p+=2; |
|---|
| 568 | // Nam^v[Val] |
|---|
| 569 | np=p; |
|---|
| 570 | for (nlen=0; *p; p++) if (*p == SFLDCHR) break; else nlen++; |
|---|
| 571 | // ^v[Val] |
|---|
| 572 | p+=2; |
|---|
| 573 | // [Val] |
|---|
| 574 | vp=p; |
|---|
| 575 | p=hhp+y+len; |
|---|
| 576 | npairs++; |
|---|
| 577 | // |
|---|
| 578 | np[nlen]='\0'; // Nam dlm |
|---|
| 579 | vlen=len-nlen-2-2; // memcpy |
|---|
| 580 | if (debug) printf("+++ pair %d: %s[%d+%d,%d,%d]<br />\n",npairs,hhp,y,len,nlen,vlen); |
|---|
| 581 | if (vlen < 0) fatal("serc/vlen"); |
|---|
| 582 | |
|---|
| 583 | //start wtrig2 parms |
|---|
| 584 | if (strcmp(np,"wtrig2") == 0) { |
|---|
| 585 | wtmsg=x; //trig move parms from now on |
|---|
| 586 | sprintf(x,"wtrig2"); x+=strlen(x); //drive |
|---|
| 587 | continue; |
|---|
| 588 | } |
|---|
| 589 | // text1= text= parms |
|---|
| 590 | if (strcmp(np,"text") == 0) { |
|---|
| 591 | txtvp=vp; txtvlen=vlen; |
|---|
| 592 | continue; |
|---|
| 593 | } |
|---|
| 594 | if (strcmp(np,"text1") == 0) { |
|---|
| 595 | txt1vp=vp; txt1vlen=vlen; |
|---|
| 596 | continue; |
|---|
| 597 | } |
|---|
| 598 | // normalize c= d= parms |
|---|
| 599 | if (strcmp(np,"c") == 0 || strcmp(np,"collection") == 0) { |
|---|
| 600 | np="c"; |
|---|
| 601 | if (vlen) if (strstr(vp,"^p")) { |
|---|
| 602 | char *p=strstr(vp,"^p")+2; |
|---|
| 603 | port=(uint16_t)atoi(p); |
|---|
| 604 | vlen-=2; for (; isdigit(*p); p++) vlen--; |
|---|
| 605 | } |
|---|
| 606 | } |
|---|
| 607 | if (strcmp(np,"d") == 0 || strcmp(np,"document") == 0) { |
|---|
| 608 | np="d"; |
|---|
| 609 | } |
|---|
| 610 | //move wtrig2/other parms - w2p0.c now discart non-w2 parms |
|---|
| 611 | if (wtmsg) { |
|---|
| 612 | if (!vlen) { sprintf(x," %s" ,np); x+=strlen(x); } |
|---|
| 613 | else { sprintf(x," %s=",np); x+=strlen(x); memcpy(x,vp,vlen); x+=vlen; } |
|---|
| 614 | } |
|---|
| 615 | else if (debug) printf("+++ pair %d: %s[%d+%d,%d,%d] - ignored <br />\n",npairs,hhp,y,len,nlen,vlen); |
|---|
| 616 | |
|---|
| 617 | } // end loop |
|---|
| 618 | |
|---|
| 619 | *x='\0'; |
|---|
| 620 | if (*p) fatal("serc/wwwcgip"); |
|---|
| 621 | |
|---|
| 622 | } //end drive mainserver to wtrig2 |
|---|
| 623 | |
|---|
| 624 | } /* end if !parmwtmsg */ |
|---|
| 625 | |
|---|
| 626 | |
|---|
| 627 | |
|---|
| 628 | /* Run |
|---|
| 629 | */ |
|---|
| 630 | *buffer='\0'; |
|---|
| 631 | |
|---|
| 632 | // drive mainserver to wtrig2 |
|---|
| 633 | if (parmwtmsg || wtmsg) { |
|---|
| 634 | |
|---|
| 635 | int cmd=debug; |
|---|
| 636 | char *message=parmwtmsg; |
|---|
| 637 | int maxrds=1; |
|---|
| 638 | |
|---|
| 639 | if (wtmsg) { //cgi overrides parms! |
|---|
| 640 | char *x=wtmsg+strlen(wtmsg); |
|---|
| 641 | message=wtmsg; |
|---|
| 642 | if (txt1vlen) { |
|---|
| 643 | sprintf(x," text1="); x+=strlen(x); memcpy(x,txt1vp,txt1vlen); x+=txt1vlen; *x='\0'; |
|---|
| 644 | } |
|---|
| 645 | if (txtvlen) { |
|---|
| 646 | sprintf(x," text=" ); x+=strlen(x); memcpy(x,txtvp,txtvlen); x+=txtvlen; *x='\0'; |
|---|
| 647 | } |
|---|
| 648 | } /* end wtmsg */ |
|---|
| 649 | |
|---|
| 650 | if (debug) printf("serc: message=%s<br />\n",message); |
|---|
| 651 | if (message) { |
|---|
| 652 | if (debug || cmd >= 3) printf("serc: \"%s\" %s %d [%d read]\n",message,serverhost,port,maxrds); |
|---|
| 653 | rc=mainclient(cmd, "X1417", serverhost, port, message, buffer, buffersize, maxrds); |
|---|
| 654 | if (debug || cmd >= 3) if (rc < 0) printf("serc: failure %d \n", rc); |
|---|
| 655 | } |
|---|
| 656 | |
|---|
| 657 | } /* end parmwtmsg || wtmsg */ |
|---|
| 658 | |
|---|
| 659 | |
|---|
| 660 | |
|---|
| 661 | /* get secs_ for elapsed */ |
|---|
| 662 | secs_end=time(&secs_now); |
|---|
| 663 | |
|---|
| 664 | #if MX_SERX |
|---|
| 665 | |
|---|
| 666 | #if MXFUN |
|---|
| 667 | char *p; |
|---|
| 668 | int iarg; |
|---|
| 669 | for (p=area, iarg=1; iarg<argc; iarg++) { |
|---|
| 670 | strcpy(p,argv[iarg]); p+=strlen(p); if (iarg<argc-1) *p++='\n'; |
|---|
| 671 | } |
|---|
| 672 | *p='\0'; |
|---|
| 673 | rc=cisis_mx(area...); |
|---|
| 674 | #else /* MXFUN */ |
|---|
| 675 | rc=mxexec(argc,argv...); |
|---|
| 676 | #endif /* MXFUN */ |
|---|
| 677 | exit(rc); |
|---|
| 678 | |
|---|
| 679 | #else //MX_SERX |
|---|
| 680 | |
|---|
| 681 | //reply.. |
|---|
| 682 | if (outfmthtml) { |
|---|
| 683 | printf("%s",buffer); |
|---|
| 684 | } else { |
|---|
| 685 | printf("%s",buffer); |
|---|
| 686 | printf("</request>\n"); |
|---|
| 687 | printf("<elapsed>%"_LD_"</elapsed>\n",(LONGX)secs_end-secs_start); |
|---|
| 688 | } |
|---|
| 689 | |
|---|
| 690 | // reply trailer |
|---|
| 691 | if (outfmthtml) |
|---|
| 692 | printf("</pre></body></html>\n"); |
|---|
| 693 | else |
|---|
| 694 | printf("</serc>\n"); |
|---|
| 695 | |
|---|
| 696 | #endif //MX_SERX |
|---|
| 697 | |
|---|
| 698 | /* release working areas |
|---|
| 699 | */ |
|---|
| 700 | //if (databuff) FREE(databuff); |
|---|
| 701 | //if (textbuff) FREE(textbuff); |
|---|
| 702 | //if (buffer) FREE(buffer); |
|---|
| 703 | //if (cgimsg) FREE(cgimsg); |
|---|
| 704 | //if (wwwcgip) FREE(wwwcgip); |
|---|
| 705 | |
|---|
| 706 | /* Done |
|---|
| 707 | */ |
|---|
| 708 | return 0; |
|---|
| 709 | } |
|---|
| 710 | |
|---|
| 711 | /* |
|---|
| 712 | */ |
|---|