00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <pthread.h>
00017 #include <iostream>
00018 #include <fstream>
00019 #include <string.h>
00020 #include <time.h>
00021 #include <ctime>
00022 #include <signal.h>
00023 #include <sys/stat.h>
00024 #include <sys/types.h>
00025 #include <sys/socket.h>
00026 #include <exception>
00027 #include <typeinfo>
00028
00029 #ifndef __MSD_DEFS_H__
00030 #include "msd_defs.h"
00031 #endif
00032
00033 #ifndef __MSD_ADMIN_H__
00034 #include "msd_admin.h"
00035 #endif
00036
00037
00038 #include "msd_soapH.h"
00039
00040 #ifndef __MSD_SAX_2_PARSER__
00041 #include "msdSax2Parser.h"
00042 #endif
00043
00044 #ifndef __MSD_SOAP_ENABLED__
00045 #define __MSD_SOAP_ENABLED__
00046 #endif
00047
00048
00049 #ifndef __MSD_USER_H__
00050 #include "msd_user.h"
00051 #endif
00052
00053 #include "msd_soap_service.nsmap"
00054
00055 #ifndef __SRV_PXML__
00056 #include "srv_pxml.h"
00057 #endif
00058
00059 #include "expat.h"
00060
00061
00062 #define uSec *-1
00063 #define mSec *-1000
00064
00065 #define BACKLOG 100 // Max. request backlog (queue size)
00066 #define MAX_THR 16 // Max. threads to serve requests e.g. 8
00067 #define SERVER_TIMEOUT (24*60*60)
00068 #define IO_TIMEOUT 60
00069 #define COOKIE_DOMAIN "localhost:8080"
00070
00071 #define AUTH_USERID "admin"
00072 #define AUTH_PASSWD "guest"
00073
00074 static time_t start = 0;
00075 #define MAXRECORDS 5000
00076 #define MAX_FILE_SIZE (10000000)
00077 #define POOLSIZE 1000 // max number of remote objects that can be alive at any instance
00078 #define LEASETERM 120 //(24*60*60) // 60 lease term (in seconds). Also the rate at which objects are purged
00079 #define N 4
00080
00081
00082
00084 int xml_elno=-1;
00085 msd_xml_element * xml_inf;
00086 char * xml_Buff;
00087 char * xml_txtbuff;
00088 const char msd_soap_service[] = "http://parrot.ebi.ac.uk:8099/cgi-bin/msd_soap_service.cgi";
00089 int argcg;
00090 char ** argvg;
00091
00093
00094 void *process_request(void*);
00095
00096
00097 void default_hndl(void *data, const char *s, int len);
00098 void printcurrent(XML_Parser x_p);
00099 void start_hndl(void *data, const char *el, const char **attr);
00100 void end_hndl(void *data, const char *el);
00101 void char_hndl(void *data, const char *txt, int txtlen);
00102 void proc_hndl(void *data, const char *target, const char *pidata);
00103
00104
00105 static void *dime_read_open(struct soap*, void*, const char*, const char*, const char*);
00106 static void dime_read_close(struct soap*, void*);
00107 static size_t dime_read(struct soap*, void*, char*, size_t);
00108
00109
00110 void showsignal(int signo);
00111 void clone(int signo);
00112 void sigpipe_handle(int x);
00113 int copy_file(struct soap *soap, const char *name, const char *type);
00114
00115
00116 bool msd_authenticate(struct soap* soap);
00117
00118
00119
00121
00122
00123
00125
00126
00127
00128
00129
00130
00131 void t__connect::set(char* host_n, char* user_n, char* passwd)
00132 { dbserver= (char*)soap_malloc(soap,32);
00133 username= (char*)soap_malloc(soap,32);
00134 password= (char*)soap_malloc(soap,32);
00135 strcpy(dbserver,host_n);
00136 strcpy(username,user_n);
00137 strcpy(password,passwd);
00138 }
00139
00140 void t__connect::get()
00141 {
00142 }
00143
00145
00146
00147 void t__query::set(t__connect * pcon, t__resultset * prs, char* qry)
00148 {char* hn = (char*)soap_malloc(soap,32);
00149 char* un = (char*)soap_malloc(soap,32);
00150 char* pw = (char*)soap_malloc(soap,32);
00151 char* ls = (char*)soap_malloc(soap,128);
00152 conn_name = (char*)soap_malloc(soap,64);
00153 result_name = (char*)soap_malloc(soap,64);
00154 loginstr= (char*)soap_malloc(soap,128);
00155 query_stm = (char*)soap_malloc(soap,3000);
00156 strcpy(conn_name, pcon->name);
00157 strcpy(result_name, prs->name);
00158 sprintf(query_stm,"%s", qry);
00159
00160 strcpy(hn, pcon->dbserver);
00161 strcpy(un, pcon->username);
00162 strcpy(pw, pcon->password);
00163 sprintf(ls, "%s/%s@%s", un,pw,hn);
00164 strcpy(loginstr,ls);
00165 soap_dealloc(soap,(void*)hn);
00166 soap_dealloc(soap,(void*)un);
00167 soap_dealloc(soap,(void*)pw);
00168 soap_dealloc(soap,(void*)ls);
00169 }
00170
00171 void t__query::get()
00172 {
00173 }
00174
00175 void t__resultset::set(t__connect * pcon, char* queryn)
00176 {conn_name=(char*)soap_malloc(soap,64);
00177 strcpy(conn_name, pcon->name);
00178 query_name=(char*)soap_malloc(soap,64);
00179 strcpy(query_name,queryn);
00180 }
00181
00182 void t__resultset::get()
00183 {
00184 }
00185
00186
00188
00190
00191 class MSDConnector
00192 { public:
00193 t__root *ref[POOLSIZE];
00194 unsigned int handle;
00195 MSDConnector();
00196 ~MSDConnector();
00197 unsigned int create(struct soap *soap, enum t__object object, char *name);
00198 unsigned int lookup(enum t__object object, char *name);
00199 unsigned int rename(struct soap *soap, unsigned int handle, char *name);
00200 void release(unsigned int handle);
00201 void purge();
00202 t__root *get(unsigned int handle);
00203 t__root *root(unsigned int handle);
00204 t__connect *connect(unsigned int handle);
00205 t__query *query(unsigned int handle);
00206 t__resultset *resultset(unsigned int handle);
00207 int save(const char *file);
00208 int load(const char *file);
00209 int xf;
00210 };
00211
00212 MSDConnector::MSDConnector()
00213 { for (int i = 0; i < POOLSIZE; i++)
00214 ref[i] = NULL;
00215 handle = 0;
00216 xf=0;
00217 }
00218
00219
00220 MSDConnector::~MSDConnector()
00221 { for (int i = 0; i < POOLSIZE; i++)
00222 if (ref[i])
00223 delete ref[i];
00224 }
00225
00226
00227 unsigned int MSDConnector::create(struct soap *soap, enum t__object object, char *name)
00228 { for (int i = 0; i < POOLSIZE; i++)
00229 if (!ref[++handle % POOLSIZE])
00230 { t__root *r = NULL;
00231 if (!handle)
00232 handle += POOLSIZE;
00233 switch (object)
00234 { case ROOT:
00235 r = new t__root();
00236 break;
00237 case CONNECT:
00238 r = new t__connect();
00239 break;
00240 case QUERY:
00241 r = new t__query();
00242 break;
00243 case RESULTSET:
00244 r = new t__resultset();
00245 break;
00246 }
00247 if (r)
00248 { ref[handle % POOLSIZE] = r;
00249 r->object = object;
00250 if (name)
00251 { r->name = (char*)soap_malloc(soap,strlen(name)+1);
00252 strcpy(r->name, name);
00253 }
00254 else{
00255 r->name = NULL;
00256 }
00257 r->handle = handle;
00258 r->renew();
00259 return handle;
00260 }
00261 return 0;
00262 }
00263 return 0;
00264 }
00265
00266
00267 unsigned int MSDConnector::lookup(enum t__object object, char *name)
00268 { for (int i = 0; i < POOLSIZE; i++)
00269 if (ref[i] && ref[i]->object == object && ref[i]->name && (strcmp(ref[i]->name, name)==0))
00270 { ref[i]->renew();
00271 return ref[i]->handle;
00272 }
00273 return 0;
00274 }
00275
00276
00277 unsigned int MSDConnector::rename(struct soap *soap,unsigned int handle, char *name)
00278 { t__root *r = get(handle);
00279 if (r)
00280 { if (r->name)
00281 soap_dealloc(soap,r->name);
00282
00283 r->name = (char*)soap_malloc(soap,strlen(name)+1);
00284 strcpy(r->name, name);
00285 r->renew();
00286 return handle;
00287 }
00288 return 0;
00289 }
00290
00291
00292 t__root *MSDConnector::get(unsigned int handle)
00293 { t__root *r = ref[handle % POOLSIZE];
00294 if (r && r->handle == handle)
00295 return r;
00296 return NULL;
00297 }
00298
00299
00300 t__root *MSDConnector::root(unsigned int handle)
00301 { t__root *r = get(handle);
00302 if (r)
00303 r->renew();
00304 return r;
00305 }
00306
00307
00309 t__connect *MSDConnector::connect(unsigned int handle)
00310 { t__connect *con = (t__connect*)get(handle);
00311 if (con)
00312 { if (con->object == CONNECT)
00313 con->renew();
00314 else
00315 con = NULL;
00316 }
00317 return con;
00318 }
00320 t__query *MSDConnector::query(unsigned int handle)
00321 { t__query *q = (t__query*)get(handle);
00322 if (q)
00323 { if (q->object == QUERY)
00324 q->renew();
00325 else
00326 q = NULL;
00327 }
00328 return q;
00329 }
00330
00332 t__resultset *MSDConnector::resultset(unsigned int handle)
00333 { t__resultset *rs = (t__resultset*)get(handle);
00334 if (rs)
00335 { if (rs->object == RESULTSET)
00336 rs->renew();
00337 else
00338 rs = NULL;
00339 }
00340 return rs;
00341 }
00342
00344
00345
00346
00347
00348
00349 void MSDConnector::purge()
00350 { time_t t = time(NULL);
00351 fprintf(stderr, "Purging objects...");
00352 for (int i = 0; i < POOLSIZE; i++)
00353 { t__root *r = ref[i];
00354 if (r && r->lease < t)
00355 { if (r->name)
00356 fprintf(stderr, " %s(%u)", r->name, r->handle);
00357 else
00358 fprintf(stderr, " (%u)", r->handle);
00359 delete r;
00360 ref[i] = NULL;
00361 }
00362 }
00363 fprintf(stderr, "\nKeeping objects...");
00364 for (int i = 0; i < POOLSIZE; i++)
00365 { t__root *r = ref[i];
00366 if (r)
00367 { if (r->name)
00368 fprintf(stderr, " %s(%u)", r->name, r->handle);
00369 else
00370 fprintf(stderr, " (%u)", r->handle);
00371 }
00372 }
00373 fprintf(stderr, "\n");
00374 }
00375
00376
00377 void MSDConnector::release(unsigned int handle)
00378 { t__root *r = get(handle);
00379 if (r)
00380 { delete r;
00381 ref[handle % POOLSIZE] = NULL;
00382 }
00383 }
00384
00385
00386 int MSDConnector::save(const char *file)
00387 { struct soap soap;
00388
00389 soap_init(&soap);
00390 if (! file){
00391
00392 soap_omode(&soap, SOAP_ENC_ZLIB);
00393 }
00394
00395 soap_begin(&soap);
00396 if (file){
00397 soap.sendfd = open(file, O_CREAT|O_TRUNC|O_WRONLY, S_IREAD|S_IWRITE);
00398
00399 if (soap.sendfd < 0)
00400 return -1;}
00401 soap_begin_send(&soap);
00402 for (int i = 0; i < POOLSIZE; i++)
00403 if (ref[i])
00404 { ref[i]->soap_serialize(&soap);
00405 soap_begin_send(&soap);
00406 ref[i]->soap_put(&soap, "item", NULL);
00407 soap_end_send(&soap);
00408 }
00409 if (file)
00410 close(soap.sendfd);
00411 soap_end(&soap);
00412 soap_done(&soap);
00413 return 0;
00414 }
00415
00416
00417 int MSDConnector::load(const char *file)
00418 { struct soap soap;
00419 t__root *r;
00420
00421 soap_init(&soap);
00422 if (! file){
00423
00424 soap_imode(&soap, SOAP_ENC_ZLIB);
00425 }
00426
00427 if (file){
00428 soap.recvfd = open(file, O_RDONLY);
00429 if (soap.recvfd < 0)
00430 return -1;}
00431 soap_begin_recv(&soap);
00432 for (int i = 0; i < POOLSIZE; i++)
00433 { if (ref[i])
00434 { delete ref[i];
00435 ref[i] = NULL;
00436 }
00437 }
00438 for (;;)
00439 { r = soap_in_t__root(&soap, "item", NULL, NULL);
00440 if (r)
00441 ref[r->handle % POOLSIZE] = r;
00442 else
00443 break;
00444 }
00445 if (file)
00446 close(soap.recvfd);
00447
00448 soap_end_recv(&soap);
00449 if (soap.error != SOAP_OK && soap.error != SOAP_EOF)
00450 { soap_print_fault(&soap, stderr);
00451 soap_print_fault_location(&soap, stderr);
00452 }
00453
00454 soap_free(&soap);
00455 soap_done(&soap);
00456 return 0;
00457 }
00458
00459
00461
00462
00463
00464 int set_datafile_name (const char* fname ){
00465 char buffer[64];
00466 char newenv[64];
00467 sprintf(buffer,getenv ("MSD_WS_DATAFILE"));
00468 if (strstr(buffer, fname)==NULL)
00469 {
00470 sprintf(newenv , "MSD_WS_DATAFILE=%s",fname);
00471 putenv (newenv);
00472 }
00473 return 0;
00474 }
00475
00477
00478
00479
00480
00481
00482 static msdUser supervisor_user;
00483
00484 int main(int argc, char **argv)
00485 { char logstr[128];
00486
00487 msdAdmin admin_object;
00488
00489 if (!msd_get_userinfo(admin_object, supervisor_user))
00490 {fprintf(stderr,"\nAuthentication failed, only Administrator can start the server.");
00491 exit(1);
00492 }
00493 sprintf(logstr,"%s/%s@%s", supervisor_user.dbuname,supervisor_user.getDBPass(),supervisor_user.host);
00494 fprintf(stderr,logstr);
00495 struct soap soap;
00496 MSDConnector connector;
00497
00498
00499 soap_init(&soap);
00500
00501
00502 soap_set_omode(&soap, SOAP_XML_GRAPH);
00503
00504
00505 soap.accept_timeout = LEASETERM;
00506
00507 soap.user = (void*)&connector;
00508
00509 char* fn;
00510
00511
00512 if (argc < 3)
00513 {
00514 fn=(char*)soap_malloc(&soap,65);
00515 if (argv[1] && (strlen(argv[1])!= 0))
00516 sprintf(fn,"session%s.dat",argv[1]);
00517 else
00518 sprintf(fn,"%s","sessioncommon.dat");
00519
00520
00521
00522 connector.load(fn);
00523 connector.purge();
00524 soap_serve(&soap);
00525 connector.save(fn);
00526
00527 soap_free(&soap);
00528 soap_done(&soap);
00529 }
00530 else
00531
00532 { int m, s;
00533
00534
00535
00536
00537 struct soap *soap_thr[MAX_THR];
00538
00539 pthread_t tid[MAX_THR];
00540
00541
00542 char *host = (char*)soap_malloc(&soap,strlen(argv[1])+1);
00543 sprintf(host,"%s",argv[1]);
00544 int port = atoi(argv[2]);
00545
00546 msdPrompt(host);
00547 fprintf(stderr, "Starting PDBe SOAP Web API Server on port %d\n", port);
00548
00550 pid_t pid;
00551 signal(SIGINT,showsignal);
00552 signal(SIGUSR1,clone);
00553 pid = fork();
00554
00555 if (pid <0){
00556 msdPrompt(host);
00557 fprintf(stderr, "Forking Error : )\n");
00558 exit(-1);
00559 }else if (pid !=0 ){
00560 msdPrompt(host);
00561 fprintf(stderr, "Parrent process level 1 started...\n");
00562 }else{
00563 pid = fork();
00564
00565 if (pid <0){
00566 msdPrompt(host);
00567 fprintf(stderr, "Forking error : )\n");
00568 exit(-1);
00569 }else if (pid !=0 ){
00570 msdPrompt(host);
00571 fprintf(stderr, "Parrent process level 2 started...\n");
00572 }else {
00574 m = soap_bind(&soap, host, port, BACKLOG);
00575 if (m < 0)
00576 {msdPrompt(host);
00577 fprintf(stderr,"Socket connection failed. %d \nTrying again, please wait...", m);
00578 }
00579 int nc=1;
00580 while (m < 0){
00581
00582 fprintf(stderr,"%2d", nc);
00583 wait(3);
00584 m = soap_bind(&soap, host, port, BACKLOG);
00585 fprintf(stderr,"");
00586 nc++;
00587 if (nc > 99)
00588 {fprintf(stderr,"Socket connection failed. %d \nCan not bind to the port.", m);
00589 exit(1);
00590 }
00591
00592 }
00593 msdPrompt(host);
00594 fprintf(stderr,"Port bind successful: master socket: %d \n", m);
00595 fprintf(stderr,"Server is running...\n");
00596
00597 signal(SIGPIPE, sigpipe_handle);
00598
00599 for (int count = 0; count >= 0; count++)
00600 { soap.socket_flags = MSG_NOSIGNAL;
00601
00602 msdPrompt(host);
00603 fprintf(stderr,"Starting Session or Job %d ...\n", count);
00604
00605
00606 for (int i = 0; i < MAX_THR; i++)
00607 {
00608 s = soap_accept(&soap);
00609 if (s < 0)
00610
00611 { if (soap.errnum){
00612
00613 soap_print_fault(&soap, stderr);
00614 break;
00615 }
00616
00617 else
00618 { connector.purge();
00619 continue;
00620 }
00621
00622 }
00623
00624
00625 msdPrompt(host);
00626 fprintf(stderr,"Thread %d accepts socket %d connection from IP %d.%d.%d.%d \n", i, s, (soap.ip >> 24)&0xFF, (soap.ip >> 16)&0xFF, (soap.ip >> 8)&0xFF, soap.ip&0xFF);
00627 if (!soap_thr[i])
00628 {
00629 soap_thr[i] = soap_copy(&soap);
00630 if (!soap_thr[i]){
00631 msdPrompt(host);
00632 fprintf(stderr,"Can not soap copy for Thread %d ", i);
00633 exit(1);
00634 }else{
00635
00636 soap_set_omode(soap_thr[i], SOAP_XML_GRAPH);
00637
00638 soap_thr[i]->socket = s;
00639 soap_thr[i]->user = (void*)&connector;
00640 pthread_create(&tid[i], NULL, (void*(*)(void*))process_request, (void*)soap_thr[i]);
00641
00642
00643 }
00644
00645 }
00646 else
00647 { pthread_join(tid[i], NULL);
00648
00649 msdPrompt(host);
00650 fprintf(stderr,"Thread %d from Job %d completed.\n", i, count);
00651
00652 if (soap_thr[i]->error != SOAP_OK && soap_thr[i]->error != SOAP_EOF)
00653 { soap_print_fault(soap_thr[i], stderr);
00654 soap_print_fault_location(soap_thr[i], stderr);
00655 }
00656
00657
00658 soap_destroy(soap_thr[i]);
00659 soap_end(soap_thr[i]);
00660 soap_free(soap_thr[i]);
00661 soap_done(soap_thr[i]);
00662
00663 soap_thr[i] = NULL;
00664
00665 }
00666
00667 }
00668 for (int i = 0; i < MAX_THR; i++) {
00669 if (soap_thr[i])
00670 {soap_thr[i] = NULL;
00671 }
00672 }
00673 }
00674
00675 soap_done(&soap);
00676 }
00677 }
00678 }
00679 return 0;
00680 }
00681
00683 void *process_request(void *soap)
00684 {
00685 pthread_detach(pthread_self());
00686
00687 soap_serve((struct soap*)soap);
00688
00689 return NULL;
00690 }
00691
00692
00693 void default_hndl(void *data, const char *s, int len) {
00694
00695 }
00696
00697
00698
00699
00700
00701
00703 void printcurrent(XML_Parser x_p) {
00704 XML_SetDefaultHandler(x_p, default_hndl);
00705 XML_DefaultCurrent(x_p);
00706 XML_SetDefaultHandler(x_p, (XML_DefaultHandler) 0);
00707 }
00708
00709 void start_hndl(void *data, const char *el, const char **attr) {
00710 xml_elno++;
00711 xml_inf[xml_elno].tag=(char *)malloc(strlen(el)+1);
00712 sprintf(xml_inf[xml_elno].tag,"%s",el);
00713 xml_inf[xml_elno].data=(char *)malloc(strlen(xml_txtbuff)+1);
00714 sprintf(xml_inf[xml_elno].data,"%s","");
00715 sprintf(xml_txtbuff,"%s", "");
00716 printcurrent((XML_Parser) data);
00717 }
00718
00719 void end_hndl(void *data, const char *el) {
00720 sprintf(xml_inf[xml_elno].data,"%s",xml_txtbuff);
00721
00722 }
00723
00724 void char_hndl(void *data, const char *txt, int txtlen) {
00725
00726 char* xbuf =(char*)SOAP_MALLOC(strlen(txt)+1);
00727
00728 sprintf(xbuf,"%s","");
00729 strcpy(xbuf,txt);
00730 xbuf[txtlen]='\0';
00731
00732 sprintf(xml_txtbuff,"%s%s", xml_txtbuff, xbuf);
00733
00734 }
00735
00736 void proc_hndl(void *data, const char *target, const char *pidata) {
00737
00738 printcurrent((XML_Parser) data);
00739
00740 }
00741
00742 void showsignal(int signo){
00743
00744
00745 fprintf(stderr,"\nSignal : %d \n",signo);
00746 exit(1);
00747 }
00748
00749 void clone(int signo){
00750 main(argcg, argvg);
00751 return;
00752 }
00753
00754 void sigpipe_handle(int x) {}
00757 static void *dime_read_open(struct soap *soap, void *handle, const char *id, const char *type, const char *options)
00758 {
00759
00760 return handle;
00761 }
00762
00763 static void dime_read_close(struct soap *soap, void *handle)
00764 { fclose((FILE*)handle);
00765 }
00766
00767 static size_t dime_read(struct soap *soap, void *handle, char *buf, size_t len)
00768 { return fread(buf, 1, len, (FILE*)handle);
00769 }
00770
00771
00773
00774 int copy_file(struct soap *soap, const char *name, const char *type)
00775 { FILE *fd;
00776 size_t r;
00777 fd = fopen(name, "r");
00778 if (!fd)
00779 return SOAP_EOF;
00780 soap->http_content = type;
00781 if (soap_begin_send(soap)
00782 || soap_response(soap, SOAP_FILE))
00783 return soap->error;
00784 for (;;)
00785 { r = fread(soap->tmpbuf, 1, sizeof(soap->tmpbuf), fd);
00786 if (!r)
00787 break;
00788 if (soap_send_raw(soap, soap->tmpbuf, r))
00789 { soap_end_send(soap);
00790 fclose(fd);
00791 return soap->error;
00792 }
00793 }
00794 fclose(fd);
00795 if (soap_end_send(soap))
00796 return soap->error;
00797 return SOAP_OK;
00798 }
00800
00801 bool msd_authenticate(struct soap* soap){
00802 msdAdmin sec_check;
00803 if (!soap->userid || !soap->passwd || !sec_check.msdLogin(soap->userid,soap->passwd ))
00804 return false;
00805 return true;
00806 }
00807
00808
00810 int ns4__msdGetSSMXml(struct soap *soap, char * sessionid, int &res_ssmxml)
00811 { if (sessionid)
00812 { char* session_id = (char*)soap_malloc(soap, strlen(sessionid)+1);
00813 sprintf(session_id,"%s",sessionid);
00814 char* name = (char*)soap_malloc(soap,256);
00815 sprintf(name,"/tmp_mnt/net_nfs5/vol4/research-thornton/ssmout/%s_out.xml",session_id);
00816 soap_set_omode(soap, SOAP_IO_CHUNK);
00817
00818 if (!strchr(name, '\\') && !strchr(name, ':'))
00819 {
00820 if (!soap_tag_cmp(name, "*.xml")
00821 || !soap_tag_cmp(name, "*.xsd")
00822 || !soap_tag_cmp(name, "*.wsdl"))
00823 if (copy_file(soap, name , "text/xml") == SOAP_OK)
00824 {res_ssmxml = 0;
00825 return SOAP_OK;
00826 }else{res_ssmxml = 12;
00827 return soap_sender_fault(soap, "Fille Can not be copied", NULL);
00828 }
00829
00830
00831 }
00832 }
00833 else
00834 return soap_sender_fault(soap, "Fille name required to transfer", NULL);
00835 return SOAP_OK;
00836 }
00838
00839 int ns4__msdGetSoapBase64Data(struct soap *soap, int diyf, char * sessionid, SOAP_ENC__base64 &s_bindata)
00840 { if (sessionid)
00841 { char* session_id = (char*)soap_malloc(soap, strlen(sessionid)+1);
00842 sprintf(session_id,"%s",sessionid);
00843 char* name = (char*)soap_malloc(soap,256);
00844 sprintf(name,"/tmp_mnt/net_nfs5/vol4/research-thornton/ssmout/%s_out.xml",session_id);
00845 int j=0;
00846 bool out_file_ok;
00847 if ((out_file_ok=fileexists(name)== false) && (diyf != 0))
00848 {return soap_sender_fault(soap, "Result fille not ready", NULL);
00849 }
00850 while(j<12*15)
00851 { if (out_file_ok=fileexists(name)== true)
00852 {
00853 break;}else
00854 {
00855 wait(2);
00856 }
00857 j++;
00858 }
00859 FILE *fd = NULL;
00860 struct stat sb;
00861 int i, c, xmlsize;
00862 fd = fopen(name, "rb");
00863 if (!fd || !out_file_ok)
00864 return soap_sender_fault(soap, "Cannot open file", NULL);
00865 if (!fstat(fileno(fd), &sb) && sb.st_size > 0)
00866 {xmlsize= sb.st_size;}
00867 else
00868 {xmlsize=MAX_FILE_SIZE;}
00869
00870
00871
00872 s_bindata.__ptr = (unsigned char*)soap_malloc(soap, xmlsize);
00873 for (i = 0; i < xmlsize; i++)
00874 { if ((c = fgetc(fd)) == EOF)
00875 break;
00876 s_bindata.__ptr[i] = c;
00877 }
00878 fclose(fd);
00879 s_bindata.__size = i;
00880
00881 }
00882 else
00883 return soap_sender_fault(soap, "Fille name required to transfer", NULL);
00884 return SOAP_OK;
00885 }
00886
00887
00889 int ns4__msdGetDime(struct soap *soap, int diyf, char* sessionid , xsd__base64Binary &d_bindata)
00890 { if (sessionid)
00891 { char* session_id = (char*)soap_malloc(soap, strlen(sessionid)+1);
00892 sprintf(session_id,"%s",sessionid);
00893 char* name = (char*)soap_malloc(soap,256);
00894 sprintf(name,"/tmp_mnt/net_nfs5/vol4/research-thornton/ssmout/%s_out.xml",session_id);
00895 int j=0;
00896 bool out_file_ok;
00897 if ((out_file_ok=fileexists(name)== false) && (diyf != 0))
00898 {return soap_sender_fault(soap, "Result fille not ready", NULL);
00899 }
00900 while(j<12*15)
00901 { if (out_file_ok=fileexists(name)== true)
00902 {
00903 break;}else
00904 {
00905 wait(2);
00906 }
00907 j++;
00908 }
00909 FILE *fd = NULL;
00910 struct stat sb;
00911 int i, c;
00912
00913 if (!strchr(name, '\\') && !strchr(name, ':'))
00914 fd = fopen(name, "rb");
00915 if (!fd)
00916 return soap_sender_fault(soap, "Cannot open file", NULL);
00917 if (!fstat(fileno(fd), &sb) && sb.st_size > 0)
00918 {
00919 soap->fdimereadopen = dime_read_open;
00920 soap->fdimereadclose = dime_read_close;
00921 soap->fdimeread = dime_read;
00922 d_bindata.__ptr = (unsigned char*)fd;
00923 d_bindata.__size = sb.st_size;
00924 }
00925 else
00926 { d_bindata.__ptr = (unsigned char*)soap_malloc(soap, MAX_FILE_SIZE);
00927 for (i = 0; i < MAX_FILE_SIZE; i++)
00928 { if ((c = fgetc(fd)) == EOF)
00929 break;
00930 d_bindata.__ptr[i] = c;
00931 }
00932 fclose(fd);
00933 d_bindata.__size = i;
00934 }
00935 d_bindata.id = "";
00936 d_bindata.type = "text/xml";
00937
00938 d_bindata.options = soap_dime_option(soap, 0, "SSM_XML_OUT");
00939
00940 }
00941 else
00942 return soap_sender_fault(soap, "Fille name required to transfer", NULL);
00943 return SOAP_OK;
00944 }
00946
00947 int ns4__msdGetXsdBase64BinData(struct soap *soap, int diyf, char * sessionid, xsd__base64Binary &x_bindata)
00948 { if (sessionid)
00949 { char* session_id = (char*)soap_malloc(soap, strlen(sessionid)+1);
00950 sprintf(session_id,"%s",sessionid);
00951 char* name = (char*)soap_malloc(soap,256);
00952 sprintf(name,"/tmp_mnt/net_nfs5/vol4/research-thornton/ssmout/%s_out.xml",session_id);
00953 int j=0;
00954 bool out_file_ok;
00955 if ((out_file_ok=fileexists(name)== false) && (diyf != 0))
00956 {return soap_sender_fault(soap, "Result fille not ready", NULL);
00957 }
00958 while(j<12*15)
00959 { if (out_file_ok=ssm_file_completed(name,"</SSMResults>")== true)
00960 {
00961 break;}else
00962 {
00963 wait(2);
00964 }
00965 j++;
00966 }
00967 FILE *fd = NULL;
00968 struct stat sb;
00969 int i, c, xmlsize;
00970 fd = fopen(name, "rb");
00971 if (!fd || !out_file_ok)
00972 return soap_sender_fault(soap, "Cannot open file", NULL);
00973 if (!fstat(fileno(fd), &sb) && sb.st_size > 0)
00974
00975 {xmlsize= sb.st_size;}
00976 else
00977 {xmlsize=MAX_FILE_SIZE;}
00978
00979
00980
00981 x_bindata.__ptr = (unsigned char*)soap_malloc(soap, xmlsize);
00982 for (i = 0; i < xmlsize; i++)
00983 { if ((c = fgetc(fd)) == EOF)
00984 break;
00985 x_bindata.__ptr[i] = c;
00986 }
00987 fclose(fd);
00988 x_bindata.__size = i;
00989
00990 }
00991 else
00992 return soap_sender_fault(soap, "Fille name required to transfer", NULL);
00993 return SOAP_OK;
00994 }
00995
00996
00997
00998 int ns4__msdValidate(struct soap *soap, char* UserXmlStr, char*&ServXmlStr)
00999 { char* tmpin=(char*)soap_malloc(soap, 2048);
01000 strcpy(tmpin,UserXmlStr);
01001 char* tmpout=(char*)soap_malloc(soap, 2048);
01002 msdSax2Parser* p = new msdSax2Parser();
01003 strcpy(tmpout, p->validate(tmpin));
01004 ServXmlStr = tmpout;
01005 return SOAP_OK;
01006 }
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01025
01026
01027
01029
01030 int ns4__create(struct soap *soap, enum t__object object, char *name, enum t__status &c_status)
01031 { char* oname;
01032 oname=(char*)soap_malloc(soap,strlen(name)+1);
01033 strcpy(oname,name);
01034 MSDConnector *connector = (MSDConnector*)soap->user;
01035 if (!soap->header)
01036 soap->header = (struct SOAP_ENV__Header*)soap_malloc(soap, sizeof(struct SOAP_ENV__Header));
01037 if (soap->header)
01038 { soap->header->h__handle = connector->create(soap, object, oname);
01039 if (soap->header->h__handle){
01040 c_status = OK;
01041 } else c_status = INVALID;
01042 }else c_status = RETRY;
01043 return SOAP_OK;
01044 }
01045
01046 int ns4__lookup(struct soap *soap, enum t__object object, char *name, enum t__status &l_status)
01047 { char* oname;
01048 oname=(char*)soap_malloc(soap,strlen(name)+1);
01049 strcpy(oname,name);
01050 MSDConnector *connector = (MSDConnector*)soap->user;
01051
01052 if (!soap->header)
01053 soap->header = (struct SOAP_ENV__Header*)soap_malloc(soap, sizeof(struct SOAP_ENV__Header));
01054 if (soap->header)
01055 { soap->header->h__handle = connector->lookup(object, oname);
01056 if (soap->header->h__handle)
01057 l_status = OK;
01058 else l_status = NOTFOUND;
01059 }else l_status = RETRY;
01060 return SOAP_OK;
01061 }
01062
01063 int ns4__rename(struct soap *soap, char *name, enum t__status &ren_status)
01064 { char* oname;
01065 oname=(char*)soap_malloc(soap,strlen(name)+1);
01066 strcpy(oname,name);
01067 MSDConnector *connector = (MSDConnector*)soap->user;
01068 if (soap->header)
01069 { soap->header->h__handle = connector->rename(soap, soap->header->h__handle, oname);
01070 if (soap->header->h__handle)
01071 ren_status = OK;
01072 else ren_status = INVALID;
01073 }else ren_status = INVALID;
01074 return SOAP_OK;
01075 }
01076
01077 int ns4__release(struct soap *soap, enum t__status &rel_status)
01078 { MSDConnector *connector = (MSDConnector*)soap->user;
01079 if (soap->header && soap->header->h__handle)
01080 { connector->release(soap->header->h__handle);
01081 rel_status = OK;
01082 }else rel_status = INVALID;
01083 return SOAP_OK;
01084 }
01085
01086
01087
01089
01090
01091
01093 int ns4__msdConnect(struct soap *soap, char* conn_name, int &conn_status)
01094 { extern msdUser supervisor_user;
01095
01096 char* host = (char*)soap_malloc(soap,81);
01097 char* usern = (char*)soap_malloc(soap,81);
01098 char* pass = (char*)soap_malloc(soap,81);
01099 sprintf(host,"%s",supervisor_user.host);
01100 sprintf(usern,"%s", supervisor_user.dbuname);
01101 sprintf(pass,"%s", supervisor_user.getDBPass());
01102 char errmess[512];
01103 char* hn;
01104 char* un;
01105 char* pw;
01106 char* cn;
01107 cn = (char*)soap_malloc(soap, strlen(conn_name)+1);
01108
01109 sprintf(cn,"%s", conn_name);
01110 hn = (char*)soap_malloc(soap, strlen(host)+1);
01111
01112 sprintf(hn, "%s" , host);
01113 un = (char*)soap_malloc(soap, strlen(usern)+1);
01114
01115 sprintf(un,"%s", usern);
01116 pw = (char*)soap_malloc(soap, strlen(pass)+1);
01117
01118 sprintf(pw,"%s", pass);
01119 if (!msd_authenticate(soap))
01120 {
01121 conn_status = 7;
01122 return soap_sender_fault(soap, "\nLogin Failed. This method requires authentication.\n Username and Password"
01123 " Should be set just before calling this method.", NULL);
01124 }
01125 MSDConnector *connector = (MSDConnector*)soap->user;
01126 if (!soap->header)
01127 soap->header = (struct SOAP_ENV__Header*)soap_malloc(soap, sizeof(struct SOAP_ENV__Header));
01128 if (soap->header)
01129 { soap->header->h__handle = connector->lookup(CONNECT, cn);
01130 if (soap->header->h__handle){
01131 sprintf(errmess,"A Connection Object with name: %s already exists.", cn);
01132 return soap_sender_fault(soap, errmess, NULL);
01133 }
01134 soap->header->h__handle = connector->create(soap, CONNECT, cn);
01135 if (soap->header->h__handle){
01136 t__connect * rc = connector->connect(soap->header->h__handle);
01137 if (rc)
01138 {rc->set(hn, un, pw);
01139 rc=NULL;
01140 conn_status = 0;
01141 }else{ conn_status = 1;
01142 return soap_sender_fault(soap, "Invalid Connect Object.", NULL);
01143 }
01144
01145 }else { conn_status = 2;
01146 return soap_sender_fault(soap, "Connect Object not created.", NULL);
01147 }
01148
01149 }else { conn_status = 3;
01150 return soap_sender_fault(soap, "Soap Header handle not found.", NULL);
01151 }
01152
01153 soap_dealloc(soap,(void*)hn);
01154 soap_dealloc(soap,(void*)un);
01155 soap_dealloc(soap,(void*)pw);
01156 soap_dealloc(soap,(void*)cn);
01157 return SOAP_OK;
01158
01159
01160 }
01161
01162
01163 int ns4__msdGetconnect(struct soap *soap, char* conn_name, int &gstatus )
01164 { MSDConnector *connector = (MSDConnector*)soap->user;
01165 if (!soap->header)
01166 soap->header = (struct SOAP_ENV__Header*)soap_malloc(soap, sizeof(struct SOAP_ENV__Header));
01167
01168 if (soap->header)
01169 { t__connect *conn = connector->connect(soap->header->h__handle);
01170 if (conn){
01171
01172 gstatus = 0;
01173 }else gstatus = 1;
01174 }
01175 return SOAP_OK;
01176 }
01177
01178
01179
01180
01181
01183 int msd_sender_exception(struct soap *soap, msdbConnect& db, msdbException& p){
01184 char* errstr = (char*)soap_malloc(soap,sizeof(p.stm_text)+10);
01185 char* errmsg = (char*)soap_malloc(soap,sizeof(p.msg)+1);
01186 sprintf(errstr, "\nSQL: [%s]\n", p.stm_text);
01187 stringstream buff;
01188 buff << p.msg;
01189 string buffstr = buff.str()+ errstr;
01190 sprintf(errmsg,"%s", buffstr.c_str());
01191 db.logoff();
01192 msdbConnect::otl_terminate();
01193 return soap_sender_fault(soap, errmsg, NULL);
01194 }
01196
01197 int ns4__msdExecQuery(struct soap *soap, char* conn_name, char* query_name, char* result_name, int buf, int &exec_status)
01198 { char* sql;
01199 char* cn;
01200 char* qn;
01201 char* rn;
01202 int Nrecs=0;
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216 if (!msd_authenticate(soap))
01217 { exec_status = 7;
01218 return soap_sender_fault(soap, "\nLogin Failed. This method requires authentication.\n"
01219 " Username and Password Should be set just before calling this method."
01220 , NULL);
01221 }
01222
01223
01224 cn = (char*)soap_malloc(soap, strlen(conn_name)+1);
01225 sprintf(cn, "%s",conn_name);
01226 qn = (char*)soap_malloc(soap, strlen(query_name)+1);
01227 sprintf(qn, "%s",query_name);
01228 rn = (char*)soap_malloc(soap, strlen(result_name)+1);
01229 sprintf(rn, "%s",result_name);
01230 char* qr_err = (char*)soap_malloc(soap, 3072);
01231 char* qr_err_detail = (char*)soap_malloc(soap, 3072);
01232 MSDConnector *connector = (MSDConnector*)soap->user;
01233 if (!soap->header)
01234 soap->header = (struct SOAP_ENV__Header*)soap_malloc(soap, sizeof(struct SOAP_ENV__Header));
01235 if (soap->header)
01236 { soap->header->h__handle = connector->lookup(CONNECT, cn);
01237 if (soap->header->h__handle){
01238 t__connect * rc =connector->connect(soap->header->h__handle);
01239 soap->header->h__handle = connector->lookup(RESULTSET, rn);
01240 if (soap->header->h__handle){
01241 t__resultset* rs = connector->resultset(soap->header->h__handle);
01242 soap->header->h__handle = connector->lookup(QUERY, qn);
01243 if (soap->header->h__handle){
01244 t__query *qry = connector->query(soap->header->h__handle);
01245 if (qry && rc && rs)
01246 {sql = (char*)soap_malloc(soap, strlen(qry->query_stm)+1);
01247 sprintf(sql,"%s", qry->query_stm);
01248
01249
01250 msdbConnect db;
01251 msdbConnect::msdbInit(1);
01252 int j=0;
01253 int desc_len;
01254 otl_column_desc* desc;
01255 char* sqltmp=(char*)soap_malloc(soap,4096);
01256 sprintf(sqltmp,"%s",sql);
01257 char* sqlparam=(char*)soap_malloc(soap,4096);
01258 make_select_param(sqltmp,sqlparam);
01259
01260 try{
01261 db.rlogon(qry->loginstr);
01262
01263 db.set_max_long_size(MAXBLOBSIZE);
01264
01265 char* sqlcount=(char*)soap_malloc(soap,4096);
01266
01267
01268 make_select_count (sqlparam,sqlcount);
01269
01270 msdbStream ic (buf, sqlcount, db);
01271 ic << 1;
01272
01273 while(!ic.eof()){
01274 ic >> Nrecs;
01275 }
01276 }
01277 catch(msdbException& p){
01278 cerr<<p.msg<<endl;
01279 cerr<<p.stm_text<<endl;
01280 cerr<<p.var_info<<endl;
01281 rs->hasdata=0;
01282 qry->exf=0;
01283 exec_status = 6;
01284 return msd_sender_exception(soap,db,p);
01285 }
01286
01287 try
01288 {
01289
01290
01291 if (Nrecs > 0){
01292
01293 msdbStream i(buf, sqlparam, db);
01294
01295
01296
01297 i << 1;
01298 desc=i.describe_select(desc_len);
01299
01300
01301
01302
01303 if (rs->prs){
01304
01305
01306
01307
01308
01309
01310
01311 rs->prs=NULL;
01312 }
01313 rs->prs = (xsd__anyType**)soap_malloc(soap,desc_len*sizeof(xsd__anyType*));
01314 for(int n=0;n<desc_len;++n){
01315
01316 rs->prs[n] = new array(Nrecs);
01317 switch (desc[n].dbtype){
01318 case 1 : {for (int i=0;i<Nrecs ;++i )
01319 {(*rs->prs[n])[i]= new xsd__string(desc[n].dbsize+1);
01320 }} break;
01321 case 2 : {if (desc[n].scale == 129){
01322 for (int i=0;i<Nrecs ;++i )
01323 {(*rs->prs[n])[i]= new xsd__float();
01324 }}
01325 else if (desc[n].scale==0)
01326 {if ((desc[n].prec<=10 && desc[n].prec !=0) || has_integer_name(desc[n].name) == 1)
01327 {
01328 for (int i=0;i<Nrecs ;++i )
01329 {(*rs->prs[n])[i]= new xsd__int();
01330 }}else
01331 {for (int i=0;i<Nrecs ;++i )
01332 {(*rs->prs[n])[i]= new xsd__float();
01333 }}
01334 }
01335 else
01336 {for (int i=0;i<Nrecs ;++i )
01337 {(*rs->prs[n])[i]= new xsd__int();
01338 }}
01339 } break;
01340
01341 case 3 : {for (int i=0;i<Nrecs ;++i )
01342 {(*rs->prs[n])[i]= new xsd__float();
01343 }} break;
01344 case 4 : {for (int i=0;i<Nrecs ;++i )
01345 {(*rs->prs[n])[i]= new xsd__int();
01346 }} break;
01347 case 5 : {for (int i=0;i<Nrecs ;++i )
01348 {(*rs->prs[n])[i]= new xsd__int();
01349 }} break;
01350 case 6 : {for (int i=0;i<Nrecs ;++i )
01351 {(*rs->prs[n])[i]= new xsd__short();
01352 }} break;
01353 case 7 : {for (int i=0;i<Nrecs ;++i )
01354 {(*rs->prs[n])[i]= new xsd__int();
01355 }} break;
01356 case 12: {for (int i=0;i<Nrecs ;++i )
01357 {(*rs->prs[n])[i]= new xsd__date();
01358 }} break;
01359 case 96: {for (int i=0;i<Nrecs ;++i )
01360 {(*rs->prs[n])[i]= new xsd__string(desc[n].dbsize+1);
01361 }} break;
01362 default: {for (int i=0;i<Nrecs ;++i )
01363 {(*rs->prs[n])[i]= new xsd__string(desc[n].dbsize+1);
01364 }}
01365 }
01366
01367
01368
01369 }
01370
01371
01372
01373 while(!i.eof()){
01374 for (int n=0;n<desc_len ;++n ){
01375 (*rs->prs[n])[j]->getst(i);
01376 }
01377 ++j;
01378 }
01379
01380
01381
01382
01383 rs->cols=desc_len;
01384 rs->rows=Nrecs;
01385
01386 rs->hasdata=1;
01387 qry->exf=1;
01388 }
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402 }
01403
01404
01405
01406
01407
01408
01409
01410 catch(msdbException& p){
01411 cerr<<p.msg<<endl;
01412 cerr<<p.stm_text<<endl;
01413 cerr<<p.var_info<<endl;
01414 rs->hasdata=0;
01415 qry->exf=0;
01416 exec_status = 6;
01417 return msd_sender_exception(soap,db,p);
01418 }
01419 db.logoff();
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451 qry=NULL;
01452 rc=NULL;
01453 rs=NULL;
01454 exec_status = 0;
01455 } else { exec_status = 1;
01456 return soap_sender_fault(soap, "Connection, Query, Resultset objects not found", NULL);
01457 }
01458 } else {exec_status = 2;
01459 return soap_sender_fault(soap, "Query object not found", NULL);
01460 }
01461 } else {exec_status = 3;
01462 return soap_sender_fault(soap, "Resultset object not found", NULL);
01463 }
01464 } else {exec_status = 4;
01465 return soap_sender_fault(soap, "Connection object not found", NULL);
01466 }
01467 } else { exec_status = 5;
01468 return soap_sender_fault(soap, "Invalid Soap Header", NULL);
01469
01470 }
01471
01472
01473
01474
01475
01476
01477
01478 return SOAP_OK;
01479
01480
01481
01482
01483 }
01485 int ns4__msdGetResultSet(struct soap *soap, char* conn_name, char* query_name, char* result_name, array &resset_out)
01486 {
01487 char* cn;
01488 char* qn;
01489 char* rn;
01490 cn = (char*)soap_malloc(soap, strlen(conn_name)+1);
01491 sprintf(cn, "%s",conn_name);
01492 qn = (char*)soap_malloc(soap, strlen(query_name)+1);
01493 sprintf(qn, "%s",query_name);
01494 rn = (char*)soap_malloc(soap, strlen(result_name)+1);
01495 sprintf(rn, "%s",result_name);
01496
01497 MSDConnector *connector = (MSDConnector*)soap->user;
01498 if (!soap->header)
01499 soap->header = (struct SOAP_ENV__Header*)soap_malloc(soap, sizeof(struct SOAP_ENV__Header));
01500 if (soap->header)
01501 { soap->header->h__handle = connector->lookup(CONNECT, cn);
01502 if (soap->header->h__handle){
01503 t__connect * rc =connector->connect(soap->header->h__handle);
01504 soap->header->h__handle = connector->lookup(RESULTSET, rn);
01505 if (soap->header->h__handle){
01506 t__resultset* rs = connector->resultset(soap->header->h__handle);
01507 soap->header->h__handle = connector->lookup(QUERY, qn);
01508 if (soap->header->h__handle){
01509 t__query *qry = connector->query(soap->header->h__handle);
01510
01511 if (qry && rc && rs)
01512 { if (!qry->exf ==1)
01513 {return soap_sender_fault(soap, "Query not executed, no result available.", NULL);
01514 } else{
01515 resset_out.__ptr=rs->prs;
01516 resset_out.__size=rs->cols;
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528 qry=NULL;
01529 rc=NULL;
01530 rs=NULL;
01531
01532 }
01533 } else {
01534 return soap_sender_fault(soap, "Connection, Query, Resultset objects not found", NULL);
01535 }
01536 } else {
01537 return soap_sender_fault(soap, "Query object not found", NULL);
01538 }
01539 } else {
01540 return soap_sender_fault(soap, "Resultset object not found", NULL);
01541 }
01542 } else {
01543 return soap_sender_fault(soap, "Connection object not found", NULL);
01544 }
01545 } else {
01546 return soap_sender_fault(soap, "Invalid Soap Header", NULL);
01547
01548 }
01549
01550
01551
01552
01553
01554
01555 return SOAP_OK;
01556 }
01557
01559 int ns4__msdGetResult(struct soap *soap, char* conn_name, char* query_name, char* result_name, ns4__msdGetResultResponse &res_out)
01560 {
01561 char* cn;
01562 char* qn;
01563 char* rn;
01564 cn = (char*)soap_malloc(soap, strlen(conn_name)+1);
01565 sprintf(cn, "%s",conn_name);
01566 qn = (char*)soap_malloc(soap, strlen(query_name)+1);
01567 sprintf(qn, "%s",query_name);
01568 rn = (char*)soap_malloc(soap, strlen(result_name)+1);
01569 sprintf(rn, "%s",result_name);
01570
01571 MSDConnector *connector = (MSDConnector*)soap->user;
01572 if (!soap->header)
01573 soap->header = (struct SOAP_ENV__Header*)soap_malloc(soap, sizeof(struct SOAP_ENV__Header));
01574 if (soap->header)
01575 { soap->header->h__handle = connector->lookup(CONNECT, cn);
01576 if (soap->header->h__handle){
01577 t__connect * rc =connector->connect(soap->header->h__handle);
01578 soap->header->h__handle = connector->lookup(RESULTSET, rn);
01579 if (soap->header->h__handle){
01580 t__resultset* rs = connector->resultset(soap->header->h__handle);
01581 soap->header->h__handle = connector->lookup(QUERY, qn);
01582 if (soap->header->h__handle){
01583 t__query *qry = connector->query(soap->header->h__handle);
01584
01585 if (qry && rc && rs)
01586 { if (!qry->exf ==1)
01587 {return soap_sender_fault(soap, "Query not executed, no result available.", NULL);
01588 } else{
01589
01590
01591
01592 res_out.rs.cols=rs->cols;
01593 res_out.rs.rows=rs->rows;
01594
01595
01596
01597
01598 res_out.rs.r.__ptr = rs->prs;
01599 res_out.rs.r.__size = rs->cols;
01600
01601 qry=NULL;
01602 rc=NULL;
01603 rs=NULL;
01604
01605 }
01606 } else {
01607 return soap_sender_fault(soap, "Connection, Query, Resultset objects not found", NULL);
01608 }
01609 } else {
01610 return soap_sender_fault(soap, "Query object not found", NULL);
01611 }
01612 } else {
01613 return soap_sender_fault(soap, "Resultset object not found", NULL);
01614 }
01615 } else {
01616 return soap_sender_fault(soap, "Connection object not found", NULL);
01617 }
01618 } else {
01619 return soap_sender_fault(soap, "Invalid Soap Header", NULL);
01620
01621 }
01622
01623
01624
01625
01626
01627
01628 return SOAP_OK;
01629 }
01630
01632
01633 int ns4__msdEndQueryPack(struct soap *soap, char* query_name, char* result_name, int &endqp_out)
01634 { char* qn;
01635 char* rn;
01636 qn = (char*)soap_malloc(soap, strlen(query_name)+1);
01637 sprintf(qn, "%s",query_name);
01638 rn = (char*)soap_malloc(soap, strlen(result_name)+1);
01639 sprintf(rn, "%s",result_name);
01640
01641 MSDConnector *connector = (MSDConnector*)soap->user;
01642 if (!soap->header)
01643 soap->header = (struct SOAP_ENV__Header*)soap_malloc(soap, sizeof(struct SOAP_ENV__Header));
01644 if (soap->header)
01645 {
01646
01647
01648 soap->header->h__handle = connector->lookup(RESULTSET, rn);
01649 if (soap->header->h__handle){
01650 t__resultset* rs = connector->resultset(soap->header->h__handle);
01651 if (rs && rs->hasdata==1)
01652 {for (int n=0;n<rs->cols;++n){
01653 for (int i=0;i<rs->rows ;++i){
01654 if ((*rs->prs[n])[i])
01655 {delete (*rs->prs[n])[i];
01656 }
01657
01658 }
01659 if (rs->prs[n])
01660 {soap_delete(soap, (void*)rs->prs[n]);}
01661 }
01662 }
01663
01664 connector->release(soap->header->h__handle);
01665 soap->header->h__handle = connector->lookup(QUERY, qn);
01666 if (soap->header->h__handle){
01667
01668 connector->release(soap->header->h__handle);
01669 rs=NULL;
01670 endqp_out = 0;
01671 } else { endqp_out = 1;
01672 return soap_sender_fault(soap, "Query object not found", NULL);
01673 }
01674 } else { endqp_out = 2;
01675 return soap_sender_fault(soap, "Resultset object not found", NULL);
01676 }
01677
01678
01679
01680 } else { endqp_out = 4;
01681 return soap_sender_fault(soap, "Invalid Soap Header", NULL);
01682
01683 }
01684
01685
01686
01687
01688
01689 return SOAP_OK;
01690 }
01691
01693
01694 int ns4__msdEndConnect(struct soap *soap, char* conn_name, int &endc_out)
01695 { char* cn;
01696 cn = (char*)soap_malloc(soap, strlen(conn_name)+1);
01697 sprintf(cn, "%s",conn_name);
01698
01699 MSDConnector *connector = (MSDConnector*)soap->user;
01700 if (!soap->header)
01701 soap->header = (struct SOAP_ENV__Header*)soap_malloc(soap, sizeof(struct SOAP_ENV__Header));
01702 if (soap->header)
01703 { soap->header->h__handle = connector->lookup(CONNECT, cn);
01704 if (soap->header->h__handle){
01705 connector->release(soap->header->h__handle);
01706 } else { endc_out = 3;
01707 return soap_sender_fault(soap, "Connection object not found", NULL);
01708 }
01709 } else { endc_out = 4;
01710 return soap_sender_fault(soap, "Invalid Soap Header", NULL);
01711 }
01712 return SOAP_OK;
01713 }
01714
01716 int ns4__msdEndSession(struct soap *soap, char* sessionid, int &ends_out){
01717 extern msdUser supervisor_user;
01718 char* host = (char*)soap_malloc(soap,81);
01719 char* usern = (char*)soap_malloc(soap,81);
01720 char* pass = (char*)soap_malloc(soap,81);
01721 sprintf(host,"%s",supervisor_user.host);
01722 sprintf(usern,"%s", supervisor_user.dbuname);
01723 sprintf(pass,"%s", supervisor_user.getDBPass());
01724 char* loginstr = (char*)soap_malloc(soap,256);
01725 char* sqldel = (char*)soap_malloc(soap,512);
01726 sprintf(sqldel, "delete from ssm_out_tab where session_id = '%s'", sessionid);
01727 sprintf(loginstr,"%s/%s@%s",usern,pass,host);
01728 msdbConnect db;
01729 msdbConnect::msdbInit();
01730 try{
01731 db.rlogon(loginstr);
01732 otl_cursor::direct_exec
01733 (db,sqldel,msdbException::disabled);
01734 }
01735 catch(msdbException& p){
01736 cerr<<p.msg<<endl;
01737 cerr<<p.stm_text<<endl;
01738 cerr<<p.var_info<<endl;
01739 return msd_sender_exception(soap,db,p);
01740 }
01741 db.logoff();
01742 return SOAP_OK;
01743 }
01745 int ns4__msdQuery(struct soap *soap, char* conn_name, char* query_name, char* result_name, char* stm, int &q_status)
01746 { char* cn;
01747 char* qn;
01748 char* rn;
01749 char* qr;
01750 char errmess[512];
01751 cn = (char*)soap_malloc(soap, strlen(conn_name)+1);
01752
01753 sprintf(cn, "%s",conn_name);
01754 qn = (char*)soap_malloc(soap, strlen(query_name)+1);
01755
01756 sprintf(qn, "%s",query_name);
01757 rn = (char*)soap_malloc(soap, strlen(result_name)+1);
01758
01759 sprintf(rn, "%s",result_name);
01760 qr = (char*)soap_malloc(soap, strlen(stm)+1);
01761
01762 sprintf(qr, "%s",stm);
01763
01764 MSDConnector *connector = (MSDConnector*)soap->user;
01765 if (!soap->header)
01766 soap->header = (struct SOAP_ENV__Header*)soap_malloc(soap, sizeof(struct SOAP_ENV__Header));
01767 if (soap->header)
01768 { soap->header->h__handle = connector->lookup(CONNECT, cn);
01769 if (soap->header->h__handle){
01770 t__connect * rc =connector->connect(soap->header->h__handle);
01771 soap->header->h__handle = connector->lookup(RESULTSET, rn);
01772 if (soap->header->h__handle){
01773 t__resultset* rs = connector->resultset(soap->header->h__handle);
01774 soap->header->h__handle = connector->lookup(QUERY, qn);
01775 if (soap->header->h__handle){
01776 sprintf(errmess,"A Query Object with name: %s already exists.", qn);
01777 return soap_sender_fault(soap, errmess, NULL);
01778 }
01779 soap->header->h__handle = connector->create(soap, QUERY, qn);
01780 if (soap->header->h__handle){
01781 t__query *qry = connector->query(soap->header->h__handle);
01782 if (qry && rc && rs)
01783 {qry->set(rc,rs,qr);
01784 qry->exf=0;
01785 qry=NULL;
01786 rc=NULL;
01787 rs=NULL;
01788 q_status = 0;
01789 } else
01790 { q_status = 1;
01791 return soap_sender_fault(soap, "Invalid query Object.", NULL);
01792 }
01793 } else { q_status = 2;
01794 return soap_sender_fault(soap, "Query Object not created.", NULL);
01795 }
01796 } else { q_status = 3;
01797 return soap_sender_fault(soap, "Result Object not found.", NULL);
01798 }
01799
01800 } else { q_status = 4;
01801 return soap_sender_fault(soap, "Connect Object not found.", NULL);
01802 }
01803
01804 } else { q_status = 5;
01805 return soap_sender_fault(soap, "Invalid Soap Header", NULL);
01806 }
01807
01808
01809
01810
01811
01812
01813 return SOAP_OK;
01814 }
01815
01816
01817
01818
01819 int ns4__msdResultset(struct soap *soap, char* conn_name, char* query_name, char* res_name, int &rs_status)
01820 { char* cn;
01821 char* qn;
01822 char* rn;
01823 char errmess[512];
01824 cn = (char*)soap_malloc(soap, strlen(conn_name)+1);
01825
01826 sprintf(cn, "%s",conn_name);
01827 qn = (char*)soap_malloc(soap, strlen(query_name)+1);
01828
01829 sprintf(qn, "%s",query_name);
01830 rn = (char*)soap_malloc(soap, strlen(res_name)+1);
01831
01832 sprintf(rn, "%s",res_name);
01833
01834 MSDConnector *connector = (MSDConnector*)soap->user;
01835 if (!soap->header)
01836 soap->header = (struct SOAP_ENV__Header*)soap_malloc(soap, sizeof(struct SOAP_ENV__Header));
01837 if (soap->header)
01838 {soap->header->h__handle = connector->lookup(CONNECT, cn);
01839 if (soap->header->h__handle){
01840 t__connect * rc =connector->connect(soap->header->h__handle);
01841 soap->header->h__handle = connector->lookup(RESULTSET, rn);
01842 if (soap->header->h__handle){
01843 sprintf(errmess,"A Result Object with name: %s already exists.", rn);
01844 return soap_sender_fault(soap, errmess, NULL);
01845 }
01846 soap->header->h__handle = connector->create(soap, RESULTSET, rn);
01847 if (soap->header->h__handle){
01848 t__resultset * rs = connector->resultset(soap->header->h__handle);
01849 if (rs && rc)
01850 {rs->set(rc, qn);
01851 rs->hasdata=0;
01852 rc=NULL;
01853 rs=NULL;
01854 rs_status = 0;
01855 } else { rs_status = 2;
01856 return soap_sender_fault(soap, "Invalid Result object.", NULL);
01857 }
01858 } else { rs_status = 3;
01859 return soap_sender_fault(soap, "Result Object not found.", NULL);
01860 }
01861
01862 } else { rs_status = 4;
01863 return soap_sender_fault(soap, "Connect Object not found.", NULL);
01864 }
01865
01866 } else { rs_status = 5;
01867 return soap_sender_fault(soap, "Invalid Soap Header", NULL);
01868 }
01869
01870
01871
01872
01873 return SOAP_OK;
01874 }
01875
01876
01877
01878 int ns4__msdLispInit(struct soap *soap, int argc, char* argv[], int &lispinit_result){
01879 lispinit_result = msd_lisp_init(argc, argv);
01880 return SOAP_OK;
01881 }
01882
01883
01884 int ns4__msdLispLoad(struct soap *soap, char * fn, int &lispload_result){
01885 lispload_result = msd_lisp_load(fn);
01886 return SOAP_OK;
01887 }
01888
01889
01890 int ns4__msdLispEval(struct soap *soap, int &lispeval_result){
01891 lispeval_result = msd_lisp_eval();
01892 return SOAP_OK;
01893 }
01894
01895
01896 int ns4__msdWriteTableAtts(struct soap *soap, char* schema, char* connstr, char* fname, int &wta_result){
01897 wta_result = msd_write_table_attributes(schema,connstr, fname);
01898 return SOAP_OK;
01899 }
01900
01901
01902 int ns4__msdGetTablesRelations(struct soap *soap, char* schema, char* connstr, int >r_result){
01903 gtr_result = msd_get_tables_relations(schema,connstr);
01904 return SOAP_OK;
01905 }
01906
01907 int ns4__msdGetDatamodel(struct soap *soap, char* schema, char* connstr, int &gdm_result){
01908 gdm_result = msd_get_datamodel(schema,connstr);
01909 return SOAP_OK;
01910 }
01911
01912
01913
01915 int ns4__echoMap(struct soap *soap, struct a__Map inputMap, struct a__Map & _return )
01916 { _return = inputMap;
01917 return SOAP_OK;
01918 }
01919
01920 int ns4__echoMapArray(struct soap *soap, struct ArrayOfMap inputMapArray, struct ArrayOfMap & returns)
01921 { returns = inputMapArray;
01922
01923
01924 return SOAP_OK;
01925 }
01926
01927
01928
01930 int ns4__msdSSM(struct soap *soap,int numofpars, array *inparams, int &res_ssm){
01931
01932 char* xmlstr = (char*)soap_malloc(soap,4096);
01933 char* xmlstrn = (char*)soap_malloc(soap,4096);
01934 char* infname = (char*)soap_malloc(soap,256);
01935 char* outfname = (char*)soap_malloc(soap,256);
01936
01937 if (inparams)
01938 { inparams->__size=numofpars;
01939 if (!(*inparams)[0])
01940 {return soap_sender_fault(soap, "Missing or bad first argument, which should be XML query.", NULL);
01941 }
01942 if (!(*inparams)[1])
01943 {return soap_sender_fault(soap, "Missing second argument, which should be session number.", NULL);
01944 }
01945 } else
01946 {return soap_sender_fault(soap, "Invalid Array of arguments.", NULL);
01947 }
01948
01949
01950 sprintf(xmlstr,"%s",(*inparams)[0]->__item);
01951
01952
01954 char * pch;
01955 pch = strtok (xmlstr,">");
01956 sprintf (xmlstrn,"%s", "");
01957 while (pch != NULL){
01958
01959 if (pch[0]==' ' || pch[0]=='\n')
01960 { while (pch[0]==' ' || pch[0]=='\n'){
01961 pch++;
01962 }
01963 sprintf (xmlstrn,"%s%s>",xmlstrn, pch);
01964 }else{
01965 sprintf (xmlstrn,"%s%s>",xmlstrn, pch);}
01966 pch = strtok (NULL, ">");
01967 }
01968 sprintf (xmlstr, "%s",xmlstrn);
01969 pch = strtok (xmlstr,">");
01970 sprintf (xmlstrn,"%s", "");
01971 while (pch != NULL)
01972 { if (pch[0]=='<' )
01973 {sprintf (xmlstrn,"%s\n%s>",xmlstrn, pch);
01974 }else{
01975 sprintf (xmlstrn,"%s%s>",xmlstrn, pch);}
01976 pch = strtok (NULL, ">\n");
01977 }
01978 sprintf (xmlstrn,"%s\n",xmlstrn);
01980
01981
01982
01983
01984
01985
01986 sprintf(infname,"/tmp_mnt/net_nfs5/vol4/research-thornton/ssmout/%s_in.xml",(*inparams)[1]->__item);
01987 FILE * pfile;
01988 if (fileexists(infname)== true)
01989 { res_ssm = 4;
01990 return soap_sender_fault(soap, "Invalid session number, Session already exists.",
01991 "<error xmlns=\"http://tempuri.org/\">Session already exists.</error>");
01992
01993
01994
01995 }
01996 pfile = fopen (infname,"w+t");
01997 if (pfile==NULL)
01998 {res_ssm = 3;
01999 return soap_sender_fault(soap, "error: could not create input file. " , NULL);
02000
02001
02002 }
02003 fwrite (xmlstrn , 1 , strlen(xmlstrn), pfile);
02004 fclose (pfile);
02005 pfile=NULL;
02006 sprintf(outfname,"/tmp_mnt/net_nfs5/vol4/research-thornton/ssmout/%s_out.xml",(*inparams)[1]->__item);
02007 char* buff;
02008 char* syscall;
02009 size_t buffsize=0;
02010
02011
02012
02013
02014
02015
02016
02017
02018
02019 char ** tmp = (char**)soap_malloc(soap,5*256);
02020 for (int i=0;i<5 ;i++ ){
02021 tmp[i]= (char*)soap_malloc(soap,256);
02022 }
02023 sprintf(tmp[0],"%s","/ebi/msd/ssm/cgi-bin/ssmserver -offline");
02024 sprintf(tmp[1],"%s",infname);
02025 sprintf(tmp[2],"%s",outfname);
02026 sprintf(tmp[3],"%s","/ebi/msd/ssm/ssmdata/ssm_sawebservice.conf");
02027 sprintf(tmp[4]," > /tmp_mnt/net_nfs5/vol4/research-thornton/ssmout/%s_ssmws.log", (*inparams)[1]->__item);
02028 buff=(char *)soap_malloc(soap, 5*(256+1));
02029 sprintf(buff,"%s",tmp[0]);
02030 for (int i=1;i<5 ;i++ )
02031 {sprintf(buff,"%s %s",buff,tmp[i]);
02032 }
02033
02034
02035
02036 syscall = (char*)soap_malloc(soap, strlen(buff)+1);
02037 sprintf(syscall,"%s", buff);
02038 pfile=fopen (infname,"rt");
02039 if (pfile)
02040 {fclose (pfile);
02041 pfile=NULL;
02042 res_ssm = system(syscall);
02043 }
02044
02045 if (res_ssm < 0){
02046 res_ssm = errno;
02047 }
02048 return SOAP_OK;
02049 }
02050
02051 int ns4__msdSSMPurge(struct soap *soap, char* sessionid, int &res_ssmpurge){
02052 char* syscall = (char*)soap_malloc(soap,512);
02053 sprintf(syscall, "rm -frR /tmp_mnt/net_nfs5/vol4/research-thornton/ssmout/%s_*", sessionid);
02054 res_ssmpurge = system(syscall);
02055 if (res_ssmpurge < 0){
02056 res_ssmpurge = errno;
02057 }
02058 return SOAP_OK;
02059 }
02060
02061
02063 int ns4__msdSSMParser(struct soap *soap, int diyf, char* sessionid, int &res_ssmparser){
02064 extern msdUser supervisor_user;
02065 char* xmlfn = (char*)soap_malloc(soap,256);
02066 char* session = (char*)soap_malloc(soap,64);
02067 char* db_server= (char*)soap_malloc(soap,81);
02068 char* loginstr = (char*)soap_malloc(soap,256);
02069 char* syscall = (char*)soap_malloc(soap,256);
02070 char* fname = (char*)soap_malloc(soap,512);
02071 char* ofname = (char*)soap_malloc(soap,512);
02072 char* typechecker = (char*)soap_malloc(soap,32);
02073 char* tmp = (char*)soap_malloc(soap,64);
02074 char* usern = (char*)soap_malloc(soap,81);
02075 char* pass = (char*)soap_malloc(soap,81);
02076 sprintf(db_server,"%s",supervisor_user.host);
02077 sprintf(usern,"%s", supervisor_user.dbuname);
02078 sprintf(pass,"%s", supervisor_user.getDBPass());
02079
02080 sprintf(loginstr,"%s/%s@%s",usern,pass,db_server);
02081 sprintf(session,"%s",sessionid);
02082 ucase(usern);
02083
02084
02085 sprintf(xmlfn,"/tmp_mnt/net_nfs5/vol4/research-thornton/ssmout/%s_out.xml",session);
02086 sprintf(fname,"/tmp_mnt/net_nfs5/vol4/research-thornton/ssmout/%s_in.xml",session);
02087 sprintf(ofname,"/tmp_mnt/net_nfs5/vol4/research-thornton/ssmout/%s_log.txt",session);
02088 char write_line[1024];
02089 char* stmnt = (char*)soap_malloc(soap,512);
02090
02092 if (sessionid)
02093 {
02094 int j=0;
02095 bool out_file_ok;
02096 if ((out_file_ok=fileexists(xmlfn)== false) && (diyf != 0))
02097 {res_ssmparser = 5;
02098 return soap_sender_fault(soap, "Result fille not ready", NULL);
02099 }
02100 while(j<30*15)
02101 { if (out_file_ok=fileexists(xmlfn)== true)
02102 {
02103 break;}else
02104 {
02105 wait(5);
02106 }
02107 j++;
02108 }
02109
02110 if (!out_file_ok){
02111 res_ssmparser =6;
02112 return soap_sender_fault(soap, "XML SSM file will not be ready in less than 15 minutes.", NULL);}
02114 PCSSMXML SSMXML;
02115 char* queryID = (char*)soap_malloc(soap,500);
02116 char* targetID = (char*)soap_malloc(soap,500);
02117 char* queryCh = (char*)soap_malloc(soap,10);
02118 char* targetCh = (char*)soap_malloc(soap,10);
02119 mat44 RT;
02120 int rc, nMatches;
02121
02122 InitMatType();
02123
02124 SSMXML = new CSSMXML();
02125
02126
02127 rc = SSMXML->readSSMXML ( xmlfn );
02128
02129 if (rc) {
02130 res_ssmparser=rc;
02131
02132 }
02133
02134 nMatches = SSMXML->getNofMatches();
02135 sprintf (write_line, " Total %i matches\n",nMatches );
02136
02137 if (nMatches<=0){
02138 res_ssmparser=2;
02139
02140 }
02141
02142 char* insert_stm = (char*)soap_malloc(soap,4096);
02143
02144 sprintf(stmnt, "insert into %s.ssm_out_tab values ('%s' ", usern, session);
02145
02146 rc = SSMXML->getQueryID ( queryID );
02147
02148 char* table_exists_stm = (char*)soap_malloc(soap,3072);
02149 int n;
02150 char* create_table_stm = (char*)soap_malloc(soap, 3072);
02151 sprintf(create_table_stm, "create table %s.ssm_out_tab(session_id varchar2(64), query_id varchar2(10), target_id varchar2(10), query_chain varchar2(6), target_chain varchar2(6),"
02152 "p_score number, z_score number, rmsd number, r_xx number, r_xy number, r_xz number, r_yx number, r_yy number, r_yz number, r_zx number, r_zy number, r_zz number,"
02153 "t_x number, t_y number, t_z number, pair_query_start varchar2(10), pair_query_end varchar2(10),pair_target_chain varchar2(6), pair_target_start varchar2(6), "
02154 "pair_target_end varchar2(6),querydate varchar2(32) DEFAULT TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS'))", usern);
02155 sprintf(table_exists_stm, "select count(*) "
02156 "from all_objects o where o.object_name like 'SSM_OUT_TAB' and o.owner = '%s'", usern);
02157 msdbConnect db;
02158 msdbConnect::msdbInit();
02159 try{
02160 fprintf(stderr,loginstr);
02161 db.rlogon(loginstr);
02162
02163 msdbStream i(1, table_exists_stm, db);
02164 i >> n;
02165 if (n==0)
02166 {otl_cursor::direct_exec(db,create_table_stm);
02167 }
02168
02169
02170 }
02171 catch(msdbException& p){
02172 cerr<<p.msg<<endl;
02173 cerr<<p.stm_text<<endl;
02174 cerr<<p.var_info<<endl;
02175
02176
02177
02178 return msd_sender_exception(soap,db,p);
02179
02180 }
02181 if (rc==query_pdbentry) {
02182 sprintf(stmnt, "%s, '%s'",stmnt,queryID);
02183
02184 }
02185 else if (rc==query_file) {
02186 sprintf(stmnt, "%s, '%s'",stmnt,queryID);
02187
02188 }
02189 else {
02190 sprintf(stmnt, "%s, NULL",stmnt);
02191
02192 }
02193
02194 for (int i=1;i<=nMatches;i++) {
02195 sprintf (insert_stm,"%s",stmnt);
02196
02197 rc = SSMXML->getTargetID ( targetID,i );
02198 switch (rc) {
02199 case target_pdbentry :
02200 {
02201 sprintf(insert_stm, "%s, '%s'",insert_stm,targetID);
02202
02203 }
02204 break;
02205 case target_file :
02206 {
02207 sprintf(insert_stm, "%s, '%s'",insert_stm,targetID);
02208
02209 }
02210 break;
02211 case target_pdb :
02212 {
02213 sprintf(insert_stm, "%s, '%s'",insert_stm,targetID);
02214
02215 }
02216 break;
02217 case target_scop :
02218 {
02219 sprintf(insert_stm, "%s, '%s'",insert_stm,targetID);
02220
02221 }
02222 break;
02223 case target_scopsubset :
02224 {
02225 sprintf(insert_stm, "%s, '%s'",insert_stm,targetID);
02226
02227 }
02228 break;
02229 default :
02230 {
02231 sprintf(insert_stm, "%s, NULL",insert_stm);}
02232 }
02233
02234 SSMXML->getQueryChain ( queryCh ,i );
02235 SSMXML->getTargetChain ( targetCh,i );
02236
02237
02238 if (!queryCh || strlen(queryCh)==0 || queryCh==NULL)
02239 {sprintf(insert_stm, "%s, NULL",insert_stm);}
02240 else
02241 {sprintf(insert_stm, "%s, '%s'",insert_stm,queryCh);
02242
02243 }
02244 if (!targetCh || strlen(targetCh)==0 || targetCh==NULL)
02245 {sprintf(insert_stm, "%s, NULL",insert_stm);}
02246 else
02247 {sprintf(insert_stm, "%s, '%s'",insert_stm,targetCh);
02248
02249 }
02251
02253 sprintf(typechecker,"%11.4f",SSMXML->getPScore(i));
02254 if (isnum(typechecker))
02255 {sprintf(insert_stm, "%s, %11.4f",insert_stm,SSMXML->getPScore(i));}
02256 else
02257 {sprintf(insert_stm, "%s, NULL",insert_stm);
02258 }
02259 sprintf(typechecker,"%11.4f",SSMXML->getZScore(i));
02260 if (isnum(typechecker))
02261 {sprintf(insert_stm, "%s, %11.4f",insert_stm,SSMXML->getZScore(i));}
02262 else
02263 {sprintf(insert_stm, "%s, NULL",insert_stm);
02264 }
02265 sprintf(typechecker,"%11.4f",SSMXML->getRMSD(i));
02266 if (isnum(typechecker))
02267 {sprintf(insert_stm, "%s, %11.4f",insert_stm,SSMXML->getRMSD(i));}
02268 else
02269 {sprintf(insert_stm, "%s, NULL",insert_stm);
02270 }
02271
02272
02274
02275 rc = SSMXML->getRTMatrix ( RT,i );
02276 if (rc) {
02277
02278 for (int x=0;x<3 ;x++ )
02279 {for (int y=0;y<4 ;y++ )
02280 {sprintf(insert_stm, "%s, NULL",insert_stm);}
02281 }
02282 sprintf(insert_stm, "%s )",insert_stm);
02283
02284 break;
02285 }
02286
02287 for (int x=0;x<3 ;x++ )
02288 {for (int y=0;y<4 ;y++ )
02289 {sprintf(insert_stm, "%s, %10.3f",insert_stm, RT[x][y]);}
02290 }
02291 sprintf(insert_stm, "%s, NULL, NULL, NULL, NULL, NULL, TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS'))",insert_stm);
02292
02293
02294
02295
02296 try
02297 {
02298 otl_cursor::direct_exec(db,insert_stm);
02299 }
02300 catch(msdbException& p){
02301 cerr<<p.msg<<endl;
02302 cerr<<p.stm_text<<endl;
02303 cerr<<p.var_info<<endl;
02304 return msd_sender_exception(soap,db,p);
02305
02306
02307
02308
02309 }
02310
02311 }
02312
02313
02314 db.logoff();
02315
02316 sprintf(syscall, "rm -f %s %s", fname,xmlfn);
02317 res_ssmparser = system(syscall);
02318 if (res_ssmparser < 0){
02319 res_ssmparser = errno;
02320 }else{
02321 res_ssmparser=0;
02322 }
02323
02324
02325
02326
02327
02328
02329
02330
02331
02332
02333 }
02334 else{
02335 res_ssmparser = 3;
02336 return soap_sender_fault(soap, "session id required", NULL);
02337 }
02338 return SOAP_OK;
02339 }
02341
02343
02344
02345
02347
02348
02349
02351 int ns4__msdAppServer(struct soap *soap, int numofpars, array *inparams, int &res_appserver){
02352 inparams->__size=numofpars;
02353 size_t buffsize=0;
02354 char* syscall;
02355 char * buff;
02356 for (int i=0;i<numofpars ;i++ )
02357 {buffsize = buffsize + strlen((*inparams)[i]->__item)+1;
02358 }
02359 buff=(char *)soap_malloc(soap, buffsize);
02360 sprintf(buff,"%s",(*inparams)[0]->__item);
02361 for (int i=1;i<numofpars ;i++ )
02362 {sprintf(buff,"%s %s",buff,(*inparams)[i]->__item);
02363 }
02364 syscall = (char*)soap_malloc(soap, strlen(buff)+1);
02365 sprintf(syscall,"%s", buff);
02366 res_appserver = system(syscall);
02367 if (res_appserver < 0)
02368 {res_appserver = errno;
02369 }
02370 return SOAP_OK;
02371 }
02372
02374 int ns4__msdFasta(struct soap *soap, int numofpars, array *inparams, int &res_fasta){
02375 char* xmlstr=(char*)soap_malloc(soap,4096);
02376 char* infname=(char*)soap_malloc(soap,256);
02377 char* sessionid=(char*)soap_malloc(soap,64);
02378 char* outfname=(char*)soap_malloc(soap,256);
02379 char* sequence=(char*)soap_malloc(soap,3072);
02380 char* evalue=(char*)soap_malloc(soap,256);
02381 char* xmlstrn=(char*)soap_malloc(soap,4096);
02382 char* libref=(char*)soap_malloc(soap,8);
02383 char* library=(char*)soap_malloc(soap,256);
02384
02385
02386
02387
02388
02389
02390
02391
02392
02393
02394
02395 inparams->__size=numofpars;
02396 size_t buffsize=0;
02397 sprintf(xmlstr,"%s",(*inparams)[0]->__item);
02398
02399 xml_Buff=(char*)soap_malloc(soap,strlen(xmlstr)+1);
02400 sprintf(xml_Buff,"%s",xmlstr);
02401 sprintf(sessionid,"%s",(*inparams)[1]->__item);
02402 sprintf(infname,"/tmp_mnt/net_nfs5/vol4/research-thornton/ssmout/%s_in.fasta",sessionid);
02403 sprintf(outfname,"/tmp_mnt/net_nfs5/vol4/research-thornton/ssmout/%s_out.fasta",sessionid);
02404
02405 xml_inf = (msd_xml_element *) soap_malloc(soap, sizeof(msd_xml_element)*10);
02406 xml_txtbuff = (char*)soap_malloc(soap, 3072);
02407
02408
02409
02410 XML_Parser xp = XML_ParserCreate(NULL);
02411 XML_Parser * pxp;
02412 if (! xp) {
02413 fprintf(stderr, "Couldn't allocate memory for parser\n");
02414 exit(-1);
02415 } else {
02416 pxp=(XML_Parser *)soap_malloc(soap, sizeof(XML_Parser));
02417 pxp=&xp;
02418 }
02419
02420
02421
02422 XML_UseParserAsHandlerArg(*pxp);
02423
02424 XML_SetElementHandler(*pxp, start_hndl, end_hndl);
02425 XML_SetCharacterDataHandler(*pxp, char_hndl);
02426 XML_SetProcessingInstructionHandler(*pxp, proc_hndl);
02427 if (! XML_Parse(*pxp, xml_Buff, strlen(xml_Buff), true)) {
02428 fprintf(stderr, "Parse error at line %d:\n%s\n",
02429 XML_GetCurrentLineNumber(*pxp),
02430 XML_ErrorString(XML_GetErrorCode(*pxp)));
02431 exit(-1);
02432 }
02433
02434 XML_ParserFree(xp);
02435
02436 for (int i=0;i<=xml_elno ;i++ ){
02437 if (strcmp(xml_inf[i].tag,"evalue")==0)
02438 {sprintf(evalue,"%s",xml_inf[i].data);}else if (strcmp(xml_inf[i].tag,"sequence")==0)
02439 {removena(xml_inf[i].data);
02440 sprintf(sequence,">Q\n%s\n",xml_inf[i].data);}else if (strcmp(xml_inf[i].tag,"library")==0)
02441 {sprintf(libref,"%s",xml_inf[i].data);}
02442 }
02443
02444
02445
02446 FILE * pfile;
02447 pfile = fopen (infname,"w+t");
02448 if (pfile==NULL)
02449 {cerr << "error: could not create " << infname << endl;
02450 exit(1);}
02451 fwrite (sequence , 1 , strlen(sequence), pfile);
02452
02453
02454 fclose (pfile);
02455 pfile=NULL;
02456
02457
02458
02459
02460 lcase(libref);
02461 if (strcmp(libref, "pdb")==0)
02462 {sprintf(library,"/ebi/msd/ssm/cgi-bin/ws/fasta/pdb_aa.fasta");
02463 }
02464 xml_elno = -1;
02465 char* buff;
02466 char* syscall;
02467
02468
02469
02470 int noarr = 8;
02471 char ** tmp = (char**)soap_malloc(soap,noarr*256);
02472 for (int i=0;i<noarr ;i++ ){
02473 tmp[i]= (char*)soap_malloc(soap,256);
02474 }
02475 sprintf(tmp[0],"%s","bsub -q extsrv_interactive -R msd_ssm -o");
02476 sprintf(tmp[1],"%s",outfname);
02477 sprintf(tmp[2],"%s","/ebi/msd/ssm/cgi-bin/ws/fasta/bin/fasta -Q -H -E ");
02478 sprintf(tmp[3],"%s",evalue);
02479 sprintf(tmp[4],"%s",infname);
02480 sprintf(tmp[5],"%s",library);
02481 sprintf(tmp[6],"%s",">");
02482 sprintf(tmp[7],"%s",outfname);
02483
02484 buff=(char *)soap_malloc(soap, noarr*(256+1));
02485 sprintf(buff,"%s",tmp[0]);
02486 for (int i=1;i<noarr ;i++ )
02487 {sprintf(buff,"%s %s",buff,tmp[i]);
02488
02489
02490 }
02491
02492
02493 sprintf(buff,"%s",tmp[0]);
02494 for (int i=1;i<noarr ;i++ )
02495 {sprintf(buff,"%s %s",buff,tmp[i]);
02496 }
02497
02498
02499
02500 syscall = (char*)soap_malloc(soap, strlen(buff)+1);
02501 sprintf(syscall,"%s", buff);
02502
02503
02504
02505
02506
02507 pfile=fopen (infname,"r+t");
02508 if (pfile)
02509 {
02510 fclose (pfile);
02511 pfile=NULL;
02512
02513 res_fasta = system(syscall);
02514
02515
02516 }
02517
02518
02519 if (res_fasta < 0)
02520 {res_fasta = errno;
02521 }
02522
02523
02524
02525
02526
02527
02528
02529
02530
02531
02532
02533
02534
02535
02536
02537
02538
02539
02540
02541
02542
02543
02544
02545
02546
02547
02548
02549
02550
02551
02552
02553
02554
02555
02556
02557
02558
02559
02560
02561
02562
02563 return SOAP_OK;
02564 }
02566
02567 int ns4__msdFastaParser(struct soap *soap, char* sessionid, int &res_fastaparser){
02568 char* fastafn = (char*)soap_malloc(soap,256);
02569 char* loginstr = (char*)soap_malloc(soap,256);
02570 char* db_server = (char*)soap_malloc(soap,81);
02571 char* fasta_parser = (char*)soap_malloc(soap,256);
02572 char* syscall = (char*)soap_malloc(soap,256);
02573 char* session_id =(char*)soap_malloc(soap, strlen(sessionid)+1);
02574 extern msdUser supervisor_user;
02575 char* usern = (char*)soap_malloc(soap,81);
02576 char* pass = (char*)soap_malloc(soap,81);
02577 sprintf(db_server,"%s",supervisor_user.host);
02578 sprintf(usern,"%s", supervisor_user.dbuname);
02579 sprintf(pass,"%s", supervisor_user.getDBPass());
02580 sprintf(loginstr,"%s/%s@%s",usern,pass,db_server);
02581 strcpy(session_id,sessionid);
02582 ucase(usern);
02583
02584 sprintf(fastafn,"/tmp_mnt/net_nfs5/vol4/research-thornton/ssmout/%s_out.fasta",session_id);
02585 sprintf(fasta_parser,"/tmp_mnt/net_nfs5/vol4/research-thornton/ssmout/%s_in.fasta",session_id);
02586 char* read_line = (char*)soap_malloc(soap,1024);
02587 char* stmnt = (char*)soap_malloc(soap,256);
02588 int j=0;
02589
02590 while(!lsf_file_completed(fastafn) && j<12*15)
02591 { wait(5);
02592 j++;
02593 }
02594
02595
02596
02597 ifstream infile;
02598 infile.open(fastafn);
02599
02600
02601
02602 char * search = ">>";
02603 char * replace = "Record No.";
02604 char * linebuf = (char*)soap_malloc(soap,256);
02605 char * tempbuf = (char*)soap_malloc(soap,256);
02606 char * lastTok = (char*)soap_malloc(soap,256);
02607 char * record = (char*)soap_malloc(soap,7000);
02608 char * tmprec = (char*)soap_malloc(soap,7000);
02609 char * evalue_result = (char*)soap_malloc(soap,16);
02610 char * id_chain = (char*)soap_malloc(soap,16);
02611 char * id = (char*)soap_malloc(soap,12);
02612 char * chain = (char*)soap_malloc(soap,4);
02613 char * alignment = (char*)soap_malloc(soap,6000);
02614 char* midbuf = (char*)soap_malloc(soap,12);
02615 char* tmp = (char*)soap_malloc(soap,16);
02616 char * outBuf = (char*)soap_malloc(soap,6000);
02617
02618 char * pchs;
02619 char * pche;
02620
02621 char * per;
02622 char * tok;
02623 char * pid;
02624 char * pch;
02625 char * token = (char*)soap_malloc(soap,16);
02626 int start,end,len,newrecord,recno;
02627 newrecord=0;
02628 char* insert_stm = (char*)soap_malloc(soap,4096);
02629 sprintf(stmnt, "insert into fasta_out_tab values ('%s' ", session_id);
02630 char* table_exists_stm = (char*)soap_malloc(soap,3072);
02631 int n;
02632 char* create_table_stm = (char*)soap_malloc(soap, 3072);
02633 sprintf(create_table_stm, "create table %s.fasta_out_tab(session_id varchar2(64), e_value_result varchar2(16), lib_id_and_chain varchar2(16), lib_id varchar2(12), chain varchar2(4),"
02634 "alignment blob, querydate varchar2(32) DEFAULT TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS'))", usern);
02635 sprintf(table_exists_stm, "select count(*) "
02636 "from all_objects o where o.object_name like 'FASTA_OUT_TAB' and o.owner = '%s'", usern);
02637 msdbConnect db;
02638 msdbConnect::msdbInit();
02639 try{
02640 db.rlogon(loginstr);
02641
02642
02643
02644
02645 otl_long_string alignment_blob(6000);
02646 db.set_max_long_size(6000);
02647 msdbStream i(1, table_exists_stm, db);
02648 i >> n;
02649 if (n==0)
02650 {otl_cursor::direct_exec(db,create_table_stm);
02651 }
02652
02653
02654
02655
02656
02657
02658
02660
02661
02662 msdbStream o(1,
02663 "insert into fasta_out_tab values(:session_id<char[64]>,:e_value_result<char[16]>,:lib_id_and_chain<char[16]>, "
02664 ":lib_id<char[12]>,:chain<char[4]>,empty_blob(),TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS')) returning alignment into :alignment<blob> ",
02665 db );
02666 recno=0;
02667 do {
02668 infile.getline(linebuf, 256);
02669 if(linebuf != NULL)
02670 { strcpy(tempbuf, linebuf);
02671 pchs = strstr (tempbuf, ">>");
02672 pche = strstr (tempbuf, "Library scan:");
02673 if ((pchs != NULL) || (newrecord == 1) || (pche != NULL))
02674 {
02675 sprintf(record,"%s%s\n",record, linebuf);
02676 do {
02677 infile.getline(linebuf, 256);
02678 if(linebuf != NULL)
02679 {strcpy(tempbuf, linebuf);
02680 pchs = strstr (tempbuf, ">>");
02681 pche = strstr (tempbuf, "Library scan:");
02682 if ((pchs == NULL) && (pche == NULL)){
02683 sprintf(record,"%s%s\n",record, linebuf);
02684 }else{
02685
02686
02687 sprintf(tmprec,"%s",record);
02688 per = strstr (tmprec,":");
02689 tok = strtok (tmprec," ");
02690 sprintf(token,"%s", tok);
02691 len=strlen(token);
02692 start=per-tok+1;
02693 end=len;
02694 midcopy(token,midbuf,start,end);
02695 sprintf(id_chain,"%s",midbuf);
02696 sprintf(tmp,"%s",id_chain);
02697 pid = strtok (tmp,"_");
02698 sprintf(id,"%s",pid);
02699 start=strlen(id)+1;
02700 end=strlen(id_chain);
02701 if (start != end)
02702 {midcopy(id_chain,chain,start,end);
02703 }else sprintf(chain,"%s","");
02704
02705 sprintf(tmprec,"%s",record);
02706 per = strstr (tmprec,"E():");
02707 tok = strtok(per,"\n");
02708 sprintf(token,"%s", tok);
02709 start=per-tok+5;
02710 end=strlen(token);
02711 midcopy(token,midbuf,start,end);
02712 sprintf(evalue_result,"%s",midbuf);
02713 sprintf(tmprec,"%s",record);
02714 per = strstr (tmprec,"Q ");
02715 sprintf(alignment,"%s",per-68);
02716
02717
02718
02719
02720
02721
02722
02723
02724
02725
02726 recno++;
02727 len=strlen(alignment);
02728
02729 for (int i=0;i< len ;i++ )
02730 {alignment_blob[i] = alignment[i];
02731 }
02732 alignment_blob.set_len(len+1);
02733 o << session_id << evalue_result << id_chain << id << chain << alignment_blob;
02734 sprintf(record,"%s","");
02735 sprintf(record,"%s\n", linebuf);
02736 newrecord=1;
02737
02738 }
02739 }
02740 } while ((pchs == NULL) && !infile.eof() && (pche == NULL));
02741 }
02742 }
02743 else linebuf[0] = '0';
02744
02745 } while ( ! infile.eof());
02746
02748
02749
02750
02751
02752
02753
02754
02755
02756
02757
02758
02759
02760
02761
02762
02763 }
02764 catch(msdbException& p){
02765 cerr<<p.msg<<endl;
02766 cerr<<p.stm_text<<endl;
02767 cerr<<p.var_info<<endl;
02768 return msd_sender_exception(soap,db,p);
02769
02770
02771
02772 }
02773
02774 db.logoff();
02775 infile.close();
02776
02777 sprintf(syscall, "rm -f %s %s", fasta_parser,fastafn);
02778
02779 if (res_fastaparser < 0){
02780 res_fastaparser = errno;
02781 }else{
02782 res_fastaparser=0;
02783 }
02784
02785 return SOAP_OK;
02786 }
02788
02789
02790
02791
02792
02793
02794
02795
02796
02797
02798
02799
02800
02801
02802
02803
02804
02805
02806
02807
02808
02809
02811
02812
02813
02814
02815
02816
02817
02818
02819
02820
02821
02824
02825
02826
02827
02828
02829
02830
02831
02832
02833
02834
02836
02837
02838
02839
02840
02841
02842
02843
02844
02845
02846
02847
02848
02849
02850
02851
02852
02854
02855
02856
02857
02858
02859
02860
02861
02863
02864
02865
02866
02867
02868
02869
02870
02871
02872
02873
02874
02875
02876
02877
02878
02879
02880
02884
02885
02886
02887
02888
02889
02890
02891
02892
02893
02894
02895
02896
02897
02898
02900
02901
02902
02903
02904
02905
02907
02908