Skip to content

Commit 806fd17

Browse files
committed
add captcha notification
- pull request from tonsense (pyload#10) - updated to thrift 0.9.3 - synchronized access to thrift client
1 parent 5fc04e7 commit 806fd17

File tree

96 files changed

+78711
-63067
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+78711
-63067
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,7 @@
9797

9898
<activity android:name=".RemoteSettings" android:label="@string/remotesettings_activity"/>
9999

100+
<service android:name=".service.CheckCaptchaService" />
101+
100102
</application>
101103
</manifest>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.thrift;
20+
21+
import org.apache.thrift.async.AsyncMethodCallback;
22+
import org.apache.thrift.protocol.TMessage;
23+
import org.apache.thrift.protocol.TMessageType;
24+
import org.apache.thrift.protocol.TProtocol;
25+
import org.apache.thrift.server.AbstractNonblockingServer;
26+
27+
public abstract class AsyncProcessFunction<I, T, R> {
28+
final String methodName;
29+
30+
public AsyncProcessFunction(String methodName) {
31+
this.methodName = methodName;
32+
}
33+
34+
protected abstract boolean isOneway();
35+
36+
public abstract void start(I iface, T args, AsyncMethodCallback<R> resultHandler) throws TException;
37+
38+
public abstract T getEmptyArgsInstance();
39+
40+
public abstract AsyncMethodCallback getResultHandler(final AbstractNonblockingServer.AsyncFrameBuffer fb, int seqid);
41+
42+
public String getMethodName() {
43+
return methodName;
44+
}
45+
46+
public void sendResponse(final AbstractNonblockingServer.AsyncFrameBuffer fb, final TBase result, final byte type, final int seqid) throws TException {
47+
TProtocol oprot = fb.getOutputProtocol();
48+
49+
oprot.writeMessageBegin(new TMessage(getMethodName(), type, seqid));
50+
result.write(oprot);
51+
oprot.writeMessageEnd();
52+
oprot.getTransport().flush();
53+
54+
fb.responseReady();
55+
}
56+
}

app/src/main/java/org/apache/thrift/EncodingUtils.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,67 @@ public static final int decodeBigEndian(final byte[] buf, int offset) {
8282
| ((buf[offset + 2] & 0xff) << 8) | ((buf[offset + 3] & 0xff));
8383
}
8484

85+
/**
86+
* Bitfield utilities.
87+
* Returns true if the bit at position is set in v.
88+
*/
89+
public static final boolean testBit(byte v, int position) {
90+
return testBit((int)v, position);
91+
}
92+
93+
public static final boolean testBit(short v, int position) {
94+
return testBit((int)v, position);
95+
}
96+
97+
public static final boolean testBit(int v, int position) {
98+
return (v & (1 << position)) != 0;
99+
}
100+
101+
public static final boolean testBit(long v, int position) {
102+
return (v & (1L << position)) != 0L;
103+
}
104+
105+
/**
106+
* Returns v, with the bit at position set to zero.
107+
*/
108+
public static final byte clearBit(byte v, int position) {
109+
return (byte)clearBit((int)v, position);
110+
}
111+
112+
public static final short clearBit(short v, int position) {
113+
return (short)clearBit((int)v, position);
114+
}
115+
116+
public static final int clearBit(int v, int position) {
117+
return v & ~(1 << position);
118+
}
119+
120+
public static final long clearBit(long v, int position) {
121+
return v & ~(1L << position);
122+
}
123+
124+
/**
125+
* Returns v, with the bit at position set to 1 or 0 depending on value.
126+
*/
127+
public static final byte setBit(byte v, int position, boolean value) {
128+
return (byte)setBit((int)v, position, value);
129+
}
130+
131+
public static final short setBit(short v, int position, boolean value) {
132+
return (short)setBit((int)v, position, value);
133+
}
134+
135+
public static final int setBit(int v, int position, boolean value) {
136+
if(value)
137+
return v | (1 << position);
138+
else
139+
return clearBit(v, position);
140+
}
141+
142+
public static final long setBit(long v, int position, boolean value) {
143+
if(value)
144+
return v | (1L << position);
145+
else
146+
return clearBit(v, position);
147+
}
85148
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.thrift;
21+
22+
/**
23+
* Implementation of the Option type pattern
24+
*/
25+
public abstract class Option<T> {
26+
27+
/**
28+
* Whether the Option is defined or not
29+
* @return
30+
* true if the Option is defined (of type Some)
31+
* false if the Option is not defined (of type None)
32+
*/
33+
public abstract boolean isDefined();
34+
35+
/**
36+
* Get the value of the Option (if it is defined)
37+
* @return the value
38+
* @throws IllegalStateException if called on a None
39+
*/
40+
public abstract T get();
41+
42+
/**
43+
* Get the contained value (if defined) or else return a default value
44+
* @param other what to return if the value is not defined (a None)
45+
* @return either the value, or other if the value is not defined
46+
*/
47+
public T or(T other) {
48+
if (isDefined()) {
49+
return get();
50+
} else {
51+
return other;
52+
}
53+
}
54+
/**
55+
* The None type, representing an absent value (instead of "null")
56+
*/
57+
public static class None<T> extends Option<T> {
58+
public boolean isDefined() {
59+
return false;
60+
}
61+
62+
public T get() {
63+
throw new IllegalStateException("Cannot call get() on None");
64+
}
65+
66+
public String toString() {
67+
return "None";
68+
}
69+
}
70+
71+
/**
72+
* The Some type, representing an existence of some value
73+
* @param <T> The type of value
74+
*/
75+
public static class Some<T> extends Option<T> {
76+
private final T value;
77+
public Some(T value) {
78+
this.value = value;
79+
}
80+
81+
public boolean isDefined() {
82+
return true;
83+
}
84+
85+
public T get() {
86+
return value;
87+
}
88+
89+
public String toString() {
90+
return "Some("+value.toString()+")";
91+
}
92+
}
93+
94+
/**
95+
* Wraps value in an Option type, depending on whether or not value is null
96+
* @param value
97+
* @param <T> type of value
98+
* @return Some(value) if value is not null, None if value is null
99+
*/
100+
public static <T> Option<T> fromNullable(T value) {
101+
if (value != null) {
102+
return new Some<T>(value);
103+
} else {
104+
return new None<T>();
105+
}
106+
}
107+
108+
/**
109+
* Wrap value in a Some type (NB! value must not be null!)
110+
* @param value
111+
* @param <T> type of value
112+
* @return a new Some(value)
113+
*/
114+
public static <T> Some<T> some(T value) {
115+
return new Some<T>(value);
116+
}
117+
118+
public static <T> None<T> none() {
119+
return new None<T>();
120+
}
121+
}

app/src/main/java/org/apache/thrift/ProcessFunction.java

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
import org.apache.thrift.protocol.TMessageType;
88
import org.apache.thrift.protocol.TProtocol;
99
import org.apache.thrift.protocol.TProtocolException;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
1012

1113
public abstract class ProcessFunction<I, T extends TBase> {
1214
private final String methodName;
1315

16+
private static final Logger LOGGER = LoggerFactory.getLogger(ProcessFunction.class.getName());
17+
1418
public ProcessFunction(String methodName) {
1519
this.methodName = methodName;
1620
}
@@ -29,18 +33,36 @@ public final void process(int seqid, TProtocol iprot, TProtocol oprot, I iface)
2933
return;
3034
}
3135
iprot.readMessageEnd();
32-
TBase result = getResult(iface, args);
33-
oprot.writeMessageBegin(new TMessage(getMethodName(), TMessageType.REPLY, seqid));
34-
result.write(oprot);
35-
oprot.writeMessageEnd();
36-
oprot.getTransport().flush();
36+
TBase result = null;
37+
38+
try {
39+
result = getResult(iface, args);
40+
} catch(TException tex) {
41+
LOGGER.error("Internal error processing " + getMethodName(), tex);
42+
TApplicationException x = new TApplicationException(TApplicationException.INTERNAL_ERROR,
43+
"Internal error processing " + getMethodName());
44+
oprot.writeMessageBegin(new TMessage(getMethodName(), TMessageType.EXCEPTION, seqid));
45+
x.write(oprot);
46+
oprot.writeMessageEnd();
47+
oprot.getTransport().flush();
48+
return;
49+
}
50+
51+
if(!isOneway()) {
52+
oprot.writeMessageBegin(new TMessage(getMethodName(), TMessageType.REPLY, seqid));
53+
result.write(oprot);
54+
oprot.writeMessageEnd();
55+
oprot.getTransport().flush();
56+
}
3757
}
3858

39-
protected abstract TBase getResult(I iface, T args) throws TException;
59+
protected abstract boolean isOneway();
60+
61+
public abstract TBase getResult(I iface, T args) throws TException;
4062

41-
protected abstract T getEmptyArgsInstance();
63+
public abstract T getEmptyArgsInstance();
4264

4365
public String getMethodName() {
4466
return methodName;
4567
}
46-
}
68+
}

app/src/main/java/org/apache/thrift/TApplicationException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public class TApplicationException extends TException {
4545
public static final int MISSING_RESULT = 5;
4646
public static final int INTERNAL_ERROR = 6;
4747
public static final int PROTOCOL_ERROR = 7;
48+
public static final int INVALID_TRANSFORM = 8;
49+
public static final int INVALID_PROTOCOL = 9;
50+
public static final int UNSUPPORTED_CLIENT_TYPE = 10;
4851

4952
protected int type_ = UNKNOWN;
5053

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.thrift;
20+
21+
import org.apache.thrift.protocol.*;
22+
23+
import org.apache.thrift.server.AbstractNonblockingServer.*;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
26+
27+
import java.util.Collections;
28+
import java.util.Map;
29+
30+
public interface TAsyncProcessor {
31+
/**
32+
* Implementations must call fb.responseReady() once processing is complete
33+
*/
34+
public boolean process(final AsyncFrameBuffer fb) throws TException;
35+
}

0 commit comments

Comments
 (0)