DBROWSER.CPP
上传用户:zdlsnail
上传日期:2007-01-06
资源大小:16k
文件大小:9k
源码类别:

压缩解压

开发平台:

Visual C++

  1. #define MAXCONNECT 10
  2. #define MAXBUFFER 100000 
  3. #define MAXCONNECTID 200
  4. #define MAXUSER 1000
  5. #include <string.h>        
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <windows.h>    
  9. //#include <malloc.h>
  10. #include <ole2ver.h>
  11. #include <ole2.h>
  12. #include <httpext.h>
  13. #include <sqlext.h>
  14. //#include <odbcinst.h>
  15. #include "chcode.h"
  16. #include "sqlprog.h"
  17. #include "myole.h"
  18. DWORD dwBytesWritten;
  19.   
  20. //------------------------------------------
  21. short dog() {
  22. short i; 
  23. i=0;
  24.    _asm {
  25.          mov dx,037ah
  26.           mov ax,00ffh
  27.           out dx,ax
  28.           dec dx
  29.           dec dx
  30.           mov ax,0010h
  31.           out dx,ax
  32.           inc dx
  33.           in ax,dx 
  34.           test al,010h
  35.           jnz g150
  36.           dec dx
  37.           mov ax,0030h
  38.           out dx,ax
  39.           inc dx
  40.           in ax,dx
  41.           test al,010h
  42.           jnz g150
  43.           dec dx
  44.           mov ax,0070h
  45.           out dx,ax
  46.           inc dx
  47.           in ax,dx 
  48.           test al,010h
  49.           jz g150
  50.           inc dx
  51.           mov ax,0
  52.           out dx,ax
  53.           mov ax,1
  54.           mov i,ax   
  55.           jmp g160
  56.    g150:  
  57.           mov dx,027ah
  58.           mov ax,00ffh
  59.           out dx,ax
  60.           dec dx
  61.           dec dx
  62.           mov ax,0010h
  63.           out dx,ax
  64.           inc dx
  65.           in ax,dx 
  66.           test al,010h
  67.           jnz g155
  68.           dec dx
  69.           mov ax,0030h
  70.           out dx,ax
  71.           inc dx
  72.           in ax,dx
  73.           test al,010h
  74.           jnz g155
  75.           dec dx
  76.           mov ax,0070h
  77.           out dx,ax
  78.           inc dx
  79.           in ax,dx 
  80.           test al,010h
  81.           jz g155
  82.           inc dx
  83.           mov ax,0
  84.           out dx,ax
  85.           mov ax,1
  86.           mov i,ax   
  87.           jmp g160
  88.    g155:  mov ax,0
  89.           mov i,ax   
  90.    g160:  mov ax,1
  91.          }
  92.       return i;};
  93. //------------------------------
  94. void WriteHtml(EXTENSION_CONTROL_BLOCK *pECB,LPSTR lpsz)
  95.   {
  96. dwBytesWritten=lstrlen(lpsz);
  97. pECB->WriteClient(pECB->ConnID,(PVOID)lpsz,&dwBytesWritten,0);}
  98. //------------------------------
  99. BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD dwreason,LPVOID lpv)
  100. {
  101.   return(TRUE);}
  102. //------------------------------
  103. BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *version)
  104. {
  105.   short i;
  106.   RETCODE retcode;
  107.   version->dwExtensionVersion=MAKELONG(HSE_VERSION_MINOR,
  108. HSE_VERSION_MAJOR);
  109.   version->lpszExtensionDesc[0]='';
  110.   retcode=SQLAllocEnv(&henv);
  111.   if(retcode!=SQL_SUCCESS) return(FALSE);
  112.   for(i=0;i<MAXCONNECT;i++) {
  113.     connectStru[i].ID=0;
  114.     connectStru[i].usermark=0;
  115.     connectStru[i].hdbc=SQL_NULL_HDBC;}
  116.   return(TRUE);}
  117. //------------------------------
  118. DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB)
  119. {
  120. }
  121. abcd(unsigned char *requeststring)
  122.   {
  123.   short i,j,k,wwmark;
  124.   int connectID,funMark;
  125.   //unsigned char requeststring[20000];
  126.   EXTENSION_CONTROL_BLOCK *pECB;
  127.   unsigned char *ptr,*returnstring,*tmpstr;
  128.   long dwBytesRead;
  129.   UCHAR FAR userName[30],passWord[30],dwLib[30],dwName[30],
  130. tmpdw[30],dateString[16];
  131.   BOOL errorUpdate;
  132.   /*WriteHtml(pECB,
  133.     "HTTP/1.0, 200 OKrnContent-type: text/htmlrnrn");
  134.   if(stricmp(pECB->lpszMethod,"GET")==0)  
  135.    strcpy(requeststring,pECB->lpszQueryString);
  136.   else {
  137.     dwBytesRead=20000;
  138.     pECB->ReadClient(pECB->ConnID,(PVOID)requeststring,&dwBytesRead);}
  139.   k=10000;
  140.   while(TRUE) {
  141. i=0;
  142.     while(i<MAXCONNECT) {
  143.       if(connectStru[i].usermark==0) {
  144.     k=i;break;}
  145.       i++;}
  146.     if(k==10000) Sleep(1000);
  147. else returnstring=malloc(MAXBUFFER);
  148.     if(returnstring==NULL) {
  149.        WriteHtml(pECB,"ERROR002");return(HSE_STATUS_SUCCESS);}
  150. else break;}
  151. */
  152.   tmpstr=&requeststring[0];
  153.   connectID=0;
  154.   if(strlen(tmpstr)==0) {WriteHtml(pECB,"ERROR001");goto fail1;}
  155.   ptr=strchr(tmpstr,'=');
  156.   if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
  157.   *ptr='';ptr++;funMark=0;
  158.   if(stricmp(tmpstr,"sqlselect")==0) funMark=1;
  159.   if(stricmp(tmpstr,"sqlupdate")==0) funMark=2;
  160.   if(stricmp(tmpstr,"readwindow")==0) funMark=3;
  161.   if(stricmp(tmpstr,"readall")==0) funMark=4;
  162.   if(funMark==0) {WriteHtml(pECB,"ERROR001");goto fail1;}
  163.   tmpstr=ptr;
  164.   if((funMark==1)||(funMark==2)) {
  165.     for(j=k;i<MAXCONNECT;i++) {
  166.       if((connectStru[j].ID==connectID)&&
  167.   (connectStru[j].usermark==0)) {
  168.       k=j;break;}}
  169.     ptr=strchr(tmpstr,'t');
  170. if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
  171.     *ptr='';strcpy(userName,tmpstr);
  172. tmpstr=ptr+1;
  173.     ptr=strchr(tmpstr,'t');
  174.     if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
  175.     *ptr='';strcpy(passWord,tmpstr);
  176. tmpstr=ptr+1;ptr=strchr(tmpstr,'t');
  177. if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
  178.     *ptr='';connectID=atoi(tmpstr);
  179. tmpstr=ptr+1;ptr=strchr(tmpstr,'t');
  180.     if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
  181. *ptr='';strcpy(dwLib,tmpstr);
  182. tmpstr=ptr+1;ptr=strchr(tmpstr,'t');
  183. if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
  184.     *ptr='';strcpy(dwName,tmpstr);
  185. tmpstr=ptr+1;strcpy(connectStru[k].dwLib,dwLib);
  186.     strcpy(connectStru[k].dwName,dwName);
  187.     strcpy(connectStru[k].UID,userName);
  188.     strcpy(connectStru[k].PASSWORD,passWord);}
  189.   connectStru[k].returnstring=returnstring;
  190.   connectStru[k].pECB=pECB;
  191.   connectStru[k].usermark=1;
  192.   switch(funMark) {
  193.     case 1:
  194.       if(connectID!=connectStru[k].ID) {
  195.     if(makeConnect(k,connectID)==FALSE) {
  196.   strcpy(tmpstr,connectStru[k].DSN);
  197.   strcat(tmpstr,connectStru[k].UID);
  198.   strcat(tmpstr,connectStru[k].PASSWORD);
  199.   WriteHtml(pECB,tmpstr);
  200.   WriteHtml(pECB,"ERROR003");goto end1;}
  201.     else {
  202.   sqlSelectFun(k,tmpstr);
  203.   break;}}
  204.   else {sqlSelectFun(k,tmpstr);break;}
  205.     case 2:
  206.   ptr=strchr(tmpstr,'t');
  207.       if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto end1;}
  208.   *ptr='';
  209.   if(stricmp(tmpstr,"YES")==0) errorUpdate=TRUE;
  210.   else errorUpdate=FALSE;
  211.       connectStru[k].errorUpdate=errorUpdate;
  212.       tmpstr=ptr+1;
  213.       if(connectID!=connectStru[k].ID) {
  214.     if(makeConnect(k,connectID)==FALSE) {
  215.   WriteHtml(pECB,"ERROR003");goto end1;}
  216.     else {
  217.   sqlUpdateFun(k,tmpstr);break;}}
  218.   else {
  219. sqlUpdateFun(k,tmpstr);break;}
  220.     case 3:
  221.       ptr=strchr(tmpstr,'t');
  222.       if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
  223.       *ptr='';strcpy(userName,tmpstr);
  224.   tmpstr=ptr+1;
  225.       ptr=strchr(tmpstr,'t');
  226.       if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
  227.       *ptr='';strcpy(passWord,tmpstr);
  228.   tmpstr=ptr+1;ptr=strchr(tmpstr,'t');
  229.   if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
  230.       *ptr='';strcpy(dwName,tmpstr);
  231.       tmpstr=ptr+1;ptr=strchr(tmpstr,'t');
  232.   if(ptr==NULL) {WriteHtml(pECB,"ERROR001");goto fail1;}
  233.   *ptr='';strcpy(dateString,tmpstr);
  234.   if(UserPass(tmpdw,dwLib,userName,passWord)==FALSE) {
  235.         WriteHtml(pECB,"ERROR005");goto fail1;}
  236.   if(strlen(dwName)==0) {wwmark=0;strcpy(dwName,tmpdw);}
  237.   else wwmark=1;
  238.   readWinInfo(dwLib,dwName,dateString,wwmark,k);
  239.   break;
  240.     case 4:break;}
  241.   end1:
  242. connectStru[k].usermark=0;
  243.     free(connectStru[k].returnstring);
  244.     return(HSE_STATUS_SUCCESS);
  245.   fail1:
  246. free(returnstring);
  247. return(HSE_STATUS_SUCCESS);}
  248. //------------------------------------------
  249. main()
  250.   {
  251.      long i,ID;
  252.  long len;
  253.  size_t len1;
  254.  FILE *fp;
  255.  abcd("readwindow=dbatsqlt19970809121314t19970203121324t");
  256.      return(1);}
  257.  /*
  258.  i=MAX_CODE;
  259.  ID=TABLE_BANKS;
  260.  strcpy(connectStru[0].DSN,"foxtest");
  261.  strcpy(connectStru[0].dataDir,"C:\DBROWSER\");
  262.  Http(
  263.  "sqlselect=dbatsqlt1treport.pblttestttselectt*tfromtgpinfo");
  264.   return(1);
  265.  Http(
  266.  "sqlupdate=dbatsqlt1treport.pblttesttYEStinserttintotgpinfo(ccode,gpname)tvalues(1234,'abcd');inserttintotgpinfo(ccode,gpname)tvalues(123534,'a4bcd');");
  267.   return(1);
  268.  for(i=0;i<MAXCONNECT;i++) {
  269.    connectStru[i].ID=0;
  270.    connectStru[i].usermark=0;
  271.    connectStru[i].henv=SQL_NULL_HENV;
  272.    connectStru[i].hdbc=SQL_NULL_HDBC;
  273.  }
  274.  strcpy(connectStru[1].DSN,"fox");
  275.      strcpy(connectStru[1].UID,"DBA");
  276.      strcpy(connectStru[1].PASSWORD,"SQL");
  277.  strcpy(connectStru[1].dataDir,"C:\DBROWSER\");
  278.  connectStru[1].returnstring=malloc(1000000);
  279.  if(connectStru[1].returnstring!=NULL) {
  280.  ID=1;
  281.  len=lstrlen(connectStru[1].returnstring);
  282. // len=compress_code(connectStru[1].returnstring,len);
  283. // len=uncode_expand(connectStru[1].returnstring,len);
  284.  fp=fopen("c:\dbrowser\test.txt","w");
  285.  len1=fwrite(connectStru[1].returnstring,1l,len,fp);
  286.  fclose(fp);
  287.  free(connectStru[1].returnstring);
  288.  len=len;}
  289.      return 1; }
  290. */