# protocol.h

Go to the documentation of this file.

    00001 /*-*- mode: C; tab-width:4 -*-*/
    00002
    00010 #ifndef JAVA_PROTOCOL_H
    00011 #define JAVA_PROTOCOL_H
    00012
    00013 /* peer */
    00014 #include <stdio.h>
    00015 #ifdef __MINGW32__
    00016 # include <winsock2.h>
    00017 # define close closesocket
    00018 #else
    00019 # include <sys/types.h>
    00020 # include <sys/socket.h>
    00021 #endif
    00022
    00023 /*
    00024  * we create a unix domain socket with the name .php_java_bridge in
    00025  * the tmpdir
    00026  */
    00027 #ifndef P_tmpdir
    00028 /* xopen, normally defined in stdio.h */
    00029 #define P_tmpdir "/tmp"
    00030 #endif
    00031 #define SOCKNAME P_tmpdir"/.php_java_bridge""XXXXXX"
    00032 /* Linux: pipes created in the shared memory */
    00033 #define SOCKNAME_SHM "/dev/shm/.php_java_bridge""XXXXXX"
    00034
    00035
    00036 /*
    00037  * default log file is System.out
    00038  */
    00039 #define LOGFILE ""
    00040
    00041 #define LOG_OFF 0
    00042 #define LOG_FATAL 1
    00043 #define LOG_ERROR 2 /* default level */
    00044 #define LOG_INFO 3
    00045 #define LOG_DEBUG 4
    00046 #define DEFAULT_LEVEL "2"
    00047
    00048 #define N_JAVA_SARGS 9
    00049 #define N_JAVA_SENV 3
    00050 #define N_MONO_SARGS 6
    00051 #define N_MONO_SENV 1
    00052 #define DEFAULT_MONO_PORT "9167" /* default port for tcp/ip */
    00053 #define DEFAULT_JAVA_PORT "9267" /* default port for tcp/ip */
    00054 #define DEFAULT_JAVA_WRAPPER EXTENSION_DIR"/RunJavaBridge"
    00055 #define DEFAULT_MONO_WRAPPER EXTENSION_DIR"/RunMonoBridge"
    00056 #define DEFAULT_HOST "127.0.0.1"
    00057 #define DEFAULT_SERVLET "/JavaBridge/JavaBridge.phpjavabridge"
    00058
    00059 #define RECV_SIZE 8192 // initial size of the receive buffer
    00060 #define MAX_ARGS 100   // max # of method arguments
    00061
    00062 /* checks if we use a servlet backend (re-directed or not) */
    00063 #define IS_SERVLET_BACKEND(env) (((*env)->servlet_ctx || EXT_GLOBAL (get_servlet_context) (TSRMLS_C)))
    00064
    00065 /* checks if the servlet backend uses HTTP, either because we do not
    00066    re-direct or because we override re-direct */
    00067 #define IS_OVERRIDE_REDIRECT(env) ((((*env)->peer0!=-1) || EXT_GLOBAL (get_servlet_context) (TSRMLS_C)))
    00068
    00069 typedef struct proxyenv_ *proxyenv;
    00070 struct proxyenv_ {
    00071
    00072   /* peer */
    00073   int peer, peerr, peer0;       /* peer0 contains peer during override
    00074                                    redirect */
    00075   short peer_redirected;        /* remains true during override
    00076                                    redirect */
    00077   struct sockaddr orig_peer_saddr; /* only valid if peer is a servlet, it
    00078                                    points to the original peer */
    00079
    00080
    00081   /* used by the parser implementation */
    00082   unsigned char*s; size_t len;
    00083   ssize_t pos, c;
    00084   unsigned char recv_buf[RECV_SIZE];
    00085
    00086   /* the send buffer */
    00087   unsigned char*send;
    00088   size_t send_len, send_size;
    00089
    00090   char *server_name;
    00091
    00092   /* local server (not a servlet engine) */
    00093   short is_local;
    00094
    00095   /* for servlets: re-open connection */
    00096   short must_reopen;
    00097
    00098   struct async_ctx {
    00099     void (*handle_request)(proxyenv *env);
    00100     long nextValue;
    00101     void *result;
    00102     FILE *peer;
    00103     ssize_t (*f_send)(proxyenv*env, const void *buf, size_t len);
    00104   } async_ctx;
    00105
    00106   /* for servlet engines only */
    00107   char *servlet_ctx;
    00108   char *servlet_context_string; /* original rinit value from
    00109                                    get_servlet_context() */
    00110   short backend_has_session_proxy;
    00111
    00112   void (*handle)(proxyenv *env);
    00113   void (*handle_request)(proxyenv *env);
    00114
    00115   void (*writeCreateObjectBegin)(proxyenv *env, char*name, size_t strlen, char createInstance, void *result);
    00116   void (*writeCreateObjectEnd)(proxyenv *env);
    00117   void (*writeInvokeBegin)(proxyenv *env, long object, char*method, size_t strlen, char property, void* result);
    00118   void (*writeInvokeEnd)(proxyenv *env);
    00119   void (*writeResultBegin)(proxyenv *env, void* result);
    00120   void (*writeResultEnd)(proxyenv *env);
    00121   void (*writeString)(proxyenv *env, char*name, size_t strlen);
    00122   void (*writeBoolean)(proxyenv *env, short boolean);
    00123   void (*writeLong)(proxyenv *env, long l);
    00124   void (*writeDouble)(proxyenv *env, double d);
    00125   void (*writeObject)(proxyenv *env, long object);
    00126   void (*writeException)(proxyenv *env, long object, char*str, size_t len);
    00127   void (*writeCompositeBegin_a)(proxyenv *env);
    00128   void (*writeCompositeBegin_h)(proxyenv *env);
    00129   void (*writeCompositeEnd)(proxyenv *env);
    00130   void (*writePairBegin_s)(proxyenv *env, char*key, size_t strlen);
    00131   void (*writePairBegin_n)(proxyenv *env, unsigned long key);
    00132   void (*writePairBegin)(proxyenv *env);
    00133   void (*writePairEnd)(proxyenv *env);
    00134   void (*writeUnref)(proxyenv *env, long object);
    00135   void (*finish)(proxyenv *env);
    00136
    00137   ssize_t (*f_recv)(proxyenv*env, void *buf, size_t len);
    00138   ssize_t (*f_recv0)(proxyenv*env, void *buf, size_t len);
    00139   ssize_t (*f_send)(proxyenv*env, const void *buf, size_t len);
    00140   ssize_t (*f_send0)(proxyenv*env, const void *buf, size_t len);
    00141 };
    00142
    00143 #endif