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