# 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
    00033 /*
    00034  * default log file is System.out
    00035  */
    00036 #define LOGFILE ""
    00037
    00038 #define LOG_OFF 0
    00039 #define LOG_FATAL 1
    00040 #define LOG_ERROR 2 /* default level */
    00041 #define LOG_INFO 3
    00042 #define LOG_DEBUG 4
    00043 #define DEFAULT_LEVEL "2"
    00044
    00045 #define N_JAVA_SARGS 9
    00046 #define N_JAVA_SENV 3
    00047 #define N_MONO_SARGS 6
    00048 #define N_MONO_SENV 1
    00049 #define DEFAULT_MONO_PORT "9167" /* default port for tcp/ip */
    00050 #define DEFAULT_JAVA_PORT "9267" /* default port for tcp/ip */
    00051 #define DEFAULT_JAVA_WRAPPER EXTENSION_DIR"/RunJavaBridge"
    00052 #define DEFAULT_MONO_WRAPPER EXTENSION_DIR"/RunMonoBridge"
    00053 #define DEFAULT_HOST "127.0.0.1"
    00054 #define DEFAULT_SERVLET "/JavaBridge/JavaBridge.php"
    00055
    00056 #define RECV_SIZE 8192 // initial size of the receive buffer
    00057 #define MAX_ARGS 100   // max # of method arguments
    00058
    00059 /* checks if we use a servlet backend (re-directed or not) */
    00060 #define IS_SERVLET_BACKEND(env) (((*env)->servlet_ctx || EXT_GLOBAL (get_servlet_context) (TSRMLS_C)))
    00061
    00062 /* checks if the servlet backend uses HTTP, either because we do not
    00063    re-direct or because we override re-direct */
    00064 #define IS_OVERRIDE_REDIRECT(env) ((((*env)->peer0!=-1) || EXT_GLOBAL (get_servlet_context) (TSRMLS_C)))
    00065
    00066 typedef struct proxyenv_ *proxyenv;
    00067 struct proxyenv_ {
    00068
    00069   /* peer */
    00070   int peer, peer0;              /* peer0 contains peer during override
    00071                                    redirect */
    00072   short peer_redirected;        /* remains true during override
    00073                                    redirect */
    00074   struct sockaddr orig_peer_saddr; /* only valid if peer is a servlet, it
    00075                                    points to the original peer */
    00076
    00077
    00078   /* used by the parser implementation */
    00079   unsigned char*s; size_t len;
    00080   ssize_t pos, c;
    00081   unsigned char recv_buf[RECV_SIZE];
    00082
    00083   /* the send buffer */
    00084   unsigned char*send;
    00085   size_t send_len, send_size;
    00086
    00087   char *server_name;
    00088
    00089   /* local server (not a servlet engine) */
    00090   short is_local;
    00091
    00092   /* for servlets: re-open connection */
    00093   short must_reopen;
    00094
    00095   /* for servlet engines only */
    00096   char *servlet_ctx, *servlet_context_string;
    00097
    00098   void (*handle_request)(proxyenv *env);
    00099
    00100   void (*writeCreateObjectBegin)(proxyenv *env, char*name, size_t strlen, char createInstance, void *result);
    00101   void (*writeCreateObjectEnd)(proxyenv *env);
    00102   void (*writeInvokeBegin)(proxyenv *env, long object, char*method, size_t strlen, char property, void* result);
    00103   void (*writeInvokeEnd)(proxyenv *env);
    00104   void (*writeResultBegin)(proxyenv *env, void* result);
    00105   void (*writeResultEnd)(proxyenv *env);
    00106   void (*writeGetMethodBegin)(proxyenv *env, long object, char*method, size_t strlen, void* result);
    00107   void (*writeGetMethodEnd)(proxyenv *env);
    00108   void (*writeCallMethodBegin)(proxyenv *env, long object, long method, void* result);
    00109   void (*writeCallMethodEnd)(proxyenv *env);
    00110   void (*writeString)(proxyenv *env, char*name, size_t strlen);
    00111   void (*writeBoolean)(proxyenv *env, short boolean);
    00112   void (*writeLong)(proxyenv *env, long l);
    00113   void (*writeDouble)(proxyenv *env, double d);
    00114   void (*writeObject)(proxyenv *env, long object);
    00115   void (*writeException)(proxyenv *env, long object, char*str, size_t len);
    00116   void (*writeCompositeBegin_a)(proxyenv *env);
    00117   void (*writeCompositeBegin_h)(proxyenv *env);
    00118   void (*writeCompositeEnd)(proxyenv *env);
    00119   void (*writePairBegin_s)(proxyenv *env, char*key, size_t strlen);
    00120   void (*writePairBegin_n)(proxyenv *env, unsigned long key);
    00121   void (*writePairBegin)(proxyenv *env);
    00122   void (*writePairEnd)(proxyenv *env);
    00123   void (*writeUnref)(proxyenv *env, long object);
    00124   void (*finish)(proxyenv *env);
    00125 };
    00126
    00127 #endif