| 1 | |
|---|
| 2 | |
|---|
| 3 | /* Begin PROCXSOCKREC |
|---|
| 4 | */ |
|---|
| 5 | #if PROCXSOCKREC |
|---|
| 6 | |
|---|
| 7 | if ( (strncmp(p,"load=",5) == 0 || strncmp(p,"load/",5) == 0) /* |
|---|
| 8 | && (strstr(p,"/socket=") || strstr(p,"/socket/") */ ) { |
|---|
| 9 | |
|---|
| 10 | LONGX xtag=1; |
|---|
| 11 | int xtagzero=0; |
|---|
| 12 | int parmsocket=0; |
|---|
| 13 | int parmcmd=0; |
|---|
| 14 | int parmhead=0; |
|---|
| 15 | char *filnamp=NULL; |
|---|
| 16 | |
|---|
| 17 | int parm0=0; //1; // strip 0D |
|---|
| 18 | int parm1=0; // strip 0A |
|---|
| 19 | int parmprint=0; |
|---|
| 20 | FILE *parmfp=stdout; |
|---|
| 21 | |
|---|
| 22 | char *xarea=NULL; |
|---|
| 23 | LONGX nbytes; |
|---|
| 24 | char *q; |
|---|
| 25 | |
|---|
| 26 | char *haddp=NULL; |
|---|
| 27 | char *hlenp=NULL; |
|---|
| 28 | char *hdatap=NULL; |
|---|
| 29 | LONGX hlen=0; |
|---|
| 30 | |
|---|
| 31 | char *protocol; |
|---|
| 32 | char *serverhost; |
|---|
| 33 | uint16_t port; |
|---|
| 34 | char *docpathp; |
|---|
| 35 | |
|---|
| 36 | int maxrds=INT_MAX; |
|---|
| 37 | int xport=0; |
|---|
| 38 | |
|---|
| 39 | char *dbname; |
|---|
| 40 | LONGX mfn; |
|---|
| 41 | char *key; |
|---|
| 42 | |
|---|
| 43 | char *msgp; |
|---|
| 44 | int rc; |
|---|
| 45 | |
|---|
| 46 | int dbx; |
|---|
| 47 | int ndbx=3; |
|---|
| 48 | char *vdbname[] = { |
|---|
| 49 | "lilacs", |
|---|
| 50 | "artigo", |
|---|
| 51 | "citacoes", |
|---|
| 52 | }; |
|---|
| 53 | char *vdbserver[] = { |
|---|
| 54 | "bases.bireme.br", |
|---|
| 55 | "www.scielo.br", |
|---|
| 56 | "serverofi.bireme.br", |
|---|
| 57 | }; |
|---|
| 58 | int vdbport[] = { |
|---|
| 59 | 1417, |
|---|
| 60 | 1417, |
|---|
| 61 | 1417 |
|---|
| 62 | }; |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | /* scan parms |
|---|
| 66 | */ |
|---|
| 67 | p+=4; /* skip load */ |
|---|
| 68 | while (*p == '/') { /* /<tag>/socket */ |
|---|
| 69 | p++; |
|---|
| 70 | if (isdigit(*p)) { /* /<tag> */ |
|---|
| 71 | if (*p=='0') xtagzero=1; // allow tag /0n |
|---|
| 72 | for (xtag=0; isdigit(*p); p++ ) xtag=xtag*10+((int)(*p)-(int)'0'); |
|---|
| 73 | if (xtag < 1) fatal("fldupdat/procx/Gload/tag"); |
|---|
| 74 | if (*p=='/' || *p=='='); else fatal("fldupdat/procx/Gload/tag dlm"); |
|---|
| 75 | /* |
|---|
| 76 | if (sscanf(p,"%"_LD_,&xtag) != 1) fatal("fldupdat/procx/Gload/socket/tag"); |
|---|
| 77 | while (isdigit(*p)) p++; |
|---|
| 78 | */ |
|---|
| 79 | } else |
|---|
| 80 | if (strncmp(p,"no0D=",5) == 0 || strncmp(p,"no0D/",5) == 0 || /* /no0D */ |
|---|
| 81 | strncmp(p,"noCR=",5) == 0 || strncmp(p,"noCR/",5) == 0) { /* /noCR */ |
|---|
| 82 | p+=4; |
|---|
| 83 | parm0=1; |
|---|
| 84 | } else |
|---|
| 85 | if (strncmp(p,"no0A=",5) == 0 || strncmp(p,"no0A/",5) == 0 || /* /no0A */ |
|---|
| 86 | strncmp(p,"noLF=",5) == 0 || strncmp(p,"noLF/",5) == 0) { /* /noLF */ |
|---|
| 87 | p+=4; |
|---|
| 88 | parm1=1; |
|---|
| 89 | } else |
|---|
| 90 | if (strncmp(p,"line=",5) == 0 || strncmp(p,"line/",5) == 0 || /* /line */ |
|---|
| 91 | strncmp(p,"nonl=",5) == 0 || strncmp(p,"nonl/",5) == 0) { /* /nonl */ |
|---|
| 92 | p+=4; |
|---|
| 93 | parm0=parm1=1; |
|---|
| 94 | } else |
|---|
| 95 | if (strncmp(p,"socket=",7) == 0 || strncmp(p,"socket/",7) == 0) { /* /socket */ |
|---|
| 96 | p+=6; |
|---|
| 97 | parmsocket=1; |
|---|
| 98 | } else |
|---|
| 99 | if (strncmp(p,"head=",5) == 0 || strncmp(p,"head/",5) == 0) { /* /head */ |
|---|
| 100 | p+=4; |
|---|
| 101 | parmhead=1; |
|---|
| 102 | } else |
|---|
| 103 | if (strncmp(p,"xml=",4) == 0 || strncmp(p,"xml/",4) == 0) { /* /xml */ |
|---|
| 104 | p+=3; |
|---|
| 105 | parmcmd=1; |
|---|
| 106 | } else |
|---|
| 107 | if (strncmp(p,"tell=",5) == 0 || strncmp(p,"tell/",5) == 0) { /* /tell */ |
|---|
| 108 | p+=4; |
|---|
| 109 | parmcmd=2; |
|---|
| 110 | } else |
|---|
| 111 | if (strncmp(p,"trace=",6) == 0 || strncmp(p,"trace/",6) == 0) { /* /trace */ |
|---|
| 112 | p+=5; |
|---|
| 113 | parmcmd=3; |
|---|
| 114 | } else |
|---|
| 115 | fatal("fldupdat/procx/Gload[/<tag>][/nolf][/xml][/socket][/head][={<url>|<file>}]"); |
|---|
| 116 | //+ Gmark[/<tag>] |
|---|
| 117 | //fatal("fldupdat/procx/Gload/socket/option"); |
|---|
| 118 | } /* while /x */ |
|---|
| 119 | if (*p == '=') p++; /* <file> | <url> */ |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | /* alloc working area |
|---|
| 123 | */ |
|---|
| 124 | nbytes=(rec_maxmfrl>MAXMFRL)?rec_maxmfrl:MAXMFRL; |
|---|
| 125 | if (nbytes < MFRmfrl) nbytes=MFRmfrl; |
|---|
| 126 | nbytes+=BUFSIZ; /* buffup */ /* nbytes=MFRmfrl+MFRmfrl+BUFSIZ; */ |
|---|
| 127 | #if CICPP |
|---|
| 128 | try { xarea = (char *) new char [nbytes]; } |
|---|
| 129 | catch (BAD_ALLOC) { xarea = (char *)ALLONULL; } |
|---|
| 130 | #else /* CICPP */ |
|---|
| 131 | xarea=(char *)ALLOC((ALLOPARM)nbytes); |
|---|
| 132 | #endif /* CICPP */ |
|---|
| 133 | if (xarea == (char *)ALLONULL) fatal("fldupdat/procx/Gload/socket/ALLOC"); |
|---|
| 134 | *xarea='\0'; |
|---|
| 135 | |
|---|
| 136 | q=xarea; /* batchp */ |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | /* del/add command |
|---|
| 140 | */ |
|---|
| 141 | if (!xtagzero) sprintf(q,"D%"_LD_,xtag); |
|---|
| 142 | else sprintf(q,"D*"); q+=strlen(q); // exec tag /0n |
|---|
| 143 | |
|---|
| 144 | sprintf(haddp=q,"H%09"_LD_" ",(xtag)?(LONGX)xtag:1L); q+=strlen(q); |
|---|
| 145 | sprintf(hlenp=q,"123456789 "); q+=strlen(q); |
|---|
| 146 | hdatap=q; |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | if (parmsocket) { /* ./mx null "proc='Gload/socket=http://www.bireme.br:80/'" */ |
|---|
| 150 | |
|---|
| 151 | /* scan <url> |
|---|
| 152 | */ |
|---|
| 153 | protocol="HTTP"; |
|---|
| 154 | q=strstr(p,"://"); /* http:// */ |
|---|
| 155 | if (q) { |
|---|
| 156 | char *x; |
|---|
| 157 | int len; |
|---|
| 158 | *q='\0'; len=strlen(p); |
|---|
| 159 | if (len < 8) { |
|---|
| 160 | protocol=p; /* http | x1417*/ |
|---|
| 161 | for (x=p; *x; x++) *x=toupper(*x); |
|---|
| 162 | p=q+3; |
|---|
| 163 | } |
|---|
| 164 | else *q=':'; |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | serverhost=p; /* www.bireme.br | serverofi.bireme.br */ |
|---|
| 168 | |
|---|
| 169 | docpathp=strchr(p+1,'/'); /* /docpath | /dbname/parms */ |
|---|
| 170 | if (docpathp) *docpathp='\0'; |
|---|
| 171 | else docpathp="/"; |
|---|
| 172 | |
|---|
| 173 | port=80; /* :80 */ |
|---|
| 174 | q=strchr(p,':'); |
|---|
| 175 | if (q) { |
|---|
| 176 | *q='\0'; |
|---|
| 177 | if (sscanf(q+1,"%d",&xport) == 1) port=xport; /* :80 | :1417 */ |
|---|
| 178 | else xport=0; /*fatal("fldupdat/procx/Gload/socket/port");*/ |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | /* X1417://serverofi.bireme.br:1417/msg |
|---|
| 182 | /dbname/control/maxmfn |
|---|
| 183 | /dbname/text/mfn/mfn2/count/step |
|---|
| 184 | /dbname/dict/key/key2/contains/count |
|---|
| 185 | /dbname/bool/expression |
|---|
| 186 | /dbname/rank/text |
|---|
| 187 | */ |
|---|
| 188 | if (strcmp(protocol,"X1417") == 0) { |
|---|
| 189 | maxrds=1; /* single read */ |
|---|
| 190 | if (!xport) port=1417; /* :1417 */ |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | msgp=hdatap; |
|---|
| 194 | *msgp='\0'; |
|---|
| 195 | if (strcmp(protocol,"X1417") == 0) { |
|---|
| 196 | sprintf(msgp,"%s\n",docpathp+1); |
|---|
| 197 | } |
|---|
| 198 | else |
|---|
| 199 | if (strcmp(protocol,"HTTP") == 0) { |
|---|
| 200 | sprintf(msgp,"%s /%s HTTP/1.0\r\n\r\n",(parmhead)?"HEAD":"GET",docpathp+1); |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | if (*msgp) rc = mainclient( parmcmd, msgp, serverhost, port, hdatap, nbytes-strlen(xarea), maxrds); |
|---|
| 204 | |
|---|
| 205 | } |
|---|
| 206 | else { /* else parmsocket: <file> */ |
|---|
| 207 | |
|---|
| 208 | filnamp=p; |
|---|
| 209 | p+=strlen(p); |
|---|
| 210 | |
|---|
| 211 | rc = mainfile ( parmcmd, filnamp, parm0, parm1, hdatap, nbytes-strlen(xarea) ); |
|---|
| 212 | |
|---|
| 213 | } /* end parmsocket */ |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | if (rc < 0) { |
|---|
| 218 | sprintf(hdatap,"Gload%s error %d",parmsocket?"/socket":"",(-rc)); |
|---|
| 219 | hlen=strlen(hdatap); |
|---|
| 220 | } |
|---|
| 221 | else hlen=rc; |
|---|
| 222 | |
|---|
| 223 | if (hlen) { |
|---|
| 224 | /* actual add lenght */ |
|---|
| 225 | sprintf(hlenp,"%9"_LD_,(LONGX)hlen); hlenp[9]=' '; |
|---|
| 226 | /* print */ |
|---|
| 227 | if (parmprint) fprintf(parmfp,"%s",hdatap); |
|---|
| 228 | } |
|---|
| 229 | else if (haddp) *haddp='\0'; |
|---|
| 230 | |
|---|
| 231 | #if CICPP |
|---|
| 232 | if (recp->xfldupdat(xarea)) fatal(errp); |
|---|
| 233 | delete xarea; |
|---|
| 234 | #else /* CICPP */ |
|---|
| 235 | if (fldupdat(irec,xarea)) fatal(errp); |
|---|
| 236 | if (xarea) FREE(xarea); |
|---|
| 237 | #endif /* CICPP */ |
|---|
| 238 | |
|---|
| 239 | return NULL; //isgdump=1; |
|---|
| 240 | |
|---|
| 241 | } /* end Gload/socket */ |
|---|
| 242 | else |
|---|
| 243 | |
|---|
| 244 | #endif /* PROCXSOCKREC */ |
|---|
| 245 | /* End PROCXSOCKREC |
|---|
| 246 | */ |
|---|
| 247 | |
|---|