/[dgee]/dgee/pythonvm/pythonServices.c
ViewVC logotype

Diff of /dgee/pythonvm/pythonServices.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by ajmitch, Sun Jun 29 20:07:03 2003 UTC revision 1.2 by csmith, Sun Sep 21 10:36:02 2003 UTC
# Line 0  Line 1 
1    /*
2     * DotGNU Execution Environment Core
3     *
4     * python VM Goldwater Services
5     *
6     * Copyright (C) 2003 netFluid Technology Ltd
7     *
8     * This program is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License as published by
10     * the Free Software Foundation; either version 2 of the License, or
11     * (at your option) any later version.
12     *
13     * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     * GNU General Public License for more details.
17     *
18     * You should have received a copy of the GNU General Public License
19     * along with this program; if not, write to the Free Software
20     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21     *
22     * $Revision$  $Date$
23     *
24     * --------------------------------------------------------------------------
25     */
26    
27    #include <gwtypes.h>
28    #include <gwclient.h>
29    #include <gwapi.h>
30    #include <gwlog.h>
31    #include <gwmsgchain.h>
32    
33    #include "pythonvm.h"
34    #include "dgreadenv.h"
35    
36    #include "../fields/dgfid.h"
37    
38    static MsgChain * fetch_bytecode( char *wsname );
39    
40    /* ------------------------------------------------------------------------- */
41    /* Entry point for GWService runWS.
42     *
43     * Input:
44     *   Data stream containing:  (field, occurrance, description)
45     *      DGF_WS_NAME      1    - Webservice Assebmly DLL name
46     *      DGF_REQ_DATA     1    - Request XML to pass to WebService
47     *      DGF_CLASS_NAME   1    - Class name in assembly that contains method
48     *      DGF_METHOD_NAME  1    - The method to call in the class in the assembly
49     *    
50     * Output:
51     *   Webservice is executed and passed request data.
52     */
53    void
54    runWS( char *svc, GWMessage *reqm )
55    {
56      GWStatus   state  = GWFailure;
57    
58      MsgChain *request   = NULL;
59      MsgChain *bc_stream = NULL;
60      MsgChain *replyMC   = NULL;
61    
62      char  *stream  = NULL;
63      char  *ctype   = NULL;
64      char  *param   = NULL;
65      char  *wsname  = NULL;
66      char  *class   = NULL;
67      char  *method  = NULL;
68      char  *bcode   = NULL;
69      char *replyXML = NULL;
70      long   wlen    = 0;
71      long   clen    = 0;
72      long   mlen    = 0;
73      long   blen    = 0;
74      int    pix     = 0;
75      int    i       = 0;
76      
77      char *args[70] = {0};
78    
79    
80      do {
81        /* Instantiate a 'message buffer' from input data stream
82         */
83        if( (request = gwmc_import( reqm->data )) == NULL ) {
84          gw_logf( LOG_ERROR, "Could not instantiate request message buffer" );
85              break;
86        }
87      
88      
89        /* Extract URI, WebService ID and Request Data
90         */
91        ctype = MIME_TEXT_PLAIN;
92        wsname = (char*)gwmc_read_data( request, DGF_WS_NAME,     &ctype, 1, &wlen);
93        class  = (char*)gwmc_read_data( request, DGF_CLASS_NAME,  &ctype, 1, &clen);
94        method = (char*)gwmc_read_data( request, DGF_METHOD_NAME, &ctype, 1, &mlen);
95      
96        if( !(wsname && class && method) ) {
97          gw_logf( LOG_ERROR, "Insufficient parameters in input" );
98              gwusrerr = ERR_INTERNAL_FAILURE;
99              break;
100        }
101    
102      
103        gw_logf( LOG_DEBUG, "Fetch Webservice '%s' from Resource Manager", wsname );
104      
105        if( (bc_stream = fetch_bytecode( wsname )) == NULL ) {
106          gw_logf(LOG_ERROR, "Failure Requesting webservice from Resource Manager");
107              gwusrerr = ERR_INTERNAL_FAILURE;
108              break;
109        }
110      
111        if( bc_stream ) {
112          /* We've got some bytecode to execute
113               */
114          ctype = MIME_OCTET_STREAM;
115          bcode = (char*)gwmc_read_data(bc_stream, DGF_APP_BYTECODE, &ctype, 1, &blen);
116          gw_logf( LOG_DEBUG, "Passing WS to python VM" );
117          /* Get request data
118               */
119          
120    
121          
122          pix = 1;
123          ctype = MIME_TEXT_XML;
124          if( (param = (char*)gwmc_read_data( request, DGF_REQ_DATA, &ctype,
125                                                       pix, &wlen) ) == NULL ) {
126                gwusrerr = ERR_VM_FAILURE;
127            gw_logf( LOG_ERROR, "No xmlrpc request found in input" );
128                break;
129          }
130    
131          i = 0;
132          args[i++] = bcode;
133          args[i++] = param;
134          args[i++] = wsname;
135          args[i++] = class;
136          args[i++] = method;
137    
138              /* At this point we have the following:
139               * bcode  = webservice to execute
140               * param  = request data
141               * wsname = Name of webservice
142               * class  = 'type' of webservice, as extracted from the dgmx data
143               * method = method within 'type' that is the entry point for the WS
144               *          (Note this may come from the dgmx data and not directly from
145               *           the request data as it may be an alias.  You should ALWAYS
146               *           use THIS method name if provided and not the one in the
147               *           request!)
148               */
149    
150              /* TODO
151               * 1. Arrange for suitable VM to be invoked and pass it the set of
152               *    data above.
153               * 2. Invoke the required webservice in the VM
154               * 3. Get the reply data back as a char* (replyXML below)
155               */
156    
157          if( pythonvm_entry(i-1, args) == 0 ) {
158      
159                if( (replyXML = pythonvm_get_reply() ) != NULL ) {
160      
161              if( (replyMC = gwmc_create() ) != NULL ) {
162                gwmc_add_data( replyMC, DGF_XMLRPC_REPLY, MIME_TEXT_XML,
163                                            replyXML, strlen(replyXML) );
164      
165                if( (stream = gwmc_get_message_ptr( replyMC, &blen )) != NULL ) {
166                              gwusrerr = ERR_NO_ERROR;
167                  state = GWSuccess;
168                }
169      
170              } else gw_logf( LOG_ERROR, "Failed to create message" );
171      
172                } else gw_logf( LOG_ERROR, "Webservice Returned no data" );
173          }
174        }
175      } while(0);
176      
177      /* Return XML back to client (or gwusrerr if GWFailure)
178       */
179      if( state == GWSuccess ) gw_send_reply( state, stream, blen );
180      else gw_send_reply( state, "", 0 );
181    
182      /* Do Cleanups Here */
183      pythonvm_cleanup();
184    
185      /* Cleanup Messages
186       */
187      if( request  ) gwmc_destroy( &request   );
188      if( bc_stream) gwmc_destroy( &bc_stream );
189      if( replyMC  ) gwmc_destroy( &replyMC   );
190    
191      return;
192    }
193    
194    /* ------------------------------------------------------------------------- */
195    
196    static MsgChain *
197    fetch_bytecode( char *wsname )
198    {
199      GWMessage  replymsg = {0};
200    
201      MsgChain  *request  = NULL;
202    
203      void *stream = NULL;
204    
205      long  len = 0;
206      int   ret = 0;
207    
208      if( !wsname ) {
209        gw_logf( LOG_ERROR, "No WebService Name Supplied" );
210        return NULL;
211      }
212    
213      /* Create a request buffer and populate it...
214       */
215      if( (request = gwmc_create() ) == NULL ) {
216        gw_logf( LOG_ERROR, "Failed to create message" );
217        return NULL;
218      }
219    
220      ret = -1;
221      do {
222        gwmc_add_data( request, DGF_WS_NAME, MIME_TEXT_PLAIN,
223                                    wsname, strlen(wsname) );
224    
225        /* Get data stream to send
226         */
227        if( (stream = gwmc_get_message_ptr( request, &len )) == NULL ) {
228          gw_logf( LOG_ERROR, "Failed to get message stream" );
229              break;
230        }
231                        
232        if( ( ret = gw_svc_call( "/DGEE/RM/GetBytecode", stream, len, &replymsg, 0 )) < 0 ){
233              gw_logf( LOG_ERROR, "gw_svc_call for '/DGEE/RM/GetBytecode' failed with code %d [%s]\n", gwerror, gw_errorstr(gwerror) );
234              break;
235        }
236    
237        /* We've now got a message with bytecode embedded within it
238             */
239      } while(0);
240    
241      gwmc_destroy( &request );
242    
243      if( ret < 0 ) {
244        /* Drop all memory */
245        gw_free_message( &replymsg );
246            return NULL;
247      }
248    
249      if( (request = gwmc_importGWMessage( &replymsg )) == NULL ) {
250        gw_logf( LOG_ERROR, "Could not instantiate reply message buffer" );
251        return NULL;
252      }
253    
254      return request;
255    }
256    
257    /* ------------------------------------------------------------------------- */
258    /* end */

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26