Menu

[r559]: / phprpc_3.0 / java / PHPRPC_Server.java  Maximize  Restore  History

Download this file

776 lines (771 with data), 31.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
/**********************************************************\
| |
| The implementation of PHPRPC Protocol 3.0 |
| |
| PHPRPC_Server.java |
| |
| Release 3.0.2 |
| Copyright by Team-PHPRPC |
| |
| WebSite: http://www.phprpc.org/ |
| http://www.phprpc.net/ |
| http://www.phprpc.com/ |
| http://sourceforge.net/projects/php-rpc/ |
| |
| Authors: Ma Bingyao <andot@ujn.edu.cn> |
| |
| This file may be distributed and/or modified under the |
| terms of the GNU Lesser General Public License (LGPL) |
| version 3.0 as published by the Free Software Foundation |
| and appearing in the included file LICENSE. |
| |
\**********************************************************/
/* PHPRPC_Server class.
*
* Copyright: Ma Bingyao <andot@ujn.edu.cn>
* Version: 3.0.2
* LastModified: Feb 16, 2009
* This library is free. You can redistribute it and/or modify it.
*
/*
* Example usage:
*
* rpc.jsp
<%@ page import="java.lang.*" %>
<%@ page import="org.phprpc.*" %>
<%
PHPRPC_Server phprpc_server = new PHPRPC_Server();
phprpc_server.add("min", Math.class);
phprpc_server.add(new String[] { "sin", "cos" }, Math.class);
phprpc_server.start(request, response);
%>
*/
package org.phprpc;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.InvocationTargetException;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.OutputStreamWriter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.zip.GZIPOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.phprpc.util.Cast;
import org.phprpc.util.PHPSerializer;
import org.phprpc.util.Base64;
import org.phprpc.util.XXTEA;
import org.phprpc.util.DHParams;
final class RemoteFunction {
public Object obj;
public Method[] functions;
public RemoteFunction(Object obj, Method[] functions) {
this.obj = obj;
this.functions = functions;
}
}
final public class PHPRPC_Server {
private HttpServletRequest request;
private HttpServletResponse response;
private HttpSession session;
private PHPSerializer phpser;
private HashMap functions;
private boolean debug;
private String charset;
private boolean encode;
private boolean byref;
private boolean encrypt;
private boolean enableGZIP;
private int encryptMode;
private byte[] key;
private int keylen;
private BigInteger y;
private String output;
private String callback;
private int errno;
private String errstr;
private String cid;
private StringBuffer buffer;
private static HashMap globalFunctions = new HashMap();
private static boolean add(String[] funcnames, Object obj, Class cls, String[] aliases, HashMap functions) {
if (aliases == null) {
aliases = funcnames;
}
if (funcnames.length != aliases.length) {
return false;
}
Method[] methods = cls.getMethods();
for (int i = 0, n = funcnames.length; i < n; i++) {
ArrayList fs = new ArrayList();
for (int j = 0, m = methods.length; j < m; j++) {
int mod = methods[j].getModifiers();
if (funcnames[i].toLowerCase().equals(methods[j].getName().toLowerCase())
&& Modifier.isPublic(mod) && (obj == null) == (Modifier.isStatic(mod))) {
fs.add(methods[j]);
}
}
functions.put(aliases[i].toLowerCase(), new RemoteFunction(obj, (Method[])fs.toArray(new Method[fs.size()])));
}
return true;
}
private static boolean addGlobal(String[] funcnames, Object obj, Class cls, String[] aliases) {
return add(funcnames, obj, cls, aliases, globalFunctions);
}
private boolean add(String[] funcnames, Object obj, Class cls, String[] aliases) {
return add(funcnames, obj, cls, aliases, functions);
}
private static String[] getAllFunctions(Class cls) {
Method[] methods = cls.getDeclaredMethods();
HashMap names = new HashMap();
for (int i = 0, n = methods.length; i < n; i++) {
if (Modifier.isPublic(methods[i].getModifiers())) {
String fn = methods[i].getName().toLowerCase();
names.put(fn, fn);
}
}
Object[] fo = names.keySet().toArray();
String[] fs = new String[fo.length];
System.arraycopy(fo, 0, fs, 0, fo.length);
return fs;
}
private String toHexString(int n) {
return ((n < 16) ? "0" : "") + Integer.toHexString(n);
}
private String addJsSlashes(String str) {
char[] s = str.toCharArray();
StringBuffer sb = new StringBuffer();
for (int i = 0, n = s.length; i < n; i++) {
if (s[i] <= 31 ||
s[i] == 34 ||
s[i] == 39 ||
s[i] == 92 ||
s[i] == 127) {
sb.append("\\x");
sb.append(toHexString((int)s[i] & 0xff));
}
else {
sb.append(s[i]);
}
}
return sb.toString();
}
private String addJsSlashes(byte[] s) {
StringBuffer sb = new StringBuffer();
for (int i = 0, n = s.length; i < n; i++) {
if (s[i] <= 31 ||
s[i] == 34 ||
s[i] == 39 ||
s[i] == 92 ||
s[i] >= 127) {
sb.append("\\x");
sb.append(toHexString((int)s[i] & 0xff));
}
else {
sb.append((char)s[i]);
}
}
return sb.toString();
}
private String encodeString(String s) throws UnsupportedEncodingException {
if (encode) {
return Base64.encode(s.getBytes(charset));
}
else {
return addJsSlashes(s);
}
}
private String encodeString(byte[] s) {
if (encode) {
return Base64.encode(s);
}
else {
return addJsSlashes(s);
}
}
private byte[] encryptString(byte[] s, int level) {
if (encryptMode >= level) {
s = XXTEA.encrypt(s, key);
}
return s;
}
private byte[] decryptString(byte[] s, int level) {
if (encryptMode >= level) {
s = XXTEA.decrypt(s, key);
}
return s;
}
private void sendURL() throws UnsupportedEncodingException {
if (!request.isRequestedSessionIdValid() || session.isNew()) {
StringBuffer url = request.getRequestURL();
Enumeration e = request.getParameterNames();
if (e.hasMoreElements()) {
url.append('?');
do {
String query = (String)e.nextElement();
if (!query.toLowerCase().startsWith("phprpc_")) {
String[] values = request.getParameterValues(query);
for (int i = 0, n = values.length; i < n; i++) {
url.append(query).append('=').append(URLEncoder.encode(values[i], charset)).append('&');
}
}
} while (e.hasMoreElements());
url.setLength(url.length() - 1);
}
buffer.append("phprpc_url=\"");
buffer.append(encodeString(response.encodeURL(url.toString())));
buffer.append("\";\r\n");
}
}
private void gzip(byte[] s) throws IOException {
String acceptEncoding = request.getHeader("Accept-Encoding");
if (acceptEncoding != null && acceptEncoding.indexOf("gzip") != -1) {
ByteArrayOutputStream bs = new ByteArrayOutputStream();
GZIPOutputStream gzips = new GZIPOutputStream(bs);
gzips.write(s);
gzips.finish();
if (s.length > bs.size()) {
response.setHeader("Content-Encoding", "gzip");
response.setContentLength(bs.size());
bs.writeTo(response.getOutputStream());
return;
}
}
response.setContentLength(s.length);
response.getOutputStream().write(s);
}
private void sendCallback() throws IOException {
buffer.append(callback);
String buf = buffer.toString();
if (enableGZIP) {
gzip(buf.getBytes(charset));
}
else {
response.getWriter().write(buf);
}
response.flushBuffer();
}
private void sendFunctions() throws IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
buffer.append("phprpc_functions=\"");
functions.putAll(globalFunctions);
buffer.append(encodeString(phpser.serialize(functions.keySet().toArray())));
buffer.append("\";\r\n");
sendCallback();
}
private void sendOutput() throws IOException {
if (encryptMode >= 3) {
buffer.append("phprpc_output=\"");
buffer.append(encodeString(XXTEA.encrypt(output.getBytes(charset), key)));
buffer.append("\";\r\n");
}
else {
buffer.append("phprpc_output=\"");
buffer.append(encodeString(output));
buffer.append("\";\r\n");
}
}
private void sendError() throws IOException {
buffer.append("phprpc_errno=\"");
buffer.append(errno);
buffer.append("\";\r\n");
buffer.append("phprpc_errstr=\"");
buffer.append(encodeString(errstr));
buffer.append("\";\r\n");
sendOutput();
sendCallback();
}
private void sendHeader() {
response.setContentType("text/plain; charset=" + charset);
response.setHeader("P3P", "CP=\"CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV\"");
response.setHeader("X-Powered-By", "PHPRPC Server/3.0");
response.setDateHeader("Expires", (new Date()).getTime());
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
}
private byte[] call(Method function, Object obj, ArrayList arguments) throws Throwable {
Class[] p = function.getParameterTypes();
String funcname = function.getName();
ByteArrayOutputStream bs = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(bs, false, charset);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(bs, charset), false);
int size = arguments.size();
if (p.length != size) {
if (session == null) {
session = request.getSession(true);
}
if (p.length == size + 1) {
String className = p[p.length - 1].getName();
if (className.equals("javax.servlet.http.HttpServletRequest")) {
arguments.add(request);
}
else if (className.equals("javax.servlet.http.HttpSession")) {
arguments.add(session);
}
else if (className.equals("javax.servlet.ServletContext")) {
arguments.add(session.getServletContext());
}
else if (className.equals("java.io.PrintStream")) {
arguments.add(ps);
}
else if (className.equals("java.io.PrintWriter")) {
arguments.add(pw);
}
else {
throw new IllegalArgumentException("number of arguments mismatch for " + funcname + "().");
}
}
else if (p.length == size + 2) {
String className1 = p[p.length - 2].getName();
String className2 = p[p.length - 1].getName();
if (className1.equals("javax.servlet.http.HttpServletRequest") &&
className2.equals("java.io.PrintStream")) {
arguments.add(request);
arguments.add(ps);
}
else if (className1.equals("javax.servlet.http.HttpServletRequest") &&
className2.equals("java.io.PrintWriter")) {
arguments.add(request);
arguments.add(pw);
}
else if (className1.equals("java.io.PrintStream") &&
className2.equals("javax.servlet.http.HttpServletRequest")) {
arguments.add(ps);
arguments.add(request);
}
else if (className1.equals("java.io.PrintWriter") &&
className2.equals("javax.servlet.http.HttpServletRequest")) {
arguments.add(pw);
arguments.add(request);
}
else if (className1.equals("javax.servlet.http.HttpSession") &&
className2.equals("java.io.PrintStream")) {
arguments.add(session);
arguments.add(ps);
}
else if (className1.equals("javax.servlet.http.HttpSession") &&
className2.equals("java.io.PrintWriter")) {
arguments.add(session);
arguments.add(pw);
}
else if (className1.equals("java.io.PrintStream") &&
className2.equals("javax.servlet.http.HttpSession")) {
arguments.add(ps);
arguments.add(session);
}
else if (className1.equals("java.io.PrintWriter") &&
className2.equals("javax.servlet.http.HttpSession")) {
arguments.add(pw);
arguments.add(session);
}
else if (className1.equals("javax.servlet.ServletContext") &&
className2.equals("java.io.PrintStream")) {
arguments.add(session.getServletContext());
arguments.add(ps);
}
else if (className1.equals("javax.servlet.ServletContext") &&
className2.equals("java.io.PrintWriter")) {
arguments.add(session.getServletContext());
arguments.add(pw);
}
else if (className1.equals("java.io.PrintStream") &&
className2.equals("javax.servlet.ServletContext")) {
arguments.add(ps);
arguments.add(session.getServletContext());
}
else if (className1.equals("java.io.PrintWriter") &&
className2.equals("javax.servlet.ServletContext")) {
arguments.add(pw);
arguments.add(session.getServletContext());
}
else {
throw new IllegalArgumentException("number of arguments mismatch for " + funcname + "().");
}
}
else {
throw new IllegalArgumentException("number of arguments mismatch for " + funcname + "().");
}
}
Object[] args = arguments.toArray();
while (size < arguments.size()) {
arguments.remove(size);
}
for (int i = 0, n = args.length; i < n; i++) {
if (args[i] != null) {
args[i] = Cast.cast(args[i], p[i], charset);
}
}
byte[] result = null;
try {
result = phpser.serialize(function.invoke(obj, args));
}
catch (IllegalAccessException e1) {
throw new IllegalArgumentException(e1.getMessage() + " for " + funcname + "().");
}
catch (IllegalArgumentException e2) {
throw new IllegalArgumentException(e2.getMessage() + " for " + funcname + "().");
}
catch (NullPointerException e3) {
throw new NullPointerException(e3.getMessage() + " for " + funcname + "().");
}
catch (ExceptionInInitializerError e4) {
Throwable e5 = e4.getCause();
if (e5 != null) {
throw e5;
}
throw new ExceptionInInitializerError(e4.getMessage() + " for " + funcname + "().");
}
catch (InvocationTargetException e6) {
Throwable e7 = e6.getCause();
if (e7 != null) {
throw e7;
}
throw new InvocationTargetException(null, e6.getMessage() + " for " + funcname + "().");
}
ps.close();
pw.close();
output = new String(bs.toByteArray(), charset);
return result;
}
private boolean getBooleanRequest(String name) {
boolean var = true;
if (request.getParameter(name) != null &&
request.getParameter(name).toLowerCase().equals("false")) {
var = false;
}
return var;
}
private void initEncode() {
encode = getBooleanRequest("phprpc_encode");
}
private void initRef() {
byref = getBooleanRequest("phprpc_ref");
}
private void initErrorHandler() {
errno = 0;
errstr = "";
output = "";
}
private void initCallback() throws UnsupportedEncodingException {
if (request.getParameter("phprpc_callback") != null) {
callback = new String(Base64.decode(request.getParameter("phprpc_callback")), charset);
}
else {
callback = "";
}
}
private void initClientID() {
cid = "0";
if (request.getParameter("phprpc_id") != null) {
cid = request.getParameter("phprpc_id");
}
cid = "phprpc_" + cid;
}
private void initKeylen() {
if (request.getParameter("phprpc_keylen") != null) {
keylen = Integer.parseInt(request.getParameter("phprpc_keylen"));
}
else {
HashMap sessionObject = (HashMap)session.getAttribute(cid);
if (sessionObject != null && sessionObject.get("keylen") != null){
keylen = ((Integer)sessionObject.get("keylen")).intValue();
}
else {
keylen = 128;
}
}
}
private void initEncrypt() {
encrypt = false;
encryptMode = 0;
y = null;
if (request.getParameter("phprpc_encrypt") != null) {
String enc = request.getParameter("phprpc_encrypt").toLowerCase();
if (enc.equals("true")) {
encrypt = true;
}
else if (enc.equals("false")) {
encrypt = false;
}
else if (enc.equals("0")) {
encryptMode = 0;
}
else if (enc.equals("1")) {
encryptMode = 1;
}
else if (enc.equals("2")) {
encryptMode = 2;
}
else if (enc.equals("3")) {
encryptMode = 3;
}
else {
y = new BigInteger(enc);
}
}
}
private void initKey() throws Exception {
if (encryptMode > 0) {
if (session == null) {
session = request.getSession(true);
}
HashMap sessionObject = (HashMap)session.getAttribute(cid);
if (sessionObject != null && sessionObject.get("key") != null) {
key = (byte[])sessionObject.get("key");
}
else {
encryptMode = 0;
throw new Exception("Can't find the key for decryption.");
}
}
}
private ArrayList getArguments() throws UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
ArrayList arguments;
if (request.getParameter("phprpc_args") != null) {
arguments = (ArrayList)phpser.unserialize(decryptString(Base64.decode(request.getParameter("phprpc_args")), 1), ArrayList.class);
}
else {
arguments = new ArrayList();
}
return arguments;
}
private void callFunction() throws Throwable {
String funcname = request.getParameter("phprpc_func").toLowerCase();
RemoteFunction rf = null;
if (functions.containsKey(funcname)) {
rf = (RemoteFunction)functions.get(funcname);
}
else if (globalFunctions.containsKey(funcname)) {
rf = (RemoteFunction)globalFunctions.get(funcname);
}
else {
throw new NoSuchMethodException("Can't find this function " + request.getParameter("phprpc_func") + "().");
}
initKey();
ArrayList arguments = getArguments();
String result = null;
for (int i = 0, n = rf.functions.length; i < n; i++) {
try {
result = encodeString(encryptString(call(rf.functions[i], rf.obj, arguments), 2));
break;
}
catch (Throwable e) {
if (i == n - 1) {
errstr = "";
throw e;
}
else {
errno = 2;
if (debug) {
StackTraceElement[] st = e.getStackTrace();
StringBuffer es = new StringBuffer(e.toString()).append("\r\n");
for (int j = 0, m = st.length; j < m; j++) {
es.append(st[j].toString()).append("\r\n");
}
errstr += es.toString();
}
else {
errstr += e.toString();
}
}
}
}
buffer.append("phprpc_result=\"");
buffer.append(result);
buffer.append("\";\r\n");
if (byref) {
buffer.append("phprpc_args=\"");
buffer.append(encodeString(encryptString(phpser.serialize(arguments), 1)));
buffer.append("\";\r\n");
}
sendError();
}
private void keyExchange() throws IOException, IllegalAccessException, NoSuchAlgorithmException, IllegalArgumentException, InvocationTargetException {
HashMap sessionObject;
if (session == null) {
session = request.getSession(true);
}
initKeylen();
if (encrypt) {
DHParams dhParams = new DHParams(keylen);
keylen = dhParams.getL();
BigInteger p = dhParams.getP();
BigInteger g = dhParams.getG();
BigInteger x = dhParams.getX();
BigInteger y = g.modPow(x, p);
sessionObject = new HashMap();
sessionObject.put("x", x);
sessionObject.put("p", p);
sessionObject.put("keylen", new Integer(keylen));
session.setAttribute(cid, sessionObject);
HashMap dhp = dhParams.getDHParams();
dhp.put("y", y.toString());
buffer.append("phprpc_encrypt=\"");
buffer.append(encodeString(phpser.serialize(dhp)));
buffer.append("\";\r\n");
if (keylen != 128) {
buffer.append("phprpc_keylen=\"");
buffer.append(keylen);
buffer.append("\";\r\n");
}
sendURL();
}
else {
sessionObject = (HashMap)session.getAttribute(cid);
BigInteger x = (BigInteger)sessionObject.get("x");
BigInteger p = (BigInteger)sessionObject.get("p");
BigInteger k = y.modPow(x, p);
byte[] tempkey;
if (keylen == 128) {
tempkey = k.toByteArray();
}
else {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(k.toString().getBytes());
tempkey = md5.digest();
}
key = new byte[16];
for (int i = 1, n = Math.min(tempkey.length, 16); i <= n; i++) {
key[16 - i] = tempkey[tempkey.length - i];
}
sessionObject.put("key", key);
sessionObject.remove("x");
sessionObject.remove("p");
session.setAttribute(cid, sessionObject);
}
sendCallback();
}
public PHPRPC_Server() {
phpser = new PHPSerializer();
functions = new HashMap();
charset = "UTF-8";
debug = false;
enableGZIP = false;
}
public static boolean addGlobal(Object obj) {
Class cls = obj.getClass();
return addGlobal(getAllFunctions(cls), obj, cls, null);
}
public static boolean addGlobal(Class cls) {
return addGlobal(getAllFunctions(cls), null, cls, null);
}
public static boolean addGlobal(Object obj, Class cls) {
return addGlobal(getAllFunctions(cls), obj, cls, null);
}
public static boolean addGlobal(String function, Object obj) {
return addGlobal(new String[] { function }, obj, obj.getClass(), null);
}
public static boolean addGlobal(String function, Object obj, String alias) {
return addGlobal(new String[] { function }, obj, obj.getClass(), new String[] { alias });
}
public static boolean addGlobal(String[] functions, Object obj) {
return addGlobal(functions, obj, obj.getClass(), null);
}
public static boolean addGlobal(String[] functions, Object obj, String[] aliases) {
return addGlobal(functions, obj, obj.getClass(), aliases);
}
public static boolean addGlobal(String function, Class cls) {
return addGlobal(new String[] { function }, null, cls, null);
}
public static boolean addGlobal(String function, Class cls, String alias) {
return addGlobal(new String[] { function }, null, cls, new String[] { alias });
}
public static boolean addGlobal(String[] functions, Class cls) {
return addGlobal(functions, null, cls, null);
}
public static boolean addGlobal(String[] functions, Class cls, String[] aliases) {
return addGlobal(functions, null, cls, aliases);
}
public boolean add(Object obj) {
Class cls = obj.getClass();
return add(getAllFunctions(cls), obj, cls, null);
}
public boolean add(Class cls) {
return add(getAllFunctions(cls), null, cls, null);
}
public boolean add(Object obj, Class cls) {
return add(getAllFunctions(cls), obj, cls, null);
}
public boolean add(String function, Object obj) {
return add(new String[] { function }, obj, obj.getClass(), null);
}
public boolean add(String function, Object obj, String alias) {
return add(new String[] { function }, obj, obj.getClass(), new String[] { alias });
}
public boolean add(String[] functions, Object obj) {
return add(functions, obj, obj.getClass(), null);
}
public boolean add(String[] functions, Object obj, String[] aliases) {
return add(functions, obj, obj.getClass(), aliases);
}
public boolean add(String function, Class cls) {
return add(new String[] { function }, null, cls, null);
}
public boolean add(String function, Class cls, String alias) {
return add(new String[] { function }, null, cls, new String[] { alias });
}
public boolean add(String[] functions, Class cls) {
return add(functions, null, cls, null);
}
public boolean add(String[] functions, Class cls, String[] aliases) {
return add(functions, null, cls, aliases);
}
public void setCharset(String charset) {
this.charset = charset;
phpser.setCharset(charset);
}
public void setDebugMode(boolean debug) {
this.debug = debug;
}
public void setEnableGZIP(boolean enableGZIP) {
this.enableGZIP = enableGZIP;
}
public void start(HttpServletRequest request, HttpServletResponse response) throws IOException {
this.request = request;
this.response = response;
response.resetBuffer();
session = null;
buffer = new StringBuffer();
try {
initErrorHandler();
sendHeader();
initClientID();
initEncode();
initCallback();
initRef();
initEncrypt();
if (request.getParameter("phprpc_func") != null) {
callFunction();
}
else if (encrypt != false || y != null) {
keyExchange();
}
else {
sendFunctions();
}
}
catch (Throwable e) {
errno = 1;
if (debug) {
StackTraceElement[] st = e.getStackTrace();
StringBuffer es = new StringBuffer(e.toString()).append("\r\n");
for (int i = 0, n = st.length; i < n; i++) {
es.append(st[i].toString()).append("\r\n");
}
errstr = es.toString();
}
else {
errstr = e.toString();
}
sendError();
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.