# 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.php"
    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   /* for servlet engines only */
    00099   char *servlet_ctx, *servlet_context_string;
    00100
    00101   void (*handle_request)(proxyenv *env);
    00102
    00103   void (*writeCreateObjectBegin)(proxyenv *env, char*name, size_t strlen, char createInstance, void *result);
    00104   void (*writeCreateObjectEnd)(proxyenv *env);
    00105   void (*writeInvokeBegin)(proxyenv *env, long object, char*method, size_t strlen, char property, void* result);
    00106   void (*writeInvokeEnd)(proxyenv *env);
    00107   void (*writeResultBegin)(proxyenv *env, void* result);
    00108   void (*writeResultEnd)(proxyenv *env);
    00109   void (*writeGetMethodBegin)(proxyenv *env, long object, char*method, size_t strlen, void* result);
    00110   void (*writeGetMethodEnd)(proxyenv *env);
    00111   void (*writeCallMethodBegin)(proxyenv *env, long object, long method, void* result);
    00112   void (*writeCallMethodEnd)(proxyenv *env);
    00113   void (*writeString)(proxyenv *env, char*name, size_t strlen);
    00114   void (*writeBoolean)(proxyenv *env, short boolean);
    00115   void (*writeLong)(proxyenv *env, long l);
    00116   void (*writeDouble)(proxyenv *env, double d);
    00117   void (*writeObject)(proxyenv *env, long object);
    00118   void (*writeException)(proxyenv *env, long object, char*str, size_t len);
    00119   void (*writeCompositeBegin_a)(proxyenv *env);
    00120   void (*writeCompositeBegin_h)(proxyenv *env);
    00121   void (*writeCompositeEnd)(proxyenv *env);
    00122   void (*writePairBegin_s)(proxyenv *env, char*key, size_t strlen);
    00123   void (*writePairBegin_n)(proxyenv *env, unsigned long key);
    00124   void (*writePairBegin)(proxyenv *env);
    00125   void (*writePairEnd)(proxyenv *env);
    00126   void (*writeUnref)(proxyenv *env, long object);
    00127   void (*finish)(proxyenv *env);
    00128
    00129   ssize_t (*f_recv)(proxyenv*env, void *buf, size_t len);
    00130   ssize_t (*f_recv0)(proxyenv*env, void *buf, size_t len);
    00131   ssize_t (*f_send)(proxyenv*env, int peer, const void *buf, size_t len);
    00132   ssize_t (*f_send0)(proxyenv*env, int peer, const void *buf, size_t len);
    00133 };
    00134
    00135 #endif