DBROWSER.CPP
上传用户:zdlsnail
上传日期:2007-01-06
资源大小:16k
文件大小:9k
- #define MAXCONNECT 10
- #define MAXBUFFER 100000
- #define MAXCONNECTID 200
- #define MAXUSER 1000
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- //#include <malloc.h>
- #include <ole2ver.h>
- #include <ole2.h>
- #include <httpext.h>
- #include <sqlext.h>
-
- //#include <odbcinst.h>
- #include "chcode.h"
- #include "sqlprog.h"
- #include "myole.h"
- DWORD dwBytesWritten;
-
- //------------------------------------------
- short dog() {
- short i;
- i=0;
- _asm {
- mov dx,037ah
- mov ax,00ffh
- out dx,ax
- dec dx
- dec dx
- mov ax,0010h
- out dx,ax
- inc dx
- in ax,dx
- test al,010h
- jnz g150
- dec dx
- mov ax,0030h
- out dx,ax
- inc dx
- in ax,dx
- test al,010h
- jnz g150
- dec dx
- mov ax,0070h
- out dx,ax
- inc dx
- in ax,dx
- test al,010h
- jz g150
- inc dx
- mov ax,0
- out dx,ax
- mov ax,1
- mov i,ax
- jmp g160
- g150:
- mov dx,027ah
- mov ax,00ffh
- out dx,ax
- dec dx
- dec dx
- mov ax,0010h
- out dx,ax
- inc dx
- in ax,dx
- test al,010h
- jnz g155
- dec dx
- mov ax,0030h
- out dx,ax
- inc dx
- in ax,dx
- test al,010h
- jnz g155
- dec dx
- mov ax,0070h
- out dx,ax
- inc dx
- in ax,dx
- test al,010h
- jz g155
- inc dx
- mov ax,0
- out dx,ax
- mov ax,1
- mov i,ax
- jmp g160
- g155: mov ax,0
- mov i,ax
- g160: mov ax,1
- }
- return i;};
- //------------------------------
- void WriteHtml(EXTENSION_CONTROL_BLOCK *pECB,LPSTR lpsz)
- {
- dwBytesWritten=lstrlen(lpsz);
- pECB->WriteClient(pECB->ConnID,(PVOID)lpsz,&dwBytesWritten,0);}
- //------------------------------
- BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD dwreason,LPVOID lpv)
- {
- return(TRUE);}
- //------------------------------
- BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *version)
- {
- short i;
- RETCODE retcode;
- version->dwExtensionVersion=MAKELONG(HSE_VERSION_MINOR,
- HSE_VERSION_MAJOR);
- version->lpszExtensionDesc[0]=' ';
- retcode=SQLAllocEnv(&henv);
- if(retcode!=SQL_SUCCESS) return(FALSE);
- for(i=0;i<MAXCONNECT;i++) {
- connectStru[i].ID=0;
- connectStru[i].usermark=0;
- connectStru[i].hdbc=SQL_NULL_HDBC;}
- return(TRUE);}
- //------------------------------
- DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB)
- {
- }
- abcd(unsigned char *requeststring)
- {
- short i,j,k,wwmark;
- int connectID,funMark;
- //unsigned char requeststring[20000];
- EXTENSION_CONTROL_BLOCK *pECB;
- unsigned char *ptr,*returnstring,*tmpstr;
- long dwBytesRead;
- UCHAR FAR userName[30],passWord[30],dwLib[30],dwName[30],
- tmpdw[30],dateString[16];
- BOOL errorUpdate;
- /*WriteHtml(pECB,
- "HTTP/1.0, 200 OKrnContent-type: text/htmlrnrn");
- if(stricmp(pECB->lpszMethod,"GET")==0)
- strcpy(requeststring,pECB->lpszQueryString);
- else {
- dwBytesRead=20000;
- pECB->ReadClient(pECB->ConnID,(PVOID)requeststring,&dwBytesRead);}
- k=10000;
- while(TRUE) {
- i=0;
- while(i<MAXCONNECT) {
- if(connectStru[i].usermark==0) {
- k=i;break;}
- i++;}
- if(k==10000) Sleep(1000);
- else returnstring=malloc(MAXBUFFER);
- if(returnstring==NULL) {
- WriteHtml(pECB,"ERROR002");return(HSE_STATUS_SUCCESS);}
- else break;}
- */
- tmpstr=&requeststring[0];
- connectID=0;
- if(strlen(tmpstr)==0) {WriteHtml(pECB,"ERROR001");goto fail1;}
- ptr=strchr(tmpstr,'=');
- if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
- *ptr=' ';ptr++;funMark=0;
- if(stricmp(tmpstr,"sqlselect")==0) funMark=1;
- if(stricmp(tmpstr,"sqlupdate")==0) funMark=2;
- if(stricmp(tmpstr,"readwindow")==0) funMark=3;
- if(stricmp(tmpstr,"readall")==0) funMark=4;
- if(funMark==0) {WriteHtml(pECB,"ERROR001");goto fail1;}
- tmpstr=ptr;
- if((funMark==1)||(funMark==2)) {
- for(j=k;i<MAXCONNECT;i++) {
- if((connectStru[j].ID==connectID)&&
- (connectStru[j].usermark==0)) {
- k=j;break;}}
- ptr=strchr(tmpstr,'t');
- if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
- *ptr=' ';strcpy(userName,tmpstr);
- tmpstr=ptr+1;
- ptr=strchr(tmpstr,'t');
- if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
- *ptr=' ';strcpy(passWord,tmpstr);
- tmpstr=ptr+1;ptr=strchr(tmpstr,'t');
- if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
- *ptr=' ';connectID=atoi(tmpstr);
- tmpstr=ptr+1;ptr=strchr(tmpstr,'t');
- if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
- *ptr=' ';strcpy(dwLib,tmpstr);
- tmpstr=ptr+1;ptr=strchr(tmpstr,'t');
- if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
- *ptr=' ';strcpy(dwName,tmpstr);
- tmpstr=ptr+1;strcpy(connectStru[k].dwLib,dwLib);
- strcpy(connectStru[k].dwName,dwName);
- strcpy(connectStru[k].UID,userName);
- strcpy(connectStru[k].PASSWORD,passWord);}
- connectStru[k].returnstring=returnstring;
- connectStru[k].pECB=pECB;
- connectStru[k].usermark=1;
- switch(funMark) {
- case 1:
- if(connectID!=connectStru[k].ID) {
- if(makeConnect(k,connectID)==FALSE) {
- strcpy(tmpstr,connectStru[k].DSN);
- strcat(tmpstr,connectStru[k].UID);
- strcat(tmpstr,connectStru[k].PASSWORD);
- WriteHtml(pECB,tmpstr);
- WriteHtml(pECB,"ERROR003");goto end1;}
- else {
- sqlSelectFun(k,tmpstr);
- break;}}
- else {sqlSelectFun(k,tmpstr);break;}
- case 2:
- ptr=strchr(tmpstr,'t');
- if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto end1;}
- *ptr=' ';
- if(stricmp(tmpstr,"YES")==0) errorUpdate=TRUE;
- else errorUpdate=FALSE;
- connectStru[k].errorUpdate=errorUpdate;
- tmpstr=ptr+1;
- if(connectID!=connectStru[k].ID) {
- if(makeConnect(k,connectID)==FALSE) {
- WriteHtml(pECB,"ERROR003");goto end1;}
- else {
- sqlUpdateFun(k,tmpstr);break;}}
- else {
- sqlUpdateFun(k,tmpstr);break;}
- case 3:
- ptr=strchr(tmpstr,'t');
- if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
- *ptr=' ';strcpy(userName,tmpstr);
- tmpstr=ptr+1;
- ptr=strchr(tmpstr,'t');
- if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
- *ptr=' ';strcpy(passWord,tmpstr);
- tmpstr=ptr+1;ptr=strchr(tmpstr,'t');
- if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
- *ptr=' ';strcpy(dwName,tmpstr);
- tmpstr=ptr+1;ptr=strchr(tmpstr,'t');
- if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
- *ptr=' ';strcpy(dateString,tmpstr);
- if(UserPass(tmpdw,dwLib,userName,passWord)==FALSE) {
- WriteHtml(pECB,"ERROR005");goto fail1;}
- if(strlen(dwName)==0) {wwmark=0;strcpy(dwName,tmpdw);}
- else wwmark=1;
- readWinInfo(dwLib,dwName,dateString,wwmark,k);
- break;
- case 4:break;}
- end1:
- connectStru[k].usermark=0;
- free(connectStru[k].returnstring);
- return(HSE_STATUS_SUCCESS);
- fail1:
- free(returnstring);
- return(HSE_STATUS_SUCCESS);}
- //------------------------------------------
- main()
- {
- long i,ID;
- long len;
- size_t len1;
- FILE *fp;
- abcd("readwindow=dbatsqlt19970809121314t19970203121324t");
- return(1);}
- /*
- i=MAX_CODE;
- ID=TABLE_BANKS;
- strcpy(connectStru[0].DSN,"foxtest");
- strcpy(connectStru[0].dataDir,"C:\DBROWSER\");
- Http(
- "sqlselect=dbatsqlt1treport.pblttestttselectt*tfromtgpinfo");
- return(1);
- Http(
- "sqlupdate=dbatsqlt1treport.pblttesttYEStinserttintotgpinfo(ccode,gpname)tvalues(1234,'abcd');inserttintotgpinfo(ccode,gpname)tvalues(123534,'a4bcd');");
- return(1);
- for(i=0;i<MAXCONNECT;i++) {
- connectStru[i].ID=0;
- connectStru[i].usermark=0;
- connectStru[i].henv=SQL_NULL_HENV;
- connectStru[i].hdbc=SQL_NULL_HDBC;
- }
- strcpy(connectStru[1].DSN,"fox");
- strcpy(connectStru[1].UID,"DBA");
- strcpy(connectStru[1].PASSWORD,"SQL");
- strcpy(connectStru[1].dataDir,"C:\DBROWSER\");
- connectStru[1].returnstring=malloc(1000000);
- if(connectStru[1].returnstring!=NULL) {
- ID=1;
- len=lstrlen(connectStru[1].returnstring);
- // len=compress_code(connectStru[1].returnstring,len);
- // len=uncode_expand(connectStru[1].returnstring,len);
- fp=fopen("c:\dbrowser\test.txt","w");
- len1=fwrite(connectStru[1].returnstring,1l,len,fp);
- fclose(fp);
- free(connectStru[1].returnstring);
- len=len;}
- return 1; }
- */