mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
add opentracing spans for metrics
This commit is contained in:
committed by
Travis Reeder
parent
1cc1a5ad49
commit
dc5e67b6d2
117
vendor/github.com/apache/thrift/lib/Makefile.am
generated
vendored
Normal file
117
vendor/github.com/apache/thrift/lib/Makefile.am
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
SUBDIRS = json xml
|
||||
PRECROSS_TARGET =
|
||||
|
||||
if WITH_CPP
|
||||
# cpp dir is picked directly by plugin build
|
||||
if !WITH_PLUGIN
|
||||
SUBDIRS += cpp
|
||||
endif
|
||||
endif
|
||||
|
||||
if WITH_C_GLIB
|
||||
SUBDIRS += c_glib
|
||||
endif
|
||||
|
||||
if WITH_MONO
|
||||
SUBDIRS += csharp
|
||||
endif
|
||||
|
||||
if WITH_JAVA
|
||||
SUBDIRS += java
|
||||
PRECROSS_TARGET += precross-java
|
||||
# JavaScript unit test depends on java
|
||||
# so test only if java, ant & co is available
|
||||
SUBDIRS += js
|
||||
endif
|
||||
|
||||
if WITH_PYTHON
|
||||
SUBDIRS += py
|
||||
endif
|
||||
|
||||
if WITH_ERLANG
|
||||
SUBDIRS += erl
|
||||
endif
|
||||
|
||||
if WITH_RUBY
|
||||
SUBDIRS += rb
|
||||
endif
|
||||
|
||||
if WITH_HASKELL
|
||||
SUBDIRS += hs
|
||||
endif
|
||||
|
||||
if WITH_PERL
|
||||
SUBDIRS += perl
|
||||
endif
|
||||
|
||||
if WITH_PHP
|
||||
SUBDIRS += php
|
||||
endif
|
||||
|
||||
if WITH_DART
|
||||
SUBDIRS += dart
|
||||
endif
|
||||
|
||||
if WITH_DOTNETCORE
|
||||
SUBDIRS += netcore
|
||||
endif
|
||||
|
||||
if WITH_GO
|
||||
SUBDIRS += go
|
||||
endif
|
||||
|
||||
if WITH_D
|
||||
SUBDIRS += d
|
||||
PRECROSS_TARGET += precross-d
|
||||
endif
|
||||
|
||||
if WITH_NODEJS
|
||||
SUBDIRS += nodejs
|
||||
PRECROSS_TARGET += precross-nodejs
|
||||
endif
|
||||
|
||||
if WITH_LUA
|
||||
SUBDIRS += lua
|
||||
endif
|
||||
|
||||
if WITH_RS
|
||||
SUBDIRS += rs
|
||||
endif
|
||||
|
||||
# All of the libs that don't use Automake need to go in here
|
||||
# so they will end up in our release tarballs.
|
||||
EXTRA_DIST = \
|
||||
as3 \
|
||||
cocoa \
|
||||
d \
|
||||
dart \
|
||||
delphi \
|
||||
haxe \
|
||||
javame \
|
||||
js \
|
||||
ocaml \
|
||||
st \
|
||||
ts
|
||||
|
||||
precross-%:
|
||||
$(MAKE) -C $* precross
|
||||
precross: $(PRECROSS_TARGET)
|
||||
180
vendor/github.com/apache/thrift/lib/as3/build.xml
generated
vendored
Executable file
180
vendor/github.com/apache/thrift/lib/as3/build.xml
generated
vendored
Executable file
@@ -0,0 +1,180 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
<project name="libthrift-as3" default="compile" basedir="."
|
||||
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
|
||||
|
||||
<property name="as3.artifactid" value="${ant.project.name}"/>
|
||||
|
||||
<property name="thrift.root" location="${basedir}/../../"/>
|
||||
<property name="thrift.java.dir" location="${thrift.root}/lib/java"/>
|
||||
<property name="build.tools.dir" location="${thrift.java.dir}/build/tools/"/>
|
||||
<property name="thrift_compiler" value="${thrift.root}/compiler/cpp/thrift"/>
|
||||
|
||||
<!-- inherit from the java build file for version and other properties -->
|
||||
<property file="${thrift.java.dir}/build.properties" />
|
||||
|
||||
<property environment="env"/>
|
||||
|
||||
<condition property="version" value="${thrift.version}">
|
||||
<isset property="release"/>
|
||||
</condition>
|
||||
<property name="version" value="${thrift.version}-snapshot"/>
|
||||
|
||||
<property name="as3.final.name" value="${as3.artifactid}-${version}"/>
|
||||
|
||||
<property name="src" value="${basedir}/src"/>
|
||||
<property name="build.dir" value="${basedir}/build"/>
|
||||
|
||||
<property name="as3.swc.file" location="${build.dir}/${as3.final.name}.swc"/>
|
||||
<property name="as3.pom.xml" location="${build.dir}/${as3.final.name}.pom"/>
|
||||
|
||||
<target name="init" depends="setup.init,flex.init" unless="init.finished">
|
||||
<property name="init.finished" value="true"/>
|
||||
</target>
|
||||
|
||||
<target name="setup.init">
|
||||
<tstamp/>
|
||||
<mkdir dir="${build.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="flex.check" unless="FLEX_HOME">
|
||||
<fail message='You must set the FLEX_HOME property pointing to your flex SDK, eg. ant -DFLEX_HOME="/Applications/Adobe Flex Builder 3/sdks/3.2.0"'/>
|
||||
</target>
|
||||
|
||||
<target name="flex.init" depends="flex.check" unless="flex.finished">
|
||||
<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
|
||||
<property name="flex.finished" value="true"/>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="init">
|
||||
<path id="as.src.files">
|
||||
<fileset dir="${src}/">
|
||||
<include name="**/*.as"/>
|
||||
</fileset>
|
||||
</path>
|
||||
<pathconvert
|
||||
property="as.src.classes"
|
||||
pathsep=" "
|
||||
dirsep="."
|
||||
refid="as.src.files"
|
||||
>
|
||||
<map from="${src}/" to=""/>
|
||||
<mapper type="glob" from="*.as" to="*"/>
|
||||
</pathconvert>
|
||||
|
||||
<compc output="${as3.swc.file}" include-classes="${as.src.classes}">
|
||||
<source-path path-element="${src}"/>
|
||||
</compc>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="${build.dir}" />
|
||||
</target>
|
||||
|
||||
<target name="mvn.ant.tasks.download" depends="setup.init,mvn.ant.tasks.check" unless="mvn.ant.tasks.found">
|
||||
<get src="${mvn.ant.task.url}/${mvn.ant.task.jar}" dest="${build.tools.dir}/${mvn.ant.task.jar}" usetimestamp="true"/>
|
||||
</target>
|
||||
|
||||
<target name="mvn.ant.tasks.check">
|
||||
<condition property="mvn.ant.tasks.found">
|
||||
<typefound uri="antlib:org.apache.maven.artifact.ant" name="artifact"/>
|
||||
</condition>
|
||||
</target>
|
||||
|
||||
<target name="mvn.init" depends="mvn.ant.tasks.download" unless="mvn.finished">
|
||||
<echo message="${mvn.ant.task.jar}"/>
|
||||
<!-- Download mvn ant tasks, download dependencies, and setup pom file -->
|
||||
<typedef uri="antlib:org.apache.maven.artifact.ant" classpath="${build.tools.dir}/${mvn.ant.task.jar}"/>
|
||||
|
||||
<!-- remote repositories used to download dependencies from -->
|
||||
<artifact:remoteRepository id="central" url="${mvn.repo}"/>
|
||||
<artifact:remoteRepository id="apache" url="${apache.repo}"/>
|
||||
|
||||
<!-- Pom file information -->
|
||||
<artifact:pom id="pom"
|
||||
groupId="${thrift.groupid}"
|
||||
artifactId="${as3.artifactid}"
|
||||
version="${version}"
|
||||
url="http://thrift.apache.org"
|
||||
name="Apache Thrift"
|
||||
description="Thrift is a software framework for scalable cross-language services development."
|
||||
packaging="pom"
|
||||
>
|
||||
<remoteRepository refid="central"/>
|
||||
<remoteRepository refid="apache"/>
|
||||
<license name="The Apache Software License, Version 2.0" url="${license}"/>
|
||||
<scm connection="scm:git:https://git-wip-us.apache.org/repos/asf/thrift.git"
|
||||
developerConnection="scm:git:https://git-wip-us.apache.org/repos/asf/thrift.git"
|
||||
url="https://git-wip-us.apache.org/repos/asf?p=thrift.git"
|
||||
/>
|
||||
<!-- Thrift Developers -->
|
||||
<developer id="mcslee" name="Mark Slee"/>
|
||||
<developer id="dreiss" name="David Reiss"/>
|
||||
<developer id="aditya" name="Aditya Agarwal"/>
|
||||
<developer id="marck" name="Marc Kwiatkowski"/>
|
||||
<developer id="jwang" name="James Wang"/>
|
||||
<developer id="cpiro" name="Chris Piro"/>
|
||||
<developer id="bmaurer" name="Ben Maurer"/>
|
||||
<developer id="kclark" name="Kevin Clark"/>
|
||||
<developer id="jake" name="Jake Luciani"/>
|
||||
<developer id="bryanduxbury" name="Bryan Duxbury"/>
|
||||
<developer id="esteve" name="Esteve Fernandez"/>
|
||||
<developer id="todd" name="Todd Lipcon"/>
|
||||
<developer id="geechorama" name="Andrew McGeachie"/>
|
||||
<developer id="molinaro" name="Anthony Molinaro"/>
|
||||
<developer id="roger" name="Roger Meier"/>
|
||||
<developer id="jfarrell" name="Jake Farrell"/>
|
||||
<developer id="jensg" name="Jens Geyer"/>
|
||||
<developer id="carl" name="Carl Yeksigian"/>
|
||||
</artifact:pom>
|
||||
|
||||
<!-- Generate the pom file -->
|
||||
<artifact:writepom pomRefId="pom" file="${as3.pom.xml}"/>
|
||||
|
||||
<property name="mvn.finished" value="true"/>
|
||||
</target>
|
||||
|
||||
<macrodef name="signAndDeploy">
|
||||
<!-- Sign and deploy jars to apache repo -->
|
||||
<attribute name="file"/>
|
||||
<attribute name="classifier" default=""/>
|
||||
<attribute name="packaging" default="jar"/>
|
||||
<attribute name="pom" default=""/>
|
||||
<sequential>
|
||||
<artifact:mvn fork="true">
|
||||
<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.1:sign-and-deploy-file"/>
|
||||
<arg value="-DrepositoryId=${maven-repository-id}"/>
|
||||
<arg value="-Durl=${maven-repository-url}"/>
|
||||
<arg value="-DpomFile=@{pom}"/>
|
||||
<arg value="-Dfile=@{file}"/>
|
||||
<arg value="-Dclassifier=@{classifier}"/>
|
||||
<arg value="-Dpackaging=@{packaging}"/>
|
||||
<arg value="-Pgpg"/>
|
||||
</artifact:mvn>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<target name="publish" depends="clean,compile,mvn.init">
|
||||
<!-- Compile, packages and then send release to apache maven repo -->
|
||||
<!-- run with: ant -Drelease=true publish -->
|
||||
<signAndDeploy file="${as3.pom.xml}" packaging="pom" classifier="" pom="${as3.pom.xml}"/>
|
||||
<signAndDeploy file="${as3.swc.file}" packaging="swc" classifier="" pom="${as3.pom.xml}"/>
|
||||
</target>
|
||||
</project>
|
||||
1
vendor/github.com/apache/thrift/lib/as3/coding_standards.md
generated
vendored
Normal file
1
vendor/github.com/apache/thrift/lib/as3/coding_standards.md
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Please follow [General Coding Standards](/doc/coding_standards.md)
|
||||
31
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/AbstractMethodError.as
generated
vendored
Normal file
31
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/AbstractMethodError.as
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift {
|
||||
|
||||
import flash.errors.IllegalOperationError;
|
||||
|
||||
public class AbstractMethodError extends IllegalOperationError {
|
||||
|
||||
public function AbstractMethodError(message:String="") {
|
||||
super("Attempt to call an abstract method");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
82
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/Set.as
generated
vendored
Normal file
82
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/Set.as
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift {
|
||||
import flash.utils.Dictionary;
|
||||
|
||||
|
||||
public class Set {
|
||||
|
||||
private var _elements:Dictionary = new Dictionary();
|
||||
private var _size:int = 0;
|
||||
|
||||
public function Set(... values) {
|
||||
for each (var value:* in values) {
|
||||
add(value);
|
||||
}
|
||||
}
|
||||
|
||||
public function add(o:*):Boolean {
|
||||
var alreadyPresent:Boolean = _elements.hasOwnProperty(o);
|
||||
if (! alreadyPresent) {
|
||||
_size++;
|
||||
_elements[o] = true;
|
||||
}
|
||||
|
||||
return ! alreadyPresent;
|
||||
}
|
||||
|
||||
public function clear():void {
|
||||
for (var value:* in _elements) {
|
||||
remove(value);
|
||||
}
|
||||
}
|
||||
|
||||
public function contains(o:Object):Boolean {
|
||||
return _elements.hasOwnProperty(o);
|
||||
}
|
||||
|
||||
public function isEmpty():Boolean {
|
||||
return _size == 0;
|
||||
}
|
||||
|
||||
public function remove(o:*):Boolean {
|
||||
if (contains(o)) {
|
||||
delete _elements[o];
|
||||
_size--;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function toArray():Array {
|
||||
var ret:Array = new Array();
|
||||
for (var key:* in _elements) {
|
||||
ret.push(key);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public function get size():int {
|
||||
return _size;
|
||||
}
|
||||
}
|
||||
}
|
||||
106
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/TApplicationError.as
generated
vendored
Normal file
106
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/TApplicationError.as
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift {
|
||||
|
||||
import org.apache.thrift.protocol.TField;
|
||||
import org.apache.thrift.protocol.TProtocol;
|
||||
import org.apache.thrift.protocol.TProtocolUtil;
|
||||
import org.apache.thrift.protocol.TStruct;
|
||||
import org.apache.thrift.protocol.TType;
|
||||
|
||||
/**
|
||||
* Application level exception
|
||||
*/
|
||||
public class TApplicationError extends TError {
|
||||
|
||||
private static const TAPPLICATION_EXCEPTION_STRUCT:TStruct = new TStruct("TApplicationException");
|
||||
private static const MESSAGE_FIELD:TField = new TField("message", TType.STRING, 1);
|
||||
private static const TYPE_FIELD:TField = new TField("type", TType.I32, 2);
|
||||
|
||||
public static const UNKNOWN:int = 0;
|
||||
public static const UNKNOWN_METHOD:int = 1;
|
||||
public static const INVALID_MESSAGE_TYPE:int = 2;
|
||||
public static const WRONG_METHOD_NAME:int = 3;
|
||||
public static const BAD_SEQUENCE_ID:int = 4;
|
||||
public static const MISSING_RESULT:int = 5;
|
||||
public static const INTERNAL_ERROR:int = 6;
|
||||
public static const PROTOCOL_ERROR:int = 7;
|
||||
public static const INVALID_TRANSFORM:int = 8;
|
||||
public static const INVALID_PROTOCOL:int = 9;
|
||||
public static const UNSUPPORTED_CLIENT_TYPE:int = 10;
|
||||
|
||||
public function TApplicationError(type:int = UNKNOWN, message:String = "") {
|
||||
super(message, type);
|
||||
}
|
||||
|
||||
public static function read(iprot:TProtocol):TApplicationError {
|
||||
var field:TField;
|
||||
iprot.readStructBegin();
|
||||
|
||||
var message:String = null;
|
||||
var type:int = UNKNOWN;
|
||||
|
||||
while (true) {
|
||||
field = iprot.readFieldBegin();
|
||||
if (field.type == TType.STOP) {
|
||||
break;
|
||||
}
|
||||
switch (field.id) {
|
||||
case 1:
|
||||
if (field.type == TType.STRING) {
|
||||
message = iprot.readString();
|
||||
}
|
||||
else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (field.type == TType.I32) {
|
||||
type = iprot.readI32();
|
||||
}
|
||||
else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
break;
|
||||
}
|
||||
iprot.readFieldEnd();
|
||||
}
|
||||
iprot.readStructEnd();
|
||||
return new TApplicationError(type, message);
|
||||
}
|
||||
|
||||
public function write(oprot:TProtocol):void {
|
||||
oprot.writeStructBegin(TAPPLICATION_EXCEPTION_STRUCT);
|
||||
if (message != null) {
|
||||
oprot.writeFieldBegin(MESSAGE_FIELD);
|
||||
oprot.writeString(message);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
oprot.writeFieldBegin(TYPE_FIELD);
|
||||
oprot.writeI32(errorID);
|
||||
oprot.writeFieldEnd();
|
||||
oprot.writeFieldStop();
|
||||
oprot.writeStructEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
67
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/TBase.as
generated
vendored
Normal file
67
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/TBase.as
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift {
|
||||
|
||||
import org.apache.thrift.protocol.TProtocol;
|
||||
|
||||
/**
|
||||
* Generic base interface for generated Thrift objects.
|
||||
*
|
||||
*/
|
||||
public interface TBase {
|
||||
|
||||
/**
|
||||
* Reads the TObject from the given input protocol.
|
||||
*
|
||||
* @param iprot Input protocol
|
||||
*/
|
||||
function read(iprot:TProtocol):void;
|
||||
|
||||
/**
|
||||
* Writes the objects out to the protocol
|
||||
*
|
||||
* @param oprot Output protocol
|
||||
*/
|
||||
function write(oprot:TProtocol):void;
|
||||
|
||||
/**
|
||||
* Check if a field is currently set or unset.
|
||||
*
|
||||
* @param fieldId The field's id tag as found in the IDL.
|
||||
*/
|
||||
function isSet(fieldId:int):Boolean;
|
||||
|
||||
/**
|
||||
* Get a field's value by id. Primitive types will be wrapped in the
|
||||
* appropriate "boxed" types.
|
||||
*
|
||||
* @param fieldId The field's id tag as found in the IDL.
|
||||
*/
|
||||
function getFieldValue(fieldId:int):*;
|
||||
|
||||
/**
|
||||
* Set a field's value by id. Primitive types must be "boxed" in the
|
||||
* appropriate object wrapper type.
|
||||
*
|
||||
* @param fieldId The field's id tag as found in the IDL.
|
||||
*/
|
||||
function setFieldValue(fieldId:int, value:*):void;
|
||||
}
|
||||
}
|
||||
29
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/TError.as
generated
vendored
Normal file
29
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/TError.as
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift {
|
||||
|
||||
public class TError extends Error {
|
||||
|
||||
public function TError(message:String = "", errorCode:int = 0) {
|
||||
super(message, errorCode);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
32
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/TFieldRequirementType.as
generated
vendored
Normal file
32
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/TFieldRequirementType.as
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift {
|
||||
|
||||
/**
|
||||
* Requirement type constants.
|
||||
*
|
||||
*/
|
||||
public class TFieldRequirementType {
|
||||
public static const REQUIRED:int = 1;
|
||||
public static const OPTIONAL:int = 2;
|
||||
public static const DEFAULT:int = 3;
|
||||
}
|
||||
|
||||
}
|
||||
32
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/TProcessor.as
generated
vendored
Normal file
32
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/TProcessor.as
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift {
|
||||
|
||||
import org.apache.thrift.protocol.TProtocol;
|
||||
|
||||
/**
|
||||
* A processor is a generic object which operates upon an input stream and
|
||||
* writes to some output stream.
|
||||
*
|
||||
*/
|
||||
public interface TProcessor {
|
||||
function process(input:TProtocol, output:TProtocol):Boolean;
|
||||
}
|
||||
}
|
||||
57
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/meta_data/FieldMetaData.as
generated
vendored
Normal file
57
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/meta_data/FieldMetaData.as
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.meta_data {
|
||||
|
||||
import flash.utils.Dictionary;
|
||||
|
||||
/**
|
||||
* This class is used to store meta data about thrift fields. Every field in a
|
||||
* a struct should have a corresponding instance of this class describing it.
|
||||
*
|
||||
*/
|
||||
public class FieldMetaData {
|
||||
|
||||
public var fieldName:String;
|
||||
public var requirementType:int;
|
||||
public var valueMetaData:FieldValueMetaData;
|
||||
|
||||
private static var structMap:Dictionary = new Dictionary();
|
||||
|
||||
public function FieldMetaData(name:String, req:int, vMetaData:FieldValueMetaData) {
|
||||
this.fieldName = name;
|
||||
this.requirementType = req;
|
||||
this.valueMetaData = vMetaData;
|
||||
}
|
||||
|
||||
public static function addStructMetaDataMap(sClass:Class, map:Dictionary):void{
|
||||
structMap[sClass] = map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map with metadata (i.e. instances of FieldMetaData) that
|
||||
* describe the fields of the given class.
|
||||
*
|
||||
* @param sClass The TBase class for which the metadata map is requested
|
||||
*/
|
||||
public static function getStructMetaDataMap(sClass:Class):Dictionary {
|
||||
return structMap[sClass];
|
||||
}
|
||||
}
|
||||
}
|
||||
44
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/meta_data/FieldValueMetaData.as
generated
vendored
Normal file
44
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/meta_data/FieldValueMetaData.as
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.meta_data {
|
||||
|
||||
import org.apache.thrift.protocol.TType;
|
||||
|
||||
/**
|
||||
* FieldValueMetaData and collection of subclasses to store metadata about
|
||||
* the value(s) of a field
|
||||
*/
|
||||
public class FieldValueMetaData {
|
||||
|
||||
public var type:int;
|
||||
|
||||
public function FieldValueMetaData(type:int) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public function isStruct():Boolean {
|
||||
return type == TType.STRUCT;
|
||||
}
|
||||
|
||||
public function isContainer():Boolean {
|
||||
return type == TType.LIST || type == TType.MAP || type == TType.SET;
|
||||
}
|
||||
}
|
||||
}
|
||||
31
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/meta_data/ListMetaData.as
generated
vendored
Normal file
31
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/meta_data/ListMetaData.as
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.meta_data {
|
||||
|
||||
public class ListMetaData extends FieldValueMetaData {
|
||||
|
||||
public var elemMetaData:FieldValueMetaData;
|
||||
|
||||
public function ListMetaData(type:int, eMetaData:FieldValueMetaData) {
|
||||
super(type);
|
||||
this.elemMetaData = eMetaData;
|
||||
}
|
||||
}
|
||||
}
|
||||
33
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/meta_data/MapMetaData.as
generated
vendored
Normal file
33
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/meta_data/MapMetaData.as
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.meta_data {
|
||||
|
||||
public class MapMetaData extends FieldValueMetaData {
|
||||
|
||||
public var keyMetaData:FieldValueMetaData;
|
||||
public var valueMetaData:FieldValueMetaData;
|
||||
|
||||
public function MapMetaData(type:int, kMetaData:FieldValueMetaData, vMetaData:FieldValueMetaData) {
|
||||
super(type);
|
||||
this.keyMetaData = kMetaData;
|
||||
this.valueMetaData = vMetaData;
|
||||
}
|
||||
}
|
||||
}
|
||||
31
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/meta_data/SetMetaData.as
generated
vendored
Normal file
31
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/meta_data/SetMetaData.as
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.meta_data {
|
||||
|
||||
public class SetMetaData extends FieldValueMetaData {
|
||||
|
||||
public var elemMetaData:FieldValueMetaData;
|
||||
|
||||
public function SetMetaData(type:int, eMetaData:FieldValueMetaData) {
|
||||
super(type);
|
||||
this.elemMetaData = eMetaData;
|
||||
}
|
||||
}
|
||||
}
|
||||
31
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/meta_data/StructMetaData.as
generated
vendored
Normal file
31
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/meta_data/StructMetaData.as
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.meta_data {
|
||||
|
||||
public class StructMetaData extends FieldValueMetaData {
|
||||
|
||||
public var structClass:Class;
|
||||
|
||||
public function StructMetaData(type:int, sClass:Class) {
|
||||
super(type);
|
||||
this.structClass = sClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
316
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TBinaryProtocol.as
generated
vendored
Normal file
316
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TBinaryProtocol.as
generated
vendored
Normal file
@@ -0,0 +1,316 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.protocol {
|
||||
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
import org.apache.thrift.TError;
|
||||
import org.apache.thrift.transport.THttpClient;
|
||||
import org.apache.thrift.transport.TTransport;
|
||||
|
||||
/**
|
||||
* Binary protocol implementation for thrift.
|
||||
*/
|
||||
public class TBinaryProtocol implements TProtocol {
|
||||
|
||||
private static var ANONYMOUS_STRUCT:TStruct = new TStruct();
|
||||
|
||||
protected static const VERSION_MASK:int = int(0xffff0000);
|
||||
protected static const VERSION_1:int = int(0x80010000);
|
||||
|
||||
protected var strictRead_:Boolean = false;
|
||||
protected var strictWrite_:Boolean = true;
|
||||
|
||||
/**
|
||||
* Factory
|
||||
*/
|
||||
/*
|
||||
public static class Factory implements TProtocolFactory {
|
||||
protected boolean strictRead_ = false;
|
||||
protected boolean strictWrite_ = true;
|
||||
|
||||
public Factory() {
|
||||
this(false, true);
|
||||
}
|
||||
|
||||
public Factory(boolean strictRead, boolean strictWrite) {
|
||||
strictRead_ = strictRead;
|
||||
strictWrite_ = strictWrite;
|
||||
}
|
||||
|
||||
public TProtocol getProtocol(TTransport trans) {
|
||||
return new TBinaryProtocol(trans, strictRead_, strictWrite_);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private var trans_:TTransport;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function TBinaryProtocol(trans:TTransport, strictRead:Boolean=false, strictWrite:Boolean=true) {
|
||||
trans_ = trans;
|
||||
strictRead_ = strictRead;
|
||||
strictWrite_ = strictWrite;
|
||||
}
|
||||
|
||||
public function getTransport():TTransport {
|
||||
return trans_;
|
||||
}
|
||||
|
||||
public function writeMessageBegin(message:TMessage):void {
|
||||
if (strictWrite_) {
|
||||
var version:int = VERSION_1 | message.type;
|
||||
writeI32(version);
|
||||
writeString(message.name);
|
||||
writeI32(message.seqid);
|
||||
} else {
|
||||
writeString(message.name);
|
||||
writeByte(message.type);
|
||||
writeI32(message.seqid);
|
||||
}
|
||||
}
|
||||
|
||||
public function writeMessageEnd():void {}
|
||||
|
||||
public function writeStructBegin(struct:TStruct):void {}
|
||||
|
||||
public function writeStructEnd():void {}
|
||||
|
||||
public function writeFieldBegin(field:TField):void {
|
||||
writeByte(field.type);
|
||||
writeI16(field.id);
|
||||
}
|
||||
|
||||
public function writeFieldEnd():void {}
|
||||
|
||||
public function writeFieldStop():void {
|
||||
writeByte(TType.STOP);
|
||||
}
|
||||
|
||||
public function writeMapBegin(map:TMap):void {
|
||||
writeByte(map.keyType);
|
||||
writeByte(map.valueType);
|
||||
writeI32(map.size);
|
||||
}
|
||||
|
||||
public function writeMapEnd():void {}
|
||||
|
||||
public function writeListBegin(list:TList):void {
|
||||
writeByte(list.elemType);
|
||||
writeI32(list.size);
|
||||
}
|
||||
|
||||
public function writeListEnd():void {}
|
||||
|
||||
public function writeSetBegin(set:TSet):void {
|
||||
writeByte(set.elemType);
|
||||
writeI32(set.size);
|
||||
}
|
||||
|
||||
public function writeSetEnd():void {}
|
||||
|
||||
public function writeBool(b:Boolean):void {
|
||||
writeByte(b ? 1 : 0);
|
||||
}
|
||||
|
||||
private var out:ByteArray = new ByteArray();
|
||||
public function writeByte(b:int):void {
|
||||
reset(out);
|
||||
out.writeByte(b);
|
||||
trans_.write(out, 0, 1);
|
||||
}
|
||||
|
||||
public function writeI16(i16:int):void {
|
||||
reset(out);
|
||||
out.writeShort(i16);
|
||||
trans_.write(out, 0, 2);
|
||||
}
|
||||
|
||||
public function writeI32(i32:int):void {
|
||||
reset(out);
|
||||
out.writeInt(i32);
|
||||
trans_.write(out, 0, 4);
|
||||
}
|
||||
|
||||
//private byte[] i64out = new byte[8];
|
||||
//public function writeI64(i64:Number):void {
|
||||
//i64out[0] = (byte)(0xff & (i64 >> 56));
|
||||
//i64out[1] = (byte)(0xff & (i64 >> 48));
|
||||
//i64out[2] = (byte)(0xff & (i64 >> 40));
|
||||
//i64out[3] = (byte)(0xff & (i64 >> 32));
|
||||
//i64out[4] = (byte)(0xff & (i64 >> 24));
|
||||
//i64out[5] = (byte)(0xff & (i64 >> 16));
|
||||
//i64out[6] = (byte)(0xff & (i64 >> 8));
|
||||
//i64out[7] = (byte)(0xff & (i64));
|
||||
//trans_.write(i64out, 0, 8);
|
||||
//}
|
||||
|
||||
public function writeDouble(dub:Number):void {
|
||||
reset(out);
|
||||
out.writeDouble(dub);
|
||||
trans_.write(out, 0, 8);
|
||||
}
|
||||
|
||||
private var stringOut:ByteArray = new ByteArray();
|
||||
|
||||
public function writeString(str:String):void {
|
||||
reset(stringOut);
|
||||
stringOut.writeUTFBytes(str);
|
||||
|
||||
writeI32(stringOut.length);
|
||||
trans_.write(stringOut, 0, stringOut.length);
|
||||
}
|
||||
|
||||
public function writeBinary(bin:ByteArray):void {
|
||||
writeI32(bin.length);
|
||||
trans_.write(bin, 0, bin.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reading methods.
|
||||
*/
|
||||
|
||||
public function readMessageBegin():TMessage {
|
||||
var size:int = readI32();
|
||||
if (size < 0) {
|
||||
var version:int = size & VERSION_MASK;
|
||||
if (version != VERSION_1) {
|
||||
throw new TProtocolError(TProtocolError.BAD_VERSION, "Bad version in readMessageBegin");
|
||||
}
|
||||
return new TMessage(readString(), size & 0x000000ff, readI32());
|
||||
}
|
||||
else {
|
||||
if (strictRead_) {
|
||||
throw new TProtocolError(TProtocolError.BAD_VERSION, "Missing version in readMessageBegin, old client?");
|
||||
}
|
||||
return new TMessage(readStringBody(size), readByte(), readI32());
|
||||
}
|
||||
}
|
||||
|
||||
public function readMessageEnd():void {}
|
||||
|
||||
public function readStructBegin():TStruct {
|
||||
return ANONYMOUS_STRUCT;
|
||||
}
|
||||
|
||||
public function readStructEnd():void {}
|
||||
|
||||
public function readFieldBegin():TField {
|
||||
var type:int = readByte();
|
||||
var id:int = type == TType.STOP ? 0 : readI16();
|
||||
return new TField("", type, id);
|
||||
}
|
||||
|
||||
public function readFieldEnd():void {}
|
||||
|
||||
public function readMapBegin():TMap {
|
||||
return new TMap(readByte(), readByte(), readI32());
|
||||
}
|
||||
|
||||
public function readMapEnd():void {}
|
||||
|
||||
public function readListBegin():TList {
|
||||
return new TList(readByte(), readI32());
|
||||
}
|
||||
|
||||
public function readListEnd():void {}
|
||||
|
||||
public function readSetBegin():TSet {
|
||||
return new TSet(readByte(), readI32());
|
||||
}
|
||||
|
||||
public function readSetEnd():void {}
|
||||
|
||||
public function readBool():Boolean {
|
||||
return (readByte() == 1);
|
||||
}
|
||||
|
||||
private var bytes:ByteArray = new ByteArray();
|
||||
|
||||
public function readByte():int {
|
||||
readAll(1);
|
||||
return bytes.readByte();
|
||||
}
|
||||
|
||||
public function readI16():int {
|
||||
readAll(2);
|
||||
return bytes.readShort();
|
||||
}
|
||||
|
||||
public function readI32():int {
|
||||
readAll(4);
|
||||
return bytes.readInt();
|
||||
}
|
||||
|
||||
//private byte[] i64rd = new byte[8];
|
||||
/*
|
||||
public function readI64() throws TException {
|
||||
readAll(i64rd, 0, 8);
|
||||
return
|
||||
((long)(i64rd[0] & 0xff) << 56) |
|
||||
((long)(i64rd[1] & 0xff) << 48) |
|
||||
((long)(i64rd[2] & 0xff) << 40) |
|
||||
((long)(i64rd[3] & 0xff) << 32) |
|
||||
((long)(i64rd[4] & 0xff) << 24) |
|
||||
((long)(i64rd[5] & 0xff) << 16) |
|
||||
((long)(i64rd[6] & 0xff) << 8) |
|
||||
((long)(i64rd[7] & 0xff));
|
||||
}
|
||||
*/
|
||||
|
||||
public function readDouble():Number {
|
||||
readAll(8);
|
||||
return bytes.readDouble();
|
||||
}
|
||||
|
||||
public function readString():String {
|
||||
var size:int = readI32();
|
||||
readAll(size);
|
||||
return bytes.readUTFBytes(size);
|
||||
}
|
||||
|
||||
public function readStringBody(size:int):String {
|
||||
readAll(size);
|
||||
return bytes.readUTFBytes(size);
|
||||
}
|
||||
|
||||
public function readBinary():ByteArray {
|
||||
var size:int = readI32();
|
||||
var buf:ByteArray = new ByteArray();
|
||||
trans_.readAll(buf, 0, size);
|
||||
return buf;
|
||||
}
|
||||
|
||||
private function readAll(len:int):void {
|
||||
reset(bytes);
|
||||
|
||||
trans_.readAll(bytes, 0, len);
|
||||
|
||||
bytes.position = 0;
|
||||
}
|
||||
|
||||
private static function reset(arr:ByteArray):void {
|
||||
arr.length = 0;
|
||||
arr.position = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
43
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TField.as
generated
vendored
Normal file
43
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TField.as
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.protocol {
|
||||
|
||||
public class TField {
|
||||
|
||||
public var name:String;
|
||||
public var type:int;
|
||||
public var id:int;
|
||||
|
||||
public function TField(n:String = "", t:int = 0, i:int = 0) {
|
||||
name = n;
|
||||
type = t;
|
||||
id = i;
|
||||
}
|
||||
|
||||
public function toString():String {
|
||||
return "<TField name:'" + name + "' type:" + type + " field-id:" + id + ">";
|
||||
}
|
||||
|
||||
public function equals(otherField:TField):Boolean {
|
||||
return type == otherField.type && id == otherField.id;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
33
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TList.as
generated
vendored
Normal file
33
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TList.as
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.protocol {
|
||||
|
||||
public class TList {
|
||||
|
||||
public var elemType:int;
|
||||
public var size:int;
|
||||
|
||||
public function TList(t:int = 0, s:int = 0) {
|
||||
elemType = t;
|
||||
size = s;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
33
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TMap.as
generated
vendored
Normal file
33
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TMap.as
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.protocol {
|
||||
public class TMap {
|
||||
|
||||
public var keyType:int;
|
||||
public var valueType:int;
|
||||
public var size:int;
|
||||
|
||||
public function TMap(k:int = 0, v:int = 0, s:int = 0) {
|
||||
keyType = k;
|
||||
valueType = v;
|
||||
size = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
42
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TMessage.as
generated
vendored
Normal file
42
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TMessage.as
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.protocol {
|
||||
|
||||
public class TMessage {
|
||||
|
||||
public var name:String;
|
||||
public var type:int;
|
||||
public var seqid:int;
|
||||
|
||||
public function TMessage(n:String = "", t:int = 0, s:int = 0) {
|
||||
name = n;
|
||||
type = t;
|
||||
seqid = s;
|
||||
}
|
||||
|
||||
public function toString():String {
|
||||
return "<TMessage name:'" + name + "' type: " + type + " seqid:" + seqid + ">";
|
||||
}
|
||||
|
||||
public function equals(other:TMessage):Boolean {
|
||||
return name == other.name && type == other.type && seqid == other.seqid;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TMessageType.as
generated
vendored
Normal file
28
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TMessageType.as
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.protocol {
|
||||
|
||||
public class TMessageType {
|
||||
public static const CALL:int = 1;
|
||||
public static const REPLY:int = 2;
|
||||
public static const EXCEPTION:int = 3;
|
||||
public static const ONEWAY:int = 4;
|
||||
}
|
||||
}
|
||||
124
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TProtocol.as
generated
vendored
Normal file
124
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TProtocol.as
generated
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.protocol {
|
||||
|
||||
import org.apache.thrift.TError;
|
||||
import org.apache.thrift.transport.TTransport;
|
||||
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
/**
|
||||
* Protocol interface definition
|
||||
*/
|
||||
public interface TProtocol {
|
||||
|
||||
function TProtocol(trans:TTransport);
|
||||
|
||||
function getTransport():TTransport;
|
||||
|
||||
/**
|
||||
* Writing methods.
|
||||
*/
|
||||
function writeMessageBegin(message:TMessage):void;
|
||||
|
||||
function writeMessageEnd():void;
|
||||
|
||||
function writeStructBegin(struct:TStruct):void;
|
||||
|
||||
function writeStructEnd():void;
|
||||
|
||||
function writeFieldBegin(field:TField):void;
|
||||
|
||||
function writeFieldEnd():void;
|
||||
|
||||
function writeFieldStop():void;
|
||||
|
||||
function writeMapBegin(map:TMap):void;
|
||||
|
||||
function writeMapEnd():void;
|
||||
|
||||
function writeListBegin(list:TList):void;
|
||||
|
||||
function writeListEnd():void;
|
||||
|
||||
function writeSetBegin(set:TSet):void;
|
||||
|
||||
function writeSetEnd():void;
|
||||
|
||||
function writeBool(b:Boolean):void;
|
||||
|
||||
function writeByte(b:int):void;
|
||||
|
||||
function writeI16(i16:int):void;
|
||||
|
||||
function writeI32(i32:int):void;
|
||||
|
||||
//function writeI64(i64:Number):void;
|
||||
|
||||
function writeDouble(dub:Number):void;
|
||||
|
||||
function writeString(str:String):void;
|
||||
|
||||
function writeBinary(bin:ByteArray):void;
|
||||
|
||||
/**
|
||||
* Reading methods.
|
||||
*/
|
||||
function readMessageBegin():TMessage;
|
||||
|
||||
function readMessageEnd():void;
|
||||
|
||||
function readStructBegin():TStruct;
|
||||
|
||||
function readStructEnd():void;
|
||||
|
||||
function readFieldBegin():TField;
|
||||
|
||||
function readFieldEnd():void;
|
||||
|
||||
function readMapBegin():TMap;
|
||||
|
||||
function readMapEnd():void;
|
||||
|
||||
function readListBegin():TList;
|
||||
|
||||
function readListEnd():void;
|
||||
|
||||
function readSetBegin():TSet;
|
||||
|
||||
function readSetEnd():void;
|
||||
|
||||
function readBool():Boolean;
|
||||
|
||||
function readByte():int;
|
||||
|
||||
function readI16():int;
|
||||
|
||||
function readI32():int;
|
||||
|
||||
//function readI64():Number;
|
||||
|
||||
function readDouble():Number;
|
||||
|
||||
function readString():String;
|
||||
|
||||
function readBinary():ByteArray;
|
||||
}
|
||||
}
|
||||
39
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TProtocolError.as
generated
vendored
Normal file
39
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TProtocolError.as
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.protocol {
|
||||
|
||||
import org.apache.thrift.TError;
|
||||
|
||||
public class TProtocolError extends TError {
|
||||
|
||||
public static const UNKNOWN:int = 0;
|
||||
public static const INVALID_DATA:int = 1;
|
||||
public static const NEGATIVE_SIZE:int = 2;
|
||||
public static const SIZE_LIMIT:int = 3;
|
||||
public static const BAD_VERSION:int = 4;
|
||||
public static const NOT_IMPLEMENTED:int = 5;
|
||||
public static const DEPTH_LIMIT:int = 6;
|
||||
|
||||
public function TProtocolError(error:int = UNKNOWN, message:String = "") {
|
||||
super(message, error);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
27
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TProtocolFactory.as
generated
vendored
Normal file
27
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TProtocolFactory.as
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.protocol {
|
||||
|
||||
import org.apache.thrift.transport.TTransport;
|
||||
|
||||
public interface TProtocolFactory {
|
||||
function getProtocol(trans:TTransport):TProtocol;
|
||||
}
|
||||
}
|
||||
148
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TProtocolUtil.as
generated
vendored
Normal file
148
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TProtocolUtil.as
generated
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.protocol {
|
||||
|
||||
import org.apache.thrift.TError;
|
||||
|
||||
/**
|
||||
* Utility class with static methods for interacting with protocol data
|
||||
* streams.
|
||||
*
|
||||
*/
|
||||
public class TProtocolUtil {
|
||||
|
||||
/**
|
||||
* The maximum recursive depth the skip() function will traverse before
|
||||
* throwing a TException.
|
||||
*/
|
||||
private static var maxSkipDepth:int = int.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* Specifies the maximum recursive depth that the skip function will
|
||||
* traverse before throwing a TException. This is a global setting, so
|
||||
* any call to skip in this JVM will enforce this value.
|
||||
*
|
||||
* @param depth the maximum recursive depth. A value of 2 would allow
|
||||
* the skip function to skip a structure or collection with basic children,
|
||||
* but it would not permit skipping a struct that had a field containing
|
||||
* a child struct. A value of 1 would only allow skipping of simple
|
||||
* types and empty structs/collections.
|
||||
*/
|
||||
public function setMaxSkipDepth(depth:int):void {
|
||||
maxSkipDepth = depth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips over the next data element from the provided input TProtocol object.
|
||||
*
|
||||
* @param prot the protocol object to read from
|
||||
* @param type the next value will be intepreted as this TType value.
|
||||
*/
|
||||
public static function skip(prot:TProtocol, type:int):void {
|
||||
skipMaxDepth(prot, type, maxSkipDepth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips over the next data element from the provided input TProtocol object.
|
||||
*
|
||||
* @param prot the protocol object to read from
|
||||
* @param type the next value will be intepreted as this TType value.
|
||||
* @param maxDepth this function will only skip complex objects to this
|
||||
* recursive depth, to prevent Java stack overflow.
|
||||
*/
|
||||
public static function skipMaxDepth(prot:TProtocol, type:int, maxDepth:int):void {
|
||||
if (maxDepth <= 0) {
|
||||
throw new TError("Maximum skip depth exceeded");
|
||||
}
|
||||
switch (type) {
|
||||
case TType.BOOL: {
|
||||
prot.readBool();
|
||||
break;
|
||||
}
|
||||
case TType.BYTE: {
|
||||
prot.readByte();
|
||||
break;
|
||||
}
|
||||
case TType.I16: {
|
||||
prot.readI16();
|
||||
break;
|
||||
}
|
||||
case TType.I32: {
|
||||
prot.readI32();
|
||||
break;
|
||||
}
|
||||
/*
|
||||
case TType.I64: {
|
||||
prot.readI64();
|
||||
break;
|
||||
}
|
||||
*/
|
||||
case TType.DOUBLE: {
|
||||
prot.readDouble();
|
||||
break;
|
||||
}
|
||||
case TType.STRING: {
|
||||
prot.readBinary();
|
||||
break;
|
||||
}
|
||||
case TType.STRUCT: {
|
||||
prot.readStructBegin();
|
||||
while (true) {
|
||||
var field:TField = prot.readFieldBegin();
|
||||
if (field.type == TType.STOP) {
|
||||
break;
|
||||
}
|
||||
skipMaxDepth(prot, field.type, maxDepth - 1);
|
||||
prot.readFieldEnd();
|
||||
}
|
||||
prot.readStructEnd();
|
||||
break;
|
||||
}
|
||||
case TType.MAP: {
|
||||
var map:TMap = prot.readMapBegin();
|
||||
for (var i:int = 0; i < map.size; i++) {
|
||||
skipMaxDepth(prot, map.keyType, maxDepth - 1);
|
||||
skipMaxDepth(prot, map.valueType, maxDepth - 1);
|
||||
}
|
||||
prot.readMapEnd();
|
||||
break;
|
||||
}
|
||||
case TType.SET: {
|
||||
var set:TSet = prot.readSetBegin();
|
||||
for (var j:int = 0; j < set.size; j++) {
|
||||
skipMaxDepth(prot, set.elemType, maxDepth - 1);
|
||||
}
|
||||
prot.readSetEnd();
|
||||
break;
|
||||
}
|
||||
case TType.LIST: {
|
||||
var list:TList = prot.readListBegin();
|
||||
for (var k:int = 0; k < list.size; k++) {
|
||||
skipMaxDepth(prot, list.elemType, maxDepth - 1);
|
||||
}
|
||||
prot.readListEnd();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TSet.as
generated
vendored
Normal file
33
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TSet.as
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.protocol {
|
||||
|
||||
public class TSet {
|
||||
|
||||
public var elemType:int;
|
||||
public var size:int;
|
||||
|
||||
public function TSet(t:int = 0, s:int = 0) {
|
||||
elemType = t;
|
||||
size = s;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
31
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TStruct.as
generated
vendored
Normal file
31
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TStruct.as
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.protocol {
|
||||
|
||||
public class TStruct {
|
||||
|
||||
public var name:String;
|
||||
|
||||
public function TStruct(n:String = "") {
|
||||
name = n;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
39
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TType.as
generated
vendored
Normal file
39
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/protocol/TType.as
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.protocol {
|
||||
|
||||
public class TType {
|
||||
|
||||
public static const STOP:int = 0;
|
||||
public static const VOID:int = 1;
|
||||
public static const BOOL:int = 2;
|
||||
public static const BYTE:int = 3;
|
||||
public static const DOUBLE:int = 4;
|
||||
public static const I16:int = 6;
|
||||
public static const I32:int = 8;
|
||||
public static const I64:int = 10;
|
||||
public static const STRING:int = 11;
|
||||
public static const STRUCT:int = 12;
|
||||
public static const MAP:int = 13;
|
||||
public static const SET:int = 14;
|
||||
public static const LIST:int = 15;
|
||||
|
||||
}
|
||||
}
|
||||
251
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/transport/TFullDuplexHttpClient.as
generated
vendored
Normal file
251
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/transport/TFullDuplexHttpClient.as
generated
vendored
Normal file
@@ -0,0 +1,251 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.transport
|
||||
{
|
||||
|
||||
import flash.errors.EOFError;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLLoaderDataFormat;
|
||||
import flash.net.URLRequest;
|
||||
import flash.net.URLRequestMethod;
|
||||
import flash.utils.IDataInput;
|
||||
import flash.utils.IDataOutput;
|
||||
import flash.utils.ByteArray;
|
||||
import flash.net.Socket;
|
||||
import flash.events.EventDispatcher;
|
||||
|
||||
|
||||
/**
|
||||
* HTTP implementation of the TTransport interface. Used for working with a
|
||||
* Thrift web services implementation.
|
||||
* Unlike Http Client, it uses a single POST, and chunk-encoding to transfer all messages.
|
||||
*/
|
||||
|
||||
public class TFullDuplexHttpClient extends TTransport
|
||||
{
|
||||
private var socket:Socket = null;
|
||||
|
||||
private var host:String;
|
||||
|
||||
private var port:int;
|
||||
|
||||
private var resource:String;
|
||||
|
||||
private var stripped:Boolean = false;
|
||||
|
||||
private var obuffer:ByteArray = new ByteArray();
|
||||
|
||||
private var input:IDataInput;
|
||||
|
||||
private var output:IDataOutput;
|
||||
|
||||
private var bytesInChunk:int = 0;
|
||||
|
||||
private var CRLF:ByteArray = new ByteArray();
|
||||
|
||||
private var ioCallback:Function = null;
|
||||
|
||||
private var eventDispatcher:EventDispatcher = new EventDispatcher();
|
||||
|
||||
public function TFullDuplexHttpClient(host:String, port:int, resource:String):void
|
||||
{
|
||||
CRLF.writeByte(13);
|
||||
CRLF.writeByte(10);
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
public override function close():void
|
||||
{
|
||||
this.input = null;
|
||||
this.output = null;
|
||||
this.stripped = false;
|
||||
socket.close()
|
||||
}
|
||||
|
||||
public override function peek():Boolean
|
||||
{
|
||||
if(socket.connected)
|
||||
{
|
||||
trace("Bytes remained:" + socket.bytesAvailable);
|
||||
return socket.bytesAvailable>0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override function read(buf:ByteArray, off:int, len:int):int
|
||||
{
|
||||
var n1:int = 0, n2:int = 0, n3:int = 0, n4:int = 0, cidx:int = 2;
|
||||
var chunkSize:ByteArray = new ByteArray();
|
||||
|
||||
try
|
||||
{
|
||||
while (!stripped)
|
||||
{
|
||||
n1 = n2;
|
||||
n2 = n3;
|
||||
n3 = n4;
|
||||
n4 = input.readByte();
|
||||
if ((n1 == 13) && (n2 == 10) && (n3 == 13) && (n4 == 10))
|
||||
{
|
||||
stripped = true;
|
||||
}
|
||||
}
|
||||
|
||||
// read chunk size
|
||||
if (bytesInChunk == 0)
|
||||
{
|
||||
n1 = input.readByte();
|
||||
n2 = input.readByte();
|
||||
|
||||
chunkSize.writeByte(n1);
|
||||
chunkSize.writeByte(n2);
|
||||
|
||||
while (!((n1 == 13) && (n2 == 10)))
|
||||
{
|
||||
n1 = n2;
|
||||
n2 = input.readByte();
|
||||
chunkSize.writeByte(n2);
|
||||
}
|
||||
|
||||
bytesInChunk = parseInt(chunkSize.toString(), 16);
|
||||
}
|
||||
|
||||
input.readBytes(buf, off, len);
|
||||
debugBuffer(buf);
|
||||
bytesInChunk -= len;
|
||||
|
||||
if (bytesInChunk == 0)
|
||||
{
|
||||
// advance the : "\r\n"
|
||||
input.readUTFBytes(2);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
catch (e:EOFError)
|
||||
{
|
||||
trace(e);
|
||||
throw new TTransportError(TTransportError.UNKNOWN, "No more data available.");
|
||||
}
|
||||
catch (e:Error)
|
||||
{
|
||||
trace(e);
|
||||
// WTF??
|
||||
throw new TTransportError(TTransportError.UNKNOWN, "Bad IO error:" + e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function debugBuffer(buf:ByteArray):void
|
||||
{
|
||||
var debug:String = "BUFFER >>";
|
||||
var i:int;
|
||||
for (i = 0; i < buf.length; i++)
|
||||
{
|
||||
debug += buf[i] as int;
|
||||
debug += " ";
|
||||
}
|
||||
|
||||
trace(debug + "<<");
|
||||
}
|
||||
|
||||
public override function write(buf:ByteArray, off:int, len:int):void
|
||||
{
|
||||
obuffer.writeBytes(buf, off, len);
|
||||
}
|
||||
|
||||
public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
|
||||
{
|
||||
this.eventDispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
|
||||
}
|
||||
|
||||
public override function open():void
|
||||
{
|
||||
this.socket = new Socket();
|
||||
this.socket.addEventListener(Event.CONNECT, socketConnected);
|
||||
this.socket.addEventListener(IOErrorEvent.IO_ERROR, socketError);
|
||||
this.socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, socketSecurityError);
|
||||
this.socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
|
||||
this.socket.connect(host, port);
|
||||
}
|
||||
|
||||
public function socketConnected(event:Event):void
|
||||
{
|
||||
this.output = this.socket;
|
||||
this.input = this.socket;
|
||||
this.output.writeUTF("CONNECT " + resource + " HTTP/1.1\n" + "Host: " + host + ":" + port + "\r\n" + "User-Agent: Thrift/AS3\r\n" + "Transfer-Encoding: chunked\r\n" + "content-type: application/x-thrift\r\n" + "Accept: */*\r\n\r\n");
|
||||
this.eventDispatcher.dispatchEvent(event);
|
||||
}
|
||||
|
||||
public function socketError(event:IOErrorEvent):void
|
||||
{
|
||||
trace("Error Connecting:" + event);
|
||||
this.close();
|
||||
if (ioCallback == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ioCallback(new TTransportError(TTransportError.UNKNOWN, "IOError: " + event.text));
|
||||
this.eventDispatcher.dispatchEvent(event);
|
||||
}
|
||||
|
||||
public function socketSecurityError(event:SecurityErrorEvent):void
|
||||
{
|
||||
trace("Security Error Connecting:" + event);
|
||||
this.close();
|
||||
this.eventDispatcher.dispatchEvent(event);
|
||||
}
|
||||
|
||||
public function socketDataHandler(event:ProgressEvent):void
|
||||
{
|
||||
trace("Got Data call:" +ioCallback);
|
||||
if (ioCallback != null)
|
||||
{
|
||||
ioCallback(null);
|
||||
};
|
||||
this.eventDispatcher.dispatchEvent(event);
|
||||
}
|
||||
|
||||
public override function flush(callback:Function = null):void
|
||||
{
|
||||
trace("set callback:" + callback);
|
||||
this.ioCallback = callback;
|
||||
this.output.writeUTF(this.obuffer.length.toString(16));
|
||||
this.output.writeBytes(CRLF);
|
||||
this.output.writeBytes(this.obuffer);
|
||||
this.output.writeBytes(CRLF);
|
||||
this.socket.flush();
|
||||
// waiting for new Flex sdk 3.5
|
||||
//this.obuffer.clear();
|
||||
this.obuffer = new ByteArray();
|
||||
}
|
||||
|
||||
public override function isOpen():Boolean
|
||||
{
|
||||
return (this.socket == null ? false : this.socket.connected);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
134
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/transport/THttpClient.as
generated
vendored
Normal file
134
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/transport/THttpClient.as
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.transport {
|
||||
|
||||
import flash.errors.EOFError;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLLoaderDataFormat;
|
||||
import flash.net.URLRequest;
|
||||
import flash.net.URLRequestMethod;
|
||||
import flash.system.Capabilities;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
/**
|
||||
* HTTP implementation of the TTransport interface. Used for working with a
|
||||
* Thrift web services implementation.
|
||||
*/
|
||||
public class THttpClient extends TTransport {
|
||||
|
||||
private var request_:URLRequest = null;
|
||||
private var requestBuffer_:ByteArray = new ByteArray();
|
||||
private var responseBuffer_:ByteArray = null;
|
||||
private var traceBuffers_:Boolean = Capabilities.isDebugger;
|
||||
|
||||
|
||||
public function getBuffer():ByteArray {
|
||||
return requestBuffer_;
|
||||
}
|
||||
|
||||
public function THttpClient(request:URLRequest, traceBuffers:Boolean=true):void {
|
||||
request.contentType = "application/x-thrift";
|
||||
request_ = request;
|
||||
if(traceBuffers == false) {
|
||||
traceBuffers_ = traceBuffers;
|
||||
}
|
||||
}
|
||||
|
||||
public override function open():void {
|
||||
}
|
||||
|
||||
public override function close():void {
|
||||
}
|
||||
|
||||
public override function isOpen():Boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override function read(buf:ByteArray, off:int, len:int):int {
|
||||
if (responseBuffer_ == null) {
|
||||
throw new TTransportError(TTransportError.UNKNOWN, "Response buffer is empty, no request.");
|
||||
}
|
||||
try {
|
||||
responseBuffer_.readBytes(buf, off, len);
|
||||
if (traceBuffers_) {
|
||||
dumpBuffer(buf, "READ");
|
||||
}
|
||||
return len;
|
||||
}
|
||||
catch (e:EOFError) {
|
||||
if (traceBuffers_) {
|
||||
dumpBuffer(requestBuffer_, "FAILED-RESPONSE-REQUEST");
|
||||
dumpBuffer(responseBuffer_, "FAILED-RESPONSE");
|
||||
}
|
||||
throw new TTransportError(TTransportError.UNKNOWN, "No more data available.");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override function write(buf:ByteArray, off:int, len:int):void {
|
||||
requestBuffer_.writeBytes(buf, off, len);
|
||||
}
|
||||
|
||||
public override function flush(callback:Function=null):void {
|
||||
var loader:URLLoader = new URLLoader();
|
||||
if (callback != null) {
|
||||
loader.addEventListener(Event.COMPLETE, function(event:Event):void {
|
||||
responseBuffer_ = URLLoader(event.target).data;
|
||||
if (traceBuffers_) {
|
||||
dumpBuffer(responseBuffer_, "RESPONSE_BUFFER");
|
||||
}
|
||||
callback(null);
|
||||
responseBuffer_ = null;
|
||||
});
|
||||
loader.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent):void {
|
||||
callback(new TTransportError(TTransportError.UNKNOWN, "IOError: " + event.text));
|
||||
responseBuffer_ = null;
|
||||
});
|
||||
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function(event:SecurityErrorEvent):void {
|
||||
callback(new TTransportError(TTransportError.UNKNOWN, "SecurityError: " + event.text));
|
||||
responseBuffer_ = null;
|
||||
});
|
||||
}
|
||||
request_.method = URLRequestMethod.POST;
|
||||
loader.dataFormat = URLLoaderDataFormat.BINARY;
|
||||
requestBuffer_.position = 0;
|
||||
request_.data = requestBuffer_;
|
||||
loader.load(request_);
|
||||
}
|
||||
|
||||
private function dumpBuffer(buf:ByteArray, prefix:String):String {
|
||||
var debugString : String = prefix + " BUFFER ";
|
||||
if (buf != null) {
|
||||
debugString += "length: " + buf.length + ", ";
|
||||
for (var i : int = 0; i < buf.length; i++) {
|
||||
debugString += "[" + buf[i].toString(16) + "]";
|
||||
}
|
||||
} else {
|
||||
debugString = "null";
|
||||
}
|
||||
trace(debugString);
|
||||
return debugString;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
194
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/transport/TSocket.as
generated
vendored
Normal file
194
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/transport/TSocket.as
generated
vendored
Normal file
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.transport
|
||||
{
|
||||
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
import flash.errors.EOFError;
|
||||
import flash.errors.IOError;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLLoaderDataFormat;
|
||||
import flash.net.URLRequest;
|
||||
import flash.net.URLRequestMethod;
|
||||
import flash.utils.IDataInput;
|
||||
import flash.utils.IDataOutput;
|
||||
import flash.utils.ByteArray;
|
||||
import flash.net.Socket;
|
||||
|
||||
|
||||
/**
|
||||
* Socket implementation of the TTransport interface. Used for working with a
|
||||
* Thrift Socket Server based implementations.
|
||||
*/
|
||||
|
||||
public class TSocket extends TTransport
|
||||
{
|
||||
private var socket:Socket = null;
|
||||
|
||||
private var host:String;
|
||||
|
||||
private var port:int;
|
||||
|
||||
private var obuffer:ByteArray = new ByteArray();
|
||||
|
||||
private var input:IDataInput;
|
||||
|
||||
private var output:IDataOutput;
|
||||
|
||||
private var ioCallback:Function = null;
|
||||
|
||||
private var eventDispatcher:EventDispatcher = new EventDispatcher();
|
||||
|
||||
public function TSocket(host:String, port:int):void
|
||||
{
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public override function close():void
|
||||
{
|
||||
this.input = null;
|
||||
this.output = null;
|
||||
socket.close()
|
||||
}
|
||||
|
||||
public override function peek():Boolean
|
||||
{
|
||||
if(socket.connected)
|
||||
{
|
||||
trace("Bytes remained:" + socket.bytesAvailable);
|
||||
return socket.bytesAvailable>0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override function read(buf:ByteArray, off:int, len:int):int
|
||||
{
|
||||
var n1:int = 0, n2:int = 0, n3:int = 0, n4:int = 0, cidx:int = 2;
|
||||
var chunkSize:ByteArray = new ByteArray();
|
||||
|
||||
try
|
||||
{
|
||||
input.readBytes(buf, off, len);
|
||||
return len;
|
||||
}
|
||||
catch (e:EOFError)
|
||||
{
|
||||
trace(e);
|
||||
throw new TTransportError(TTransportError.END_OF_FILE, "No more data available.");
|
||||
}
|
||||
catch (e:IOError)
|
||||
{
|
||||
trace(e);
|
||||
if(isOpen())
|
||||
{
|
||||
throw new TTransportError(TTransportError.UNKNOWN, "IO error while reading: " + e);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new TTransportError(TTransportError.NOT_OPEN, "Socket seem not to be opened: " + e);
|
||||
}
|
||||
}
|
||||
catch (e:Error)
|
||||
{
|
||||
trace(e);
|
||||
throw new TTransportError(TTransportError.UNKNOWN, "Bad IO error: " + e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override function write(buf:ByteArray, off:int, len:int):void
|
||||
{
|
||||
obuffer.writeBytes(buf, off, len);
|
||||
}
|
||||
|
||||
public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
|
||||
{
|
||||
this.eventDispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
|
||||
}
|
||||
|
||||
public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
|
||||
{
|
||||
this.eventDispatcher.removeEventListener(type, listener, useCapture);
|
||||
}
|
||||
|
||||
public override function open():void
|
||||
{
|
||||
this.socket = new Socket();
|
||||
this.socket.addEventListener(Event.CONNECT, socketConnected);
|
||||
this.socket.addEventListener(IOErrorEvent.IO_ERROR, socketError);
|
||||
this.socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, socketSecurityError);
|
||||
this.socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
|
||||
this.socket.connect(host, port);
|
||||
}
|
||||
|
||||
public function socketConnected(event:Event):void
|
||||
{
|
||||
this.output = this.socket;
|
||||
this.input = this.socket;
|
||||
this.eventDispatcher.dispatchEvent(event);
|
||||
}
|
||||
|
||||
public function socketError(event:IOErrorEvent):void
|
||||
{
|
||||
trace("Error Connecting:" + event);
|
||||
this.close();
|
||||
if (ioCallback == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ioCallback(new TTransportError(TTransportError.UNKNOWN, "IOError: " + event.text));
|
||||
this.eventDispatcher.dispatchEvent(event);
|
||||
}
|
||||
|
||||
public function socketSecurityError(event:SecurityErrorEvent):void
|
||||
{
|
||||
trace("Security Error Connecting:" + event);
|
||||
this.close();
|
||||
this.eventDispatcher.dispatchEvent(event);
|
||||
}
|
||||
|
||||
public function socketDataHandler(event:ProgressEvent):void
|
||||
{
|
||||
if (ioCallback != null)
|
||||
{
|
||||
ioCallback(null);
|
||||
}
|
||||
this.eventDispatcher.dispatchEvent(event);
|
||||
}
|
||||
|
||||
public override function flush(callback:Function = null):void
|
||||
{
|
||||
this.ioCallback = callback;
|
||||
this.output.writeBytes(this.obuffer);
|
||||
this.socket.flush();
|
||||
this.obuffer.clear();
|
||||
}
|
||||
|
||||
public override function isOpen():Boolean
|
||||
{
|
||||
return (this.socket == null ? false : this.socket.connected);
|
||||
}
|
||||
}
|
||||
}
|
||||
127
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/transport/TTransport.as
generated
vendored
Normal file
127
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/transport/TTransport.as
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.transport {
|
||||
|
||||
import flash.utils.ByteArray;
|
||||
import org.apache.thrift.AbstractMethodError;
|
||||
|
||||
public class TTransport {
|
||||
|
||||
/**
|
||||
* Queries whether the transport is open.
|
||||
*
|
||||
* @return True if the transport is open.
|
||||
*/
|
||||
public function isOpen():Boolean {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there more data to be read?
|
||||
*
|
||||
* @return True if the remote side is still alive and feeding us
|
||||
*/
|
||||
public function peek():Boolean {
|
||||
return isOpen();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the transport for reading/writing.
|
||||
*
|
||||
* @throws TTransportException if the transport could not be opened
|
||||
*/
|
||||
public function open():void {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the transport.
|
||||
*/
|
||||
public function close():void {
|
||||
throw new AbstractMethodError();
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads up to len bytes into buffer buf, starting att offset off.
|
||||
*
|
||||
* @param buf Array to read into
|
||||
* @param off Index to start reading at
|
||||
* @param len Maximum number of bytes to read
|
||||
* @return The number of bytes actually read
|
||||
* @throws TTransportException if there was an error reading data
|
||||
*/
|
||||
public function read(buf:ByteArray, off:int, len:int):int {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Guarantees that all of len bytes are actually read off the transport.
|
||||
*
|
||||
* @param buf Array to read into
|
||||
* @param off Index to start reading at
|
||||
* @param len Maximum number of bytes to read
|
||||
* @return The number of bytes actually read, which must be equal to len
|
||||
* @throws TTransportException if there was an error reading data
|
||||
*/
|
||||
public function readAll(buf:ByteArray, off:int, len:int):int {
|
||||
var got:int = 0;
|
||||
var ret:int = 0;
|
||||
while (got < len) {
|
||||
ret = read(buf, off+got, len-got);
|
||||
if (ret <= 0) {
|
||||
throw new TTransportError(TTransportError.UNKNOWN, "Cannot read. Remote side has closed. Tried to read " + len + " bytes, but only got " + got + " bytes.");
|
||||
}
|
||||
got += ret;
|
||||
}
|
||||
return got;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the buffer to the output
|
||||
*
|
||||
* @param buf The output data buffer
|
||||
* @throws TTransportException if an error occurs writing data
|
||||
*/
|
||||
public function writeAll(buf:ByteArray):void {
|
||||
write(buf, 0, buf.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes up to len bytes from the buffer.
|
||||
*
|
||||
* @param buf The output data buffer
|
||||
* @param off The offset to start writing from
|
||||
* @param len The number of bytes to write
|
||||
* @throws TTransportException if there was an error writing data
|
||||
*/
|
||||
public function write(buf:ByteArray, off:int, len:int):void {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush any pending data out of a transport buffer.
|
||||
*
|
||||
* @throws TTransportException if there was an error writing out data.
|
||||
*/
|
||||
public function flush(callback:Function=null):void {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
}
|
||||
}
|
||||
37
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/transport/TTransportError.as
generated
vendored
Normal file
37
vendor/github.com/apache/thrift/lib/as3/src/org/apache/thrift/transport/TTransportError.as
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.transport {
|
||||
|
||||
import org.apache.thrift.TError;
|
||||
|
||||
public class TTransportError extends TError {
|
||||
|
||||
public static const UNKNOWN:int = 0;
|
||||
public static const NOT_OPEN:int = 1;
|
||||
public static const ALREADY_OPEN:int = 2;
|
||||
public static const TIMED_OUT:int = 3;
|
||||
public static const END_OF_FILE:int = 4;
|
||||
|
||||
public function TTransportError(error:int = UNKNOWN, message:String = "") {
|
||||
super(message, error);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
83
vendor/github.com/apache/thrift/lib/c_glib/CMakeLists.txt
generated
vendored
Normal file
83
vendor/github.com/apache/thrift/lib/c_glib/CMakeLists.txt
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
# Find required packages
|
||||
find_package(GLIB REQUIRED COMPONENTS gobject)
|
||||
include_directories(${GLIB_INCLUDE_DIRS})
|
||||
|
||||
include_directories(src)
|
||||
|
||||
# SYSLIBS contains libraries that need to be linked to all lib targets
|
||||
set(SYSLIBS ${GLIB_LIBRARIES} ${GLIB_GOBJECT_LIBRARIES})
|
||||
|
||||
# Create the thrift C glib library
|
||||
set(thrift_c_glib_SOURCES
|
||||
src/thrift/c_glib/thrift.c
|
||||
src/thrift/c_glib/thrift_struct.c
|
||||
src/thrift/c_glib/thrift_application_exception.c
|
||||
src/thrift/c_glib/processor/thrift_processor.c
|
||||
src/thrift/c_glib/processor/thrift_dispatch_processor.c
|
||||
src/thrift/c_glib/protocol/thrift_protocol.c
|
||||
src/thrift/c_glib/protocol/thrift_protocol_factory.c
|
||||
src/thrift/c_glib/protocol/thrift_binary_protocol.c
|
||||
src/thrift/c_glib/protocol/thrift_binary_protocol_factory.c
|
||||
src/thrift/c_glib/protocol/thrift_compact_protocol.c
|
||||
src/thrift/c_glib/protocol/thrift_compact_protocol_factory.c
|
||||
src/thrift/c_glib/transport/thrift_transport.c
|
||||
src/thrift/c_glib/transport/thrift_transport_factory.c
|
||||
src/thrift/c_glib/transport/thrift_buffered_transport_factory.c
|
||||
src/thrift/c_glib/transport/thrift_framed_transport_factory.c
|
||||
src/thrift/c_glib/transport/thrift_socket.c
|
||||
src/thrift/c_glib/transport/thrift_server_transport.c
|
||||
src/thrift/c_glib/transport/thrift_server_socket.c
|
||||
src/thrift/c_glib/transport/thrift_buffered_transport.c
|
||||
src/thrift/c_glib/transport/thrift_fd_transport.c
|
||||
src/thrift/c_glib/transport/thrift_framed_transport.c
|
||||
src/thrift/c_glib/transport/thrift_memory_buffer.c
|
||||
src/thrift/c_glib/server/thrift_server.c
|
||||
src/thrift/c_glib/server/thrift_simple_server.c
|
||||
)
|
||||
|
||||
# If OpenSSL is not found just ignore the OpenSSL stuff
|
||||
find_package(OpenSSL)
|
||||
if(OPENSSL_FOUND AND WITH_OPENSSL)
|
||||
list( APPEND thriftcpp_SOURCES
|
||||
src/thrift/c_glib/transport/thrift_ssl_socket.c
|
||||
)
|
||||
include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}")
|
||||
list(APPEND SYSLIBS "${OPENSSL_LIBRARIES}")
|
||||
endif()
|
||||
|
||||
|
||||
# Contains the thrift specific ADD_LIBRARY_THRIFT and TARGET_LINK_LIBRARIES_THRIFT
|
||||
include(ThriftMacros)
|
||||
|
||||
ADD_LIBRARY_THRIFT(thrift_c_glib ${thrift_c_glib_SOURCES})
|
||||
TARGET_LINK_LIBRARIES_THRIFT(thrift_c_glib ${SYSLIBS})
|
||||
|
||||
# Install the headers
|
||||
install(DIRECTORY "src/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
# Copy config.h file
|
||||
install(DIRECTORY "${CMAKE_BINARY_DIR}/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
113
vendor/github.com/apache/thrift/lib/c_glib/Makefile.am
generated
vendored
Executable file
113
vendor/github.com/apache/thrift/lib/c_glib/Makefile.am
generated
vendored
Executable file
@@ -0,0 +1,113 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
AUTOMAKE_OPTIONS = serial-tests
|
||||
SUBDIRS = . test
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
|
||||
lib_LTLIBRARIES = libthrift_c_glib.la
|
||||
pkgconfig_DATA = thrift_c_glib.pc
|
||||
|
||||
AM_CPPFLAGS = -Isrc -I src/thrift/c_glib
|
||||
AM_CFLAGS = -Wall -Wextra -pedantic
|
||||
|
||||
# Define the source files for the module
|
||||
|
||||
libthrift_c_glib_la_SOURCES = src/thrift/c_glib/thrift.c \
|
||||
src/thrift/c_glib/thrift_struct.c \
|
||||
src/thrift/c_glib/thrift_application_exception.c \
|
||||
src/thrift/c_glib/processor/thrift_processor.c \
|
||||
src/thrift/c_glib/processor/thrift_dispatch_processor.c \
|
||||
src/thrift/c_glib/protocol/thrift_protocol.c \
|
||||
src/thrift/c_glib/protocol/thrift_protocol_decorator.c \
|
||||
src/thrift/c_glib/protocol/thrift_protocol_factory.c \
|
||||
src/thrift/c_glib/protocol/thrift_binary_protocol.c \
|
||||
src/thrift/c_glib/protocol/thrift_multiplexed_protocol.c \
|
||||
src/thrift/c_glib/protocol/thrift_binary_protocol_factory.c \
|
||||
src/thrift/c_glib/protocol/thrift_compact_protocol.c \
|
||||
src/thrift/c_glib/protocol/thrift_compact_protocol_factory.c \
|
||||
src/thrift/c_glib/transport/thrift_transport.c \
|
||||
src/thrift/c_glib/transport/thrift_transport_factory.c \
|
||||
src/thrift/c_glib/transport/thrift_buffered_transport_factory.c \
|
||||
src/thrift/c_glib/transport/thrift_framed_transport_factory.c \
|
||||
src/thrift/c_glib/transport/thrift_socket.c \
|
||||
src/thrift/c_glib/transport/thrift_ssl_socket.c \
|
||||
src/thrift/c_glib/transport/thrift_server_transport.c \
|
||||
src/thrift/c_glib/transport/thrift_server_socket.c \
|
||||
src/thrift/c_glib/transport/thrift_buffered_transport.c \
|
||||
src/thrift/c_glib/transport/thrift_fd_transport.c \
|
||||
src/thrift/c_glib/transport/thrift_framed_transport.c \
|
||||
src/thrift/c_glib/transport/thrift_memory_buffer.c \
|
||||
src/thrift/c_glib/server/thrift_server.c \
|
||||
src/thrift/c_glib/server/thrift_simple_server.c
|
||||
|
||||
libthrift_c_glib_la_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS) $(GOBJECT_CFLAGS) $(OPENSSL_INCLUDES)
|
||||
libthrift_c_glib_la_LDFLAGS = $(AM_LDFLAGS) $(OPENSSL_LDFLAGS) $(OPENSSL_LIBS)
|
||||
|
||||
include_thriftdir = $(includedir)/thrift/c_glib
|
||||
include_thrift_HEADERS = \
|
||||
$(top_builddir)/config.h \
|
||||
src/thrift/c_glib/thrift.h \
|
||||
src/thrift/c_glib/thrift_application_exception.h \
|
||||
src/thrift/c_glib/thrift_struct.h
|
||||
|
||||
include_protocoldir = $(include_thriftdir)/protocol
|
||||
include_protocol_HEADERS = src/thrift/c_glib/protocol/thrift_protocol.h \
|
||||
src/thrift/c_glib/protocol/thrift_protocol_decorator.h \
|
||||
src/thrift/c_glib/protocol/thrift_protocol_factory.h \
|
||||
src/thrift/c_glib/protocol/thrift_binary_protocol.h \
|
||||
src/thrift/c_glib/protocol/thrift_binary_protocol_factory.h \
|
||||
src/thrift/c_glib/protocol/thrift_compact_protocol.h \
|
||||
src/thrift/c_glib/protocol/thrift_compact_protocol_factory.h \
|
||||
src/thrift/c_glib/protocol/thrift_multiplexed_protocol.h
|
||||
|
||||
include_transportdir = $(include_thriftdir)/transport
|
||||
include_transport_HEADERS = src/thrift/c_glib/transport/thrift_buffered_transport.h \
|
||||
src/thrift/c_glib/transport/thrift_fd_transport.h \
|
||||
src/thrift/c_glib/transport/thrift_framed_transport.h \
|
||||
src/thrift/c_glib/transport/thrift_memory_buffer.h \
|
||||
src/thrift/c_glib/transport/thrift_server_socket.h \
|
||||
src/thrift/c_glib/transport/thrift_server_transport.h \
|
||||
src/thrift/c_glib/transport/thrift_socket.h \
|
||||
src/thrift/c_glib/transport/thrift_platform_socket.h \
|
||||
src/thrift/c_glib/transport/thrift_ssl_socket.h \
|
||||
src/thrift/c_glib/transport/thrift_transport.h \
|
||||
src/thrift/c_glib/transport/thrift_transport_factory.h \
|
||||
src/thrift/c_glib/transport/thrift_buffered_transport_factory.h \
|
||||
src/thrift/c_glib/transport/thrift_framed_transport_factory.h
|
||||
|
||||
include_serverdir = $(include_thriftdir)/server
|
||||
include_server_HEADERS = src/thrift/c_glib/server/thrift_server.h \
|
||||
src/thrift/c_glib/server/thrift_simple_server.h
|
||||
|
||||
include_processordir = $(include_thriftdir)/processor
|
||||
include_processor_HEADERS = src/thrift/c_glib/processor/thrift_processor.h \
|
||||
src/thrift/c_glib/processor/thrift_dispatch_processor.h
|
||||
|
||||
|
||||
EXTRA_DIST = \
|
||||
CMakeLists.txt \
|
||||
coding_standards.md \
|
||||
README.md \
|
||||
test/glib.suppress \
|
||||
thrift_c_glib.pc.in
|
||||
|
||||
CLEANFILES = \
|
||||
*.gcno \
|
||||
*.gcda
|
||||
34
vendor/github.com/apache/thrift/lib/c_glib/README.md
generated
vendored
Normal file
34
vendor/github.com/apache/thrift/lib/c_glib/README.md
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
Thrift C Software Library
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
|
||||
Using Thrift with C
|
||||
===================
|
||||
|
||||
The Thrift C libraries are built using the GNU tools. Follow the instructions
|
||||
in the top-level README in order to generate the Makefiles.
|
||||
|
||||
Dependencies
|
||||
============
|
||||
|
||||
GLib
|
||||
http://www.gtk.org/
|
||||
|
||||
5
vendor/github.com/apache/thrift/lib/c_glib/coding_standards.md
generated
vendored
Normal file
5
vendor/github.com/apache/thrift/lib/c_glib/coding_standards.md
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
## C Glib Coding Standards
|
||||
|
||||
Please follow:
|
||||
* [Thrift General Coding Standards](/doc/coding_standards.md)
|
||||
* [GNOME C Coding Style](https://help.gnome.org/users/programming-guidelines/stable/c-coding-style.html.en)
|
||||
143
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/processor/thrift_dispatch_processor.c
generated
vendored
Normal file
143
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/processor/thrift_dispatch_processor.c
generated
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/thrift_application_exception.h>
|
||||
#include <thrift/c_glib/processor/thrift_dispatch_processor.h>
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (ThriftDispatchProcessor,
|
||||
thrift_dispatch_processor,
|
||||
THRIFT_TYPE_PROCESSOR)
|
||||
|
||||
gboolean
|
||||
thrift_dispatch_processor_process (ThriftProcessor *processor,
|
||||
ThriftProtocol *in,
|
||||
ThriftProtocol *out,
|
||||
GError **error)
|
||||
{
|
||||
gchar *fname;
|
||||
ThriftMessageType mtype;
|
||||
gint32 seqid;
|
||||
ThriftDispatchProcessor *dispatch_processor =
|
||||
THRIFT_DISPATCH_PROCESSOR (processor);
|
||||
|
||||
/* Read the start of the message, which we expect to be a method call */
|
||||
if (thrift_protocol_read_message_begin (in,
|
||||
&fname,
|
||||
&mtype,
|
||||
&seqid,
|
||||
error) < 0) {
|
||||
g_warning ("error reading start of message: %s",
|
||||
(error != NULL) ? (*error)->message : "(null)");
|
||||
return FALSE;
|
||||
}
|
||||
else if (mtype != T_CALL && mtype != T_ONEWAY) {
|
||||
g_warning ("received invalid message type %d from client", mtype);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Dispatch the method call */
|
||||
return THRIFT_DISPATCH_PROCESSOR_GET_CLASS (dispatch_processor)
|
||||
->dispatch_call (dispatch_processor,
|
||||
in,
|
||||
out,
|
||||
fname,
|
||||
seqid,
|
||||
error);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
thrift_dispatch_processor_real_dispatch_call (ThriftDispatchProcessor *self,
|
||||
ThriftProtocol *in,
|
||||
ThriftProtocol *out,
|
||||
gchar *fname,
|
||||
gint32 seqid,
|
||||
GError **error)
|
||||
{
|
||||
ThriftTransport *transport;
|
||||
ThriftApplicationException *xception;
|
||||
gchar *message;
|
||||
gint32 result;
|
||||
gboolean dispatch_result = FALSE;
|
||||
|
||||
THRIFT_UNUSED_VAR (self);
|
||||
|
||||
/* By default, return an application exception to the client indicating the
|
||||
method name is not recognized. */
|
||||
|
||||
if ((thrift_protocol_skip (in, T_STRUCT, error) < 0) ||
|
||||
(thrift_protocol_read_message_end (in, error) < 0))
|
||||
return FALSE;
|
||||
|
||||
g_object_get (in, "transport", &transport, NULL);
|
||||
result = thrift_transport_read_end (transport, error);
|
||||
g_object_unref (transport);
|
||||
if (result < 0)
|
||||
return FALSE;
|
||||
|
||||
if (thrift_protocol_write_message_begin (out,
|
||||
fname,
|
||||
T_EXCEPTION,
|
||||
seqid,
|
||||
error) < 0)
|
||||
return FALSE;
|
||||
message = g_strconcat ("Invalid method name: '", fname, "'", NULL);
|
||||
g_free (fname);
|
||||
xception =
|
||||
g_object_new (THRIFT_TYPE_APPLICATION_EXCEPTION,
|
||||
"type", THRIFT_APPLICATION_EXCEPTION_ERROR_UNKNOWN_METHOD,
|
||||
"message", message,
|
||||
NULL);
|
||||
g_free (message);
|
||||
result = thrift_struct_write (THRIFT_STRUCT (xception),
|
||||
out,
|
||||
error);
|
||||
g_object_unref (xception);
|
||||
if ((result < 0) ||
|
||||
(thrift_protocol_write_message_end (out, error) < 0))
|
||||
return FALSE;
|
||||
|
||||
g_object_get (out, "transport", &transport, NULL);
|
||||
dispatch_result =
|
||||
((thrift_transport_write_end (transport, error) >= 0) &&
|
||||
(thrift_transport_flush (transport, error) >= 0));
|
||||
g_object_unref (transport);
|
||||
|
||||
return dispatch_result;
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_dispatch_processor_init (ThriftDispatchProcessor *self)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (self);
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_dispatch_processor_class_init (ThriftDispatchProcessorClass *klass)
|
||||
{
|
||||
ThriftProcessorClass *processor_class =
|
||||
THRIFT_PROCESSOR_CLASS (klass);
|
||||
|
||||
/* Implement ThriftProcessor's process method */
|
||||
processor_class->process = thrift_dispatch_processor_process;
|
||||
|
||||
/* Provide a default implement for dispatch_call, which returns an exception
|
||||
to the client indicating the method name was not recognized */
|
||||
klass->dispatch_call = thrift_dispatch_processor_real_dispatch_call;
|
||||
}
|
||||
95
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/processor/thrift_dispatch_processor.h
generated
vendored
Normal file
95
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/processor/thrift_dispatch_processor.h
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_DISPATCH_PROCESSOR_H
|
||||
#define _THRIFT_DISPATCH_PROCESSOR_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/processor/thrift_processor.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_dispatch_processor.h
|
||||
* \brief Parses a method-call message header and invokes a function
|
||||
* to dispatch the call by function name.
|
||||
*
|
||||
* ThriftDispatchProcessor is an abstract helper class that parses the
|
||||
* header of a method-call message and invokes a member function,
|
||||
* dispatch_call, with the method's name.
|
||||
*
|
||||
* Subclasses must implement dispatch_call to dispatch the method call
|
||||
* to the implementing function.
|
||||
*/
|
||||
|
||||
/* Type macros */
|
||||
#define THRIFT_TYPE_DISPATCH_PROCESSOR (thrift_dispatch_processor_get_type ())
|
||||
#define THRIFT_DISPATCH_PROCESSOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_DISPATCH_PROCESSOR, ThriftDispatchProcessor))
|
||||
#define THRIFT_IS_DISPATCH_PROCESSOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_DISPATCH_PROCESSOR))
|
||||
#define THRIFT_DISPATCH_PROCESSOR_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_DISPATCH_PROCESSOR, ThriftDispatchProcessorClass))
|
||||
#define THRIFT_IS_DISPATCH_PROCESSOR_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_DISPATCH_PROCESSOR))
|
||||
#define THRIFT_DISPATCH_PROCESSOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_DISPATCH_PROCESSOR, ThriftDispatchProcessorClass))
|
||||
|
||||
/*!
|
||||
* Thrift Dispatch Processor object
|
||||
*/
|
||||
struct _ThriftDispatchProcessor
|
||||
{
|
||||
ThriftProcessor parent;
|
||||
};
|
||||
typedef struct _ThriftDispatchProcessor ThriftDispatchProcessor;
|
||||
|
||||
/*!
|
||||
* Thrift Dispatch Processor class
|
||||
*/
|
||||
struct _ThriftDispatchProcessorClass
|
||||
{
|
||||
ThriftProcessorClass parent;
|
||||
|
||||
/* public */
|
||||
gboolean (*process) (ThriftProcessor *processor,
|
||||
ThriftProtocol *in,
|
||||
ThriftProtocol *out,
|
||||
GError **error);
|
||||
|
||||
/* protected */
|
||||
gboolean (*dispatch_call) (ThriftDispatchProcessor *self,
|
||||
ThriftProtocol *in,
|
||||
ThriftProtocol *out,
|
||||
gchar *fname,
|
||||
gint32 seqid,
|
||||
GError **error);
|
||||
};
|
||||
typedef struct _ThriftDispatchProcessorClass ThriftDispatchProcessorClass;
|
||||
|
||||
/* Used by THRIFT_TYPE_DISPATCH_PROCESSOR */
|
||||
GType thrift_dispatch_processor_get_type (void);
|
||||
|
||||
/*!
|
||||
* Processes a request.
|
||||
* \public \memberof ThriftDispatchProcessorClass
|
||||
*/
|
||||
gboolean thrift_dispatch_processor_process (ThriftProcessor *processor,
|
||||
ThriftProtocol *in,
|
||||
ThriftProtocol *out,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_DISPATCH_PROCESSOR_H */
|
||||
45
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/processor/thrift_processor.c
generated
vendored
Normal file
45
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/processor/thrift_processor.c
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/processor/thrift_processor.h>
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE(ThriftProcessor, thrift_processor, G_TYPE_OBJECT)
|
||||
|
||||
gboolean
|
||||
thrift_processor_process (ThriftProcessor *processor, ThriftProtocol *in,
|
||||
ThriftProtocol *out, GError **error)
|
||||
{
|
||||
return
|
||||
THRIFT_PROCESSOR_GET_CLASS (processor)->process (processor, in, out, error);
|
||||
}
|
||||
|
||||
/* class initializer for ThriftProcessor */
|
||||
static void
|
||||
thrift_processor_class_init (ThriftProcessorClass *cls)
|
||||
{
|
||||
/* set these as virtual methods to be implemented by a subclass */
|
||||
cls->process = thrift_processor_process;
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_processor_init (ThriftProcessor *processor)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (processor);
|
||||
}
|
||||
76
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/processor/thrift_processor.h
generated
vendored
Normal file
76
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/processor/thrift_processor.h
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_PROCESSOR_H
|
||||
#define _THRIFT_PROCESSOR_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/protocol/thrift_protocol.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_processor.h
|
||||
* \brief Abstract class for Thrift processors.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_PROCESSOR (thrift_processor_get_type ())
|
||||
#define THRIFT_PROCESSOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_PROCESSOR, ThriftProcessor))
|
||||
#define THRIFT_IS_PROCESSOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_PROCESSOR))
|
||||
#define THRIFT_PROCESSOR_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_PROCESSOR, ThriftProcessorClass))
|
||||
#define THRIFT_IS_PROCESSOR_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_PROCESSOR))
|
||||
#define THRIFT_PROCESSOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_PROCESSOR, ThriftProcessorClass))
|
||||
|
||||
/*!
|
||||
* Thrift Processorobject
|
||||
*/
|
||||
struct _ThriftProcessor
|
||||
{
|
||||
GObject parent;
|
||||
};
|
||||
typedef struct _ThriftProcessor ThriftProcessor;
|
||||
|
||||
/*!
|
||||
* Thrift Processor class
|
||||
*/
|
||||
struct _ThriftProcessorClass
|
||||
{
|
||||
GObjectClass parent;
|
||||
|
||||
/* vtable */
|
||||
gboolean (*process) (ThriftProcessor *processor, ThriftProtocol *in,
|
||||
ThriftProtocol *out, GError **error);
|
||||
};
|
||||
typedef struct _ThriftProcessorClass ThriftProcessorClass;
|
||||
|
||||
/* used by THRIFT_TYPE_PROCESSOR */
|
||||
GType thrift_processor_get_type (void);
|
||||
|
||||
/*!
|
||||
* Processes the request.
|
||||
* \public \memberof ThriftProcessorClass
|
||||
*/
|
||||
gboolean thrift_processor_process (ThriftProcessor *processor,
|
||||
ThriftProtocol *in, ThriftProtocol *out,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_PROCESSOR_H */
|
||||
911
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_binary_protocol.c
generated
vendored
Normal file
911
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_binary_protocol.c
generated
vendored
Normal file
@@ -0,0 +1,911 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/protocol/thrift_protocol.h>
|
||||
#include <thrift/c_glib/protocol/thrift_binary_protocol.h>
|
||||
|
||||
G_DEFINE_TYPE(ThriftBinaryProtocol, thrift_binary_protocol, THRIFT_TYPE_PROTOCOL)
|
||||
|
||||
static guint64
|
||||
thrift_bitwise_cast_guint64 (gdouble v)
|
||||
{
|
||||
union {
|
||||
gdouble from;
|
||||
guint64 to;
|
||||
} u;
|
||||
u.from = v;
|
||||
return u.to;
|
||||
}
|
||||
|
||||
static gdouble
|
||||
thrift_bitwise_cast_gdouble (guint64 v)
|
||||
{
|
||||
union {
|
||||
guint64 from;
|
||||
gdouble to;
|
||||
} u;
|
||||
u.from = v;
|
||||
return u.to;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_message_begin (ThriftProtocol *protocol,
|
||||
const gchar *name, const ThriftMessageType message_type,
|
||||
const gint32 seqid, GError **error)
|
||||
{
|
||||
gint32 version = (THRIFT_BINARY_PROTOCOL_VERSION_1)
|
||||
| ((gint32) message_type);
|
||||
gint32 ret;
|
||||
gint32 xfer = 0;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
if ((ret = thrift_protocol_write_i32 (protocol, version, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
if ((ret = thrift_protocol_write_string (protocol, name, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
if ((ret = thrift_protocol_write_i32 (protocol, seqid, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
return xfer;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_message_end (ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
/* satisfy -Wall */
|
||||
THRIFT_UNUSED_VAR (protocol);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_struct_begin (ThriftProtocol *protocol,
|
||||
const gchar *name,
|
||||
GError **error)
|
||||
{
|
||||
/* satisfy -Wall */
|
||||
THRIFT_UNUSED_VAR (protocol);
|
||||
THRIFT_UNUSED_VAR (name);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_struct_end (ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
/* satisfy -Wall */
|
||||
THRIFT_UNUSED_VAR (protocol);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_field_begin (ThriftProtocol *protocol,
|
||||
const gchar *name,
|
||||
const ThriftType field_type,
|
||||
const gint16 field_id,
|
||||
GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
gint32 xfer = 0;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
THRIFT_UNUSED_VAR (name);
|
||||
|
||||
if ((ret = thrift_protocol_write_byte (protocol, (gint8) field_type,
|
||||
error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
if ((ret = thrift_protocol_write_i16 (protocol, field_id, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
return xfer;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_field_end (ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
/* satisfy -Wall */
|
||||
THRIFT_UNUSED_VAR (protocol);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_field_stop (ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
return thrift_protocol_write_byte (protocol, (gint8) T_STOP, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_map_begin (ThriftProtocol *protocol,
|
||||
const ThriftType key_type,
|
||||
const ThriftType value_type,
|
||||
const guint32 size,
|
||||
GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
gint32 xfer = 0;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
if ((ret = thrift_protocol_write_byte (protocol, (gint8) key_type,
|
||||
error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
if ((ret = thrift_protocol_write_byte (protocol, (gint8) value_type,
|
||||
error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
if ((ret = thrift_protocol_write_i32 (protocol, (gint32) size, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
return xfer;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_map_end (ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (protocol);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_list_begin (ThriftProtocol *protocol,
|
||||
const ThriftType element_type,
|
||||
const guint32 size,
|
||||
GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
gint32 xfer = 0;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
if ((ret = thrift_protocol_write_byte (protocol, (gint8) element_type,
|
||||
error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
|
||||
if ((ret = thrift_protocol_write_i32 (protocol, (gint32) size, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
|
||||
return xfer;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_list_end (ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (protocol);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_set_begin (ThriftProtocol *protocol,
|
||||
const ThriftType element_type,
|
||||
const guint32 size,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
return thrift_protocol_write_list_begin (protocol, element_type,
|
||||
size, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_set_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (protocol);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_bool (ThriftProtocol *protocol,
|
||||
const gboolean value, GError **error)
|
||||
{
|
||||
guint8 tmp;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
tmp = value ? 1 : 0;
|
||||
return thrift_protocol_write_byte (protocol, tmp, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_byte (ThriftProtocol *protocol, const gint8 value,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
if (thrift_transport_write (protocol->transport,
|
||||
(const gpointer) &value, 1, error))
|
||||
{
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_i16 (ThriftProtocol *protocol, const gint16 value,
|
||||
GError **error)
|
||||
{
|
||||
gint16 net;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
net = g_htons (value);
|
||||
if (thrift_transport_write (protocol->transport,
|
||||
(const gpointer) &net, 2, error))
|
||||
{
|
||||
return 2;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_i32 (ThriftProtocol *protocol, const gint32 value,
|
||||
GError **error)
|
||||
{
|
||||
gint32 net;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
net = g_htonl (value);
|
||||
if (thrift_transport_write (protocol->transport,
|
||||
(const gpointer) &net, 4, error))
|
||||
{
|
||||
return 4;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_i64 (ThriftProtocol *protocol, const gint64 value,
|
||||
GError **error)
|
||||
{
|
||||
gint64 net;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
net = GUINT64_TO_BE (value);
|
||||
if (thrift_transport_write (protocol->transport,
|
||||
(const gpointer) &net, 8, error))
|
||||
{
|
||||
return 8;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_double (ThriftProtocol *protocol,
|
||||
const gdouble value, GError **error)
|
||||
{
|
||||
guint64 bits;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
bits = GUINT64_FROM_BE (thrift_bitwise_cast_guint64 (value));
|
||||
if (thrift_transport_write (protocol->transport,
|
||||
(const gpointer) &bits, 8, error))
|
||||
{
|
||||
return 8;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_string (ThriftProtocol *protocol,
|
||||
const gchar *str, GError **error)
|
||||
{
|
||||
guint32 len;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
len = str != NULL ? strlen (str) : 0;
|
||||
/* write the string length + 1 which includes the null terminator */
|
||||
return thrift_protocol_write_binary (protocol, (const gpointer) str,
|
||||
len, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_write_binary (ThriftProtocol *protocol,
|
||||
const gpointer buf,
|
||||
const guint32 len, GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
gint32 xfer = 0;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
if ((ret = thrift_protocol_write_i32 (protocol, len, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
if (thrift_transport_write (protocol->transport,
|
||||
(const gpointer) buf, len, error) == FALSE)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += len;
|
||||
}
|
||||
|
||||
return xfer;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_message_begin (ThriftProtocol *protocol,
|
||||
gchar **name,
|
||||
ThriftMessageType *message_type,
|
||||
gint32 *seqid, GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
gint32 xfer = 0;
|
||||
gint32 sz;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
if ((ret = thrift_protocol_read_i32 (protocol, &sz, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
|
||||
if (sz < 0)
|
||||
{
|
||||
/* check for version */
|
||||
guint32 version = sz & THRIFT_BINARY_PROTOCOL_VERSION_MASK;
|
||||
if (version != THRIFT_BINARY_PROTOCOL_VERSION_1)
|
||||
{
|
||||
g_set_error (error, THRIFT_PROTOCOL_ERROR,
|
||||
THRIFT_PROTOCOL_ERROR_BAD_VERSION,
|
||||
"expected version %d, got %d",
|
||||
THRIFT_BINARY_PROTOCOL_VERSION_1, version);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*message_type = (ThriftMessageType) (sz & 0x000000ff);
|
||||
|
||||
if ((ret = thrift_protocol_read_string (protocol, name, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
|
||||
if ((ret = thrift_protocol_read_i32 (protocol, seqid, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
}
|
||||
return xfer;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_message_end (ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (protocol);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_struct_begin (ThriftProtocol *protocol,
|
||||
gchar **name,
|
||||
GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (protocol);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
*name = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_struct_end (ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (protocol);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_field_begin (ThriftProtocol *protocol,
|
||||
gchar **name,
|
||||
ThriftType *field_type,
|
||||
gint16 *field_id,
|
||||
GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
gint32 xfer = 0;
|
||||
gint8 type;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
THRIFT_UNUSED_VAR (name);
|
||||
|
||||
if ((ret = thrift_protocol_read_byte (protocol, &type, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
*field_type = (ThriftType) type;
|
||||
if (*field_type == T_STOP)
|
||||
{
|
||||
*field_id = 0;
|
||||
return xfer;
|
||||
}
|
||||
if ((ret = thrift_protocol_read_i16 (protocol, field_id, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
return xfer;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_field_end (ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (protocol);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_map_begin (ThriftProtocol *protocol,
|
||||
ThriftType *key_type,
|
||||
ThriftType *value_type,
|
||||
guint32 *size,
|
||||
GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
gint32 xfer = 0;
|
||||
gint8 k, v;
|
||||
gint32 sizei;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
if ((ret = thrift_protocol_read_byte (protocol, &k, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
*key_type = (ThriftType) k;
|
||||
|
||||
if ((ret = thrift_protocol_read_byte (protocol, &v, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
*value_type = (ThriftType) v;
|
||||
|
||||
if ((ret = thrift_protocol_read_i32 (protocol, &sizei, error)) <0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
|
||||
if (sizei < 0)
|
||||
{
|
||||
g_set_error (error, THRIFT_PROTOCOL_ERROR,
|
||||
THRIFT_PROTOCOL_ERROR_NEGATIVE_SIZE,
|
||||
"got negative size of %d", sizei);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*size = (guint32) sizei;
|
||||
return xfer;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_map_end (ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (protocol);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_list_begin (ThriftProtocol *protocol,
|
||||
ThriftType *element_type,
|
||||
guint32 *size, GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
gint32 xfer = 0;
|
||||
gint8 e;
|
||||
gint32 sizei;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
if ((ret = thrift_protocol_read_byte (protocol, &e, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
*element_type = (ThriftType) e;
|
||||
|
||||
if ((ret = thrift_protocol_read_i32 (protocol, &sizei, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
|
||||
if (sizei < 0)
|
||||
{
|
||||
g_set_error (error, THRIFT_PROTOCOL_ERROR,
|
||||
THRIFT_PROTOCOL_ERROR_NEGATIVE_SIZE,
|
||||
"got negative size of %d", sizei);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*size = (guint32) sizei;
|
||||
return xfer;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_list_end (ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (protocol);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_set_begin (ThriftProtocol *protocol,
|
||||
ThriftType *element_type,
|
||||
guint32 *size, GError **error)
|
||||
{
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
return thrift_protocol_read_list_begin (protocol, element_type, size, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_set_end (ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (protocol);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_bool (ThriftProtocol *protocol, gboolean *value,
|
||||
GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
gpointer b[1];
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
if ((ret =
|
||||
thrift_transport_read_all (protocol->transport,
|
||||
b, 1, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
*value = *(gint8 *) b != 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_byte (ThriftProtocol *protocol, gint8 *value,
|
||||
GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
gpointer b[1];
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
if ((ret =
|
||||
thrift_transport_read_all (protocol->transport,
|
||||
b, 1, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
*value = *(gint8 *) b;
|
||||
return ret;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_i16 (ThriftProtocol *protocol, gint16 *value,
|
||||
GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
union
|
||||
{
|
||||
gint8 byte_array[2];
|
||||
gint16 int16;
|
||||
} b;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
if ((ret =
|
||||
thrift_transport_read_all (protocol->transport,
|
||||
b.byte_array, 2, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
*value = g_ntohs (b.int16);
|
||||
return ret;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_i32 (ThriftProtocol *protocol, gint32 *value,
|
||||
GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
union
|
||||
{
|
||||
gint8 byte_array[4];
|
||||
gint32 int32;
|
||||
} b;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
if ((ret =
|
||||
thrift_transport_read_all (protocol->transport,
|
||||
b.byte_array, 4, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
*value = g_ntohl (b.int32);
|
||||
return ret;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_i64 (ThriftProtocol *protocol, gint64 *value,
|
||||
GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
union
|
||||
{
|
||||
gint8 byte_array[8];
|
||||
gint64 int64;
|
||||
} b;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
if ((ret =
|
||||
thrift_transport_read_all (protocol->transport,
|
||||
b.byte_array, 8, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
*value = GUINT64_FROM_BE (b.int64);
|
||||
return ret;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_double (ThriftProtocol *protocol,
|
||||
gdouble *value, GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
union
|
||||
{
|
||||
gint8 byte_array[8];
|
||||
guint64 uint64;
|
||||
} b;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
if ((ret =
|
||||
thrift_transport_read_all (protocol->transport,
|
||||
b.byte_array, 8, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
*value = thrift_bitwise_cast_gdouble (GUINT64_FROM_BE (b.uint64));
|
||||
return ret;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_string (ThriftProtocol *protocol,
|
||||
gchar **str, GError **error)
|
||||
{
|
||||
guint32 len;
|
||||
gint32 ret;
|
||||
gint32 xfer = 0;
|
||||
gint32 read_len = 0;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
/* read the length into read_len */
|
||||
if ((ret =
|
||||
thrift_protocol_read_i32 (protocol, &read_len, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
|
||||
if (read_len < 0) {
|
||||
g_set_error (error, THRIFT_PROTOCOL_ERROR,
|
||||
THRIFT_PROTOCOL_ERROR_NEGATIVE_SIZE,
|
||||
"got negative size of %d", read_len);
|
||||
*str = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* allocate the memory for the string */
|
||||
len = (guint32) read_len + 1; /* space for null terminator */
|
||||
*str = g_new0 (gchar, len);
|
||||
if (read_len > 0) {
|
||||
if ((ret =
|
||||
thrift_transport_read_all (protocol->transport,
|
||||
*str, read_len, error)) < 0)
|
||||
{
|
||||
g_free (*str);
|
||||
*str = NULL;
|
||||
len = 0;
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
} else {
|
||||
**str = 0;
|
||||
}
|
||||
|
||||
return xfer;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_binary_protocol_read_binary (ThriftProtocol *protocol,
|
||||
gpointer *buf, guint32 *len,
|
||||
GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
gint32 xfer = 0;
|
||||
gint32 read_len = 0;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
|
||||
|
||||
/* read the length into read_len */
|
||||
if ((ret =
|
||||
thrift_protocol_read_i32 (protocol, &read_len, error)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
|
||||
if (read_len > 0)
|
||||
{
|
||||
/* allocate the memory as an array of unsigned char for binary data */
|
||||
*len = (guint32) read_len;
|
||||
*buf = g_new (guchar, *len);
|
||||
if ((ret =
|
||||
thrift_transport_read_all (protocol->transport,
|
||||
*buf, *len, error)) < 0)
|
||||
{
|
||||
g_free (*buf);
|
||||
*buf = NULL;
|
||||
*len = 0;
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
} else {
|
||||
*len = (guint32) read_len;
|
||||
*buf = NULL;
|
||||
}
|
||||
|
||||
return xfer;
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_binary_protocol_init (ThriftBinaryProtocol *protocol)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (protocol);
|
||||
}
|
||||
|
||||
/* initialize the class */
|
||||
static void
|
||||
thrift_binary_protocol_class_init (ThriftBinaryProtocolClass *klass)
|
||||
{
|
||||
ThriftProtocolClass *cls = THRIFT_PROTOCOL_CLASS (klass);
|
||||
|
||||
cls->write_message_begin = thrift_binary_protocol_write_message_begin;
|
||||
cls->write_message_end = thrift_binary_protocol_write_message_end;
|
||||
cls->write_struct_begin = thrift_binary_protocol_write_struct_begin;
|
||||
cls->write_struct_end = thrift_binary_protocol_write_struct_end;
|
||||
cls->write_field_begin = thrift_binary_protocol_write_field_begin;
|
||||
cls->write_field_end = thrift_binary_protocol_write_field_end;
|
||||
cls->write_field_stop = thrift_binary_protocol_write_field_stop;
|
||||
cls->write_map_begin = thrift_binary_protocol_write_map_begin;
|
||||
cls->write_map_end = thrift_binary_protocol_write_map_end;
|
||||
cls->write_list_begin = thrift_binary_protocol_write_list_begin;
|
||||
cls->write_list_end = thrift_binary_protocol_write_list_end;
|
||||
cls->write_set_begin = thrift_binary_protocol_write_set_begin;
|
||||
cls->write_set_end = thrift_binary_protocol_write_set_end;
|
||||
cls->write_bool = thrift_binary_protocol_write_bool;
|
||||
cls->write_byte = thrift_binary_protocol_write_byte;
|
||||
cls->write_i16 = thrift_binary_protocol_write_i16;
|
||||
cls->write_i32 = thrift_binary_protocol_write_i32;
|
||||
cls->write_i64 = thrift_binary_protocol_write_i64;
|
||||
cls->write_double = thrift_binary_protocol_write_double;
|
||||
cls->write_string = thrift_binary_protocol_write_string;
|
||||
cls->write_binary = thrift_binary_protocol_write_binary;
|
||||
cls->read_message_begin = thrift_binary_protocol_read_message_begin;
|
||||
cls->read_message_end = thrift_binary_protocol_read_message_end;
|
||||
cls->read_struct_begin = thrift_binary_protocol_read_struct_begin;
|
||||
cls->read_struct_end = thrift_binary_protocol_read_struct_end;
|
||||
cls->read_field_begin = thrift_binary_protocol_read_field_begin;
|
||||
cls->read_field_end = thrift_binary_protocol_read_field_end;
|
||||
cls->read_map_begin = thrift_binary_protocol_read_map_begin;
|
||||
cls->read_map_end = thrift_binary_protocol_read_map_end;
|
||||
cls->read_list_begin = thrift_binary_protocol_read_list_begin;
|
||||
cls->read_list_end = thrift_binary_protocol_read_list_end;
|
||||
cls->read_set_begin = thrift_binary_protocol_read_set_begin;
|
||||
cls->read_set_end = thrift_binary_protocol_read_set_end;
|
||||
cls->read_bool = thrift_binary_protocol_read_bool;
|
||||
cls->read_byte = thrift_binary_protocol_read_byte;
|
||||
cls->read_i16 = thrift_binary_protocol_read_i16;
|
||||
cls->read_i32 = thrift_binary_protocol_read_i32;
|
||||
cls->read_i64 = thrift_binary_protocol_read_i64;
|
||||
cls->read_double = thrift_binary_protocol_read_double;
|
||||
cls->read_string = thrift_binary_protocol_read_string;
|
||||
cls->read_binary = thrift_binary_protocol_read_binary;
|
||||
}
|
||||
72
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_binary_protocol.h
generated
vendored
Normal file
72
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_binary_protocol.h
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_BINARY_PROTOCOL_H
|
||||
#define _THRIFT_BINARY_PROTOCOL_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/protocol/thrift_protocol.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_binary_protocol.h
|
||||
* \brief Binary protocol implementation of a Thrift protocol. Implements the
|
||||
* ThriftProtocol interface.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_BINARY_PROTOCOL (thrift_binary_protocol_get_type ())
|
||||
#define THRIFT_BINARY_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_BINARY_PROTOCOL, ThriftBinaryProtocol))
|
||||
#define THRIFT_IS_BINARY_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_BINARY_PROTOCOL))
|
||||
#define THRIFT_BINARY_PROTOCOL_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_BINARY_PROTOCOL, ThriftBinaryProtocolClass))
|
||||
#define THRIFT_IS_BINARY_PROTOCOL_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_BINARY_PROTOCOL))
|
||||
#define THRIFT_BINARY_PROTOCOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_BINARY_PROTOCOL, ThriftBinaryProtocolClass))
|
||||
|
||||
/* version numbers */
|
||||
#define THRIFT_BINARY_PROTOCOL_VERSION_1 0x80010000
|
||||
#define THRIFT_BINARY_PROTOCOL_VERSION_MASK 0xffff0000
|
||||
|
||||
typedef struct _ThriftBinaryProtocol ThriftBinaryProtocol;
|
||||
|
||||
/*!
|
||||
* Thrift Binary Protocol instance.
|
||||
*/
|
||||
struct _ThriftBinaryProtocol
|
||||
{
|
||||
ThriftProtocol parent;
|
||||
};
|
||||
|
||||
typedef struct _ThriftBinaryProtocolClass ThriftBinaryProtocolClass;
|
||||
|
||||
/*!
|
||||
* Thrift Binary Protocol class.
|
||||
*/
|
||||
struct _ThriftBinaryProtocolClass
|
||||
{
|
||||
ThriftProtocolClass parent;
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_BINARY_PROTOCOL */
|
||||
GType thrift_binary_protocol_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_BINARY_PROTOCOL_H */
|
||||
50
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_binary_protocol_factory.c
generated
vendored
Normal file
50
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_binary_protocol_factory.c
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/protocol/thrift_binary_protocol.h>
|
||||
#include <thrift/c_glib/protocol/thrift_binary_protocol_factory.h>
|
||||
|
||||
G_DEFINE_TYPE(ThriftBinaryProtocolFactory, thrift_binary_protocol_factory, THRIFT_TYPE_PROTOCOL_FACTORY)
|
||||
|
||||
ThriftProtocol *
|
||||
thrift_binary_protocol_factory_get_protocol (ThriftProtocolFactory *factory,
|
||||
ThriftTransport *transport)
|
||||
{
|
||||
ThriftBinaryProtocol *tb = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL,
|
||||
"transport", transport, NULL);
|
||||
|
||||
THRIFT_UNUSED_VAR (factory);
|
||||
|
||||
return THRIFT_PROTOCOL (tb);
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_binary_protocol_factory_class_init (ThriftBinaryProtocolFactoryClass *cls)
|
||||
{
|
||||
ThriftProtocolFactoryClass *protocol_factory_class = THRIFT_PROTOCOL_FACTORY_CLASS (cls);
|
||||
|
||||
protocol_factory_class->get_protocol = thrift_binary_protocol_factory_get_protocol;
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_binary_protocol_factory_init (ThriftBinaryProtocolFactory *factory)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (factory);
|
||||
}
|
||||
56
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_binary_protocol_factory.h
generated
vendored
Normal file
56
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_binary_protocol_factory.h
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_BINARY_PROTOCOL_FACTORY_H
|
||||
#define _THRIFT_BINARY_PROTOCOL_FACTORY_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/protocol/thrift_protocol_factory.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_BINARY_PROTOCOL_FACTORY (thrift_binary_protocol_factory_get_type ())
|
||||
#define THRIFT_BINARY_PROTOCOL_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_BINARY_PROTOCOL_FACTORY, ThriftBinaryProtocolFactory))
|
||||
#define THRIFT_IS_BINARY_PROTOCOL_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_BINARY_PROTOCOL_FACTORY))
|
||||
#define THRIFT_BINARY_PROTOCOL_FACTORY_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_BINARY_PROTOCOL_FACTORY, ThriftBinaryProtocolFactoryClass))
|
||||
#define THRIFT_IS_BINARY_PROTOCOL_FACTORY_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_BINARY_PROTOCOL_FACTORY))
|
||||
#define THRIFT_BINARY_PROTOCOL_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_BINARY_PROTOCOL_FACTORY, ThriftBinaryProtocolFactoryClass))
|
||||
|
||||
typedef struct _ThriftBinaryProtocolFactory ThriftBinaryProtocolFactory;
|
||||
|
||||
struct _ThriftBinaryProtocolFactory
|
||||
{
|
||||
ThriftProtocolFactory parent;
|
||||
};
|
||||
|
||||
typedef struct _ThriftBinaryProtocolFactoryClass ThriftBinaryProtocolFactoryClass;
|
||||
|
||||
struct _ThriftBinaryProtocolFactoryClass
|
||||
{
|
||||
ThriftProtocolFactoryClass parent;
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_BINARY_PROTOCOL_FACTORY */
|
||||
GType thrift_binary_protocol_factory_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_BINARY_PROTOCOL_FACTORY_H */
|
||||
1609
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_compact_protocol.c
generated
vendored
Normal file
1609
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_compact_protocol.c
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
107
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_compact_protocol.h
generated
vendored
Normal file
107
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_compact_protocol.h
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_COMPACT_PROTOCOL_H
|
||||
#define _THRIFT_COMPACT_PROTOCOL_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/protocol/thrift_protocol.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_compact_protocol.h
|
||||
* \brief Compact protocol implementation of a Thrift protocol. Implements the
|
||||
* ThriftProtocol interface.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_COMPACT_PROTOCOL (thrift_compact_protocol_get_type ())
|
||||
#define THRIFT_COMPACT_PROTOCOL(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_COMPACT_PROTOCOL, \
|
||||
ThriftCompactProtocol))
|
||||
#define THRIFT_IS_COMPACT_PROTOCOL(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_COMPACT_PROTOCOL))
|
||||
#define THRIFT_COMPACT_PROTOCOL_CLASS(c) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_COMPACT_PROTOCOL, \
|
||||
ThriftCompactProtocolClass))
|
||||
#define THRIFT_IS_COMPACT_PROTOCOL_CLASS(c) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_COMPACT_PROTOCOL))
|
||||
#define THRIFT_COMPACT_PROTOCOL_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_COMPACT_PROTOCOL, \
|
||||
ThriftCompactProtocolClass))
|
||||
|
||||
|
||||
typedef struct _ThriftCompactProtocol ThriftCompactProtocol;
|
||||
|
||||
/*!
|
||||
* Thrift Compact Protocol instance.
|
||||
*/
|
||||
struct _ThriftCompactProtocol
|
||||
{
|
||||
ThriftProtocol parent;
|
||||
|
||||
/* protected */
|
||||
gint32 string_limit;
|
||||
gint32 container_limit;
|
||||
|
||||
/* private */
|
||||
|
||||
/**
|
||||
* (Writing) If we encounter a boolean field begin, save the TField here
|
||||
* so it can have the value incorporated.
|
||||
*/
|
||||
const gchar* _bool_field_name;
|
||||
ThriftType _bool_field_type;
|
||||
gint16 _bool_field_id;
|
||||
|
||||
/**
|
||||
* (Reading) If we read a field header, and it's a boolean field, save
|
||||
* the boolean value here so that read_bool can use it.
|
||||
*/
|
||||
gboolean _has_bool_value;
|
||||
gboolean _bool_value;
|
||||
|
||||
/**
|
||||
* Used to keep track of the last field for the current and previous structs,
|
||||
* so we can do the delta stuff.
|
||||
*/
|
||||
|
||||
GQueue _last_field;
|
||||
gint16 _last_field_id;
|
||||
};
|
||||
|
||||
typedef struct _ThriftCompactProtocolClass ThriftCompactProtocolClass;
|
||||
|
||||
/*!
|
||||
* Thrift Compact Protocol class.
|
||||
*/
|
||||
struct _ThriftCompactProtocolClass
|
||||
{
|
||||
ThriftProtocolClass parent;
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_COMPACT_PROTOCOL */
|
||||
GType thrift_compact_protocol_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_COMPACT_PROTOCOL_H */
|
||||
140
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_compact_protocol_factory.c
generated
vendored
Normal file
140
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_compact_protocol_factory.c
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/protocol/thrift_compact_protocol.h>
|
||||
#include <thrift/c_glib/protocol/thrift_compact_protocol_factory.h>
|
||||
|
||||
/* object properties */
|
||||
enum _ThriftCompactProtocolFactoryProperties
|
||||
{
|
||||
PROP_0,
|
||||
PROP_THRIFT_COMPACT_PROTOCOL_FACTORY_STRING_LIMIT,
|
||||
PROP_THRIFT_COMPACT_PROTOCOL_FACTORY_CONTAINER_LIMIT
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (ThriftCompactProtocolFactory, thrift_compact_protocol_factory,
|
||||
THRIFT_TYPE_PROTOCOL_FACTORY)
|
||||
|
||||
ThriftProtocol *
|
||||
thrift_compact_protocol_factory_get_protocol (ThriftProtocolFactory *factory,
|
||||
ThriftTransport *transport)
|
||||
{
|
||||
ThriftCompactProtocolFactory *tcf;
|
||||
ThriftCompactProtocol *tc;
|
||||
|
||||
tcf = THRIFT_COMPACT_PROTOCOL_FACTORY (factory);
|
||||
|
||||
tc = g_object_new (THRIFT_TYPE_COMPACT_PROTOCOL,
|
||||
"transport", transport,
|
||||
"string_limit", tcf->string_limit,
|
||||
"container_limit", tcf->container_limit,
|
||||
NULL);
|
||||
|
||||
return THRIFT_PROTOCOL (tc);
|
||||
}
|
||||
|
||||
/* property accessor */
|
||||
void
|
||||
thrift_compact_protocol_factory_get_property (GObject *object, guint property_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftCompactProtocolFactory *tcf;
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
tcf = THRIFT_COMPACT_PROTOCOL_FACTORY (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_THRIFT_COMPACT_PROTOCOL_FACTORY_STRING_LIMIT:
|
||||
g_value_set_int (value, tcf->string_limit);
|
||||
break;
|
||||
case PROP_THRIFT_COMPACT_PROTOCOL_FACTORY_CONTAINER_LIMIT:
|
||||
g_value_set_int (value, tcf->container_limit);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* property mutator */
|
||||
void
|
||||
thrift_compact_protocol_factory_set_property (GObject *object, guint property_id,
|
||||
const GValue *value, GParamSpec
|
||||
*pspec)
|
||||
{
|
||||
ThriftCompactProtocolFactory *tcf;
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
tcf = THRIFT_COMPACT_PROTOCOL_FACTORY (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_THRIFT_COMPACT_PROTOCOL_FACTORY_STRING_LIMIT:
|
||||
tcf->string_limit = g_value_get_int (value);
|
||||
break;
|
||||
case PROP_THRIFT_COMPACT_PROTOCOL_FACTORY_CONTAINER_LIMIT:
|
||||
tcf->container_limit = g_value_get_int (value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_compact_protocol_factory_class_init (ThriftCompactProtocolFactoryClass
|
||||
*klass)
|
||||
{
|
||||
ThriftProtocolFactoryClass *cls;
|
||||
GObjectClass *gobject_class;
|
||||
GParamSpec *param_spec;
|
||||
|
||||
cls = THRIFT_PROTOCOL_FACTORY_CLASS (klass);
|
||||
gobject_class = G_OBJECT_CLASS (klass);
|
||||
param_spec = NULL;
|
||||
|
||||
/* setup accessors and mutators */
|
||||
gobject_class->get_property = thrift_compact_protocol_factory_get_property;
|
||||
gobject_class->set_property = thrift_compact_protocol_factory_set_property;
|
||||
|
||||
param_spec = g_param_spec_int ("string_limit",
|
||||
"Max allowed string size",
|
||||
"Set the max string limit",
|
||||
0, /* min */
|
||||
G_MAXINT32, /* max */
|
||||
0, /* default value */
|
||||
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_COMPACT_PROTOCOL_FACTORY_STRING_LIMIT,
|
||||
param_spec);
|
||||
|
||||
param_spec = g_param_spec_int ("container_limit",
|
||||
"Max allowed container size",
|
||||
"Set the max container limit",
|
||||
0, /* min */
|
||||
G_MAXINT32, /* max */
|
||||
0, /* default value */
|
||||
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_COMPACT_PROTOCOL_FACTORY_CONTAINER_LIMIT, param_spec);
|
||||
|
||||
cls->get_protocol = thrift_compact_protocol_factory_get_protocol;
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_compact_protocol_factory_init (ThriftCompactProtocolFactory *factory)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (factory);
|
||||
}
|
||||
70
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_compact_protocol_factory.h
generated
vendored
Normal file
70
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_compact_protocol_factory.h
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_COMPACT_PROTOCOL_FACTORY_H
|
||||
#define _THRIFT_COMPACT_PROTOCOL_FACTORY_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/protocol/thrift_protocol_factory.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_COMPACT_PROTOCOL_FACTORY \
|
||||
(thrift_compact_protocol_factory_get_type ())
|
||||
#define THRIFT_COMPACT_PROTOCOL_FACTORY(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_COMPACT_PROTOCOL_FACTORY, \
|
||||
ThriftCompactProtocolFactory))
|
||||
#define THRIFT_IS_COMPACT_PROTOCOL_FACTORY(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_COMPACT_PROTOCOL_FACTORY))
|
||||
#define THRIFT_COMPACT_PROTOCOL_FACTORY_CLASS(c) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_COMPACT_PROTOCOL_FACTORY, \
|
||||
ThriftCompactProtocolFactoryClass))
|
||||
#define THRIFT_IS_COMPACT_PROTOCOL_FACTORY_CLASS(c) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_COMPACT_PROTOCOL_FACTORY))
|
||||
#define THRIFT_COMPACT_PROTOCOL_FACTORY_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_COMPACT_PROTOCOL_FACTORY, \
|
||||
ThriftCompactProtocolFactoryClass))
|
||||
|
||||
typedef struct _ThriftCompactProtocolFactory ThriftCompactProtocolFactory;
|
||||
|
||||
struct _ThriftCompactProtocolFactory
|
||||
{
|
||||
ThriftProtocolFactory parent;
|
||||
|
||||
/* protected */
|
||||
gint32 string_limit;
|
||||
gint32 container_limit;
|
||||
};
|
||||
|
||||
typedef struct _ThriftCompactProtocolFactoryClass
|
||||
ThriftCompactProtocolFactoryClass;
|
||||
|
||||
struct _ThriftCompactProtocolFactoryClass
|
||||
{
|
||||
ThriftProtocolFactoryClass parent;
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_COMPACT_PROTOCOL_FACTORY */
|
||||
GType thrift_compact_protocol_factory_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_COMPACT_PROTOCOL_FACTORY_H */
|
||||
159
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_multiplexed_protocol.c
generated
vendored
Normal file
159
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_multiplexed_protocol.c
generated
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/protocol/thrift_protocol.h>
|
||||
#include <thrift/c_glib/protocol/thrift_protocol_decorator.h>
|
||||
#include <thrift/c_glib/protocol/thrift_multiplexed_protocol.h>
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_THRIFT_MULTIPLEXED_PROTOCOL_SERVICE_NAME = 1,
|
||||
PROP_THRIFT_MULTIPLEXED_PROTOCOL_END
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ThriftMultiplexedProtocol, thrift_multiplexed_protocol, THRIFT_TYPE_PROTOCOL_DECORATOR)
|
||||
|
||||
|
||||
static GParamSpec *thrift_multiplexed_protocol_obj_properties[PROP_THRIFT_MULTIPLEXED_PROTOCOL_END] = { NULL, };
|
||||
|
||||
gint32
|
||||
thrift_multiplexed_protocol_write_message_begin (ThriftMultiplexedProtocol *protocol,
|
||||
const gchar *name, const ThriftMessageType message_type,
|
||||
const gint32 seqid, GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
gchar *service_name = NULL;
|
||||
g_return_val_if_fail (THRIFT_IS_MULTIPLEXED_PROTOCOL (protocol), -1);
|
||||
|
||||
ThriftMultiplexedProtocol *self = THRIFT_MULTIPLEXED_PROTOCOL (protocol);
|
||||
ThriftMultiplexedProtocolClass *multiplexClass = THRIFT_MULTIPLEXED_PROTOCOL_GET_CLASS(self);
|
||||
ThriftProtocolClass *cls = THRIFT_PROTOCOL_CLASS (multiplexClass);
|
||||
|
||||
if( (message_type == T_CALL || message_type == T_ONEWAY) && self->service_name != NULL) {
|
||||
service_name = g_strdup_printf("%s%s%s", self->service_name, THRIFT_MULTIPLEXED_PROTOCOL_DEFAULT_SEPARATOR, name);
|
||||
}else{
|
||||
service_name = g_strdup(name);
|
||||
}
|
||||
|
||||
// relay to the protocol_decorator
|
||||
ret = thrift_protocol_decorator_write_message_begin(protocol, service_name, message_type, seqid, error);
|
||||
|
||||
g_free(service_name);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
thrift_multiplexed_protocol_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
ThriftMultiplexedProtocol *self = THRIFT_MULTIPLEXED_PROTOCOL (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_MULTIPLEXED_PROTOCOL_SERVICE_NAME:
|
||||
self->service_name = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* We don't have any other property... */
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_multiplexed_protocol_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
ThriftMultiplexedProtocol *self = THRIFT_MULTIPLEXED_PROTOCOL (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_MULTIPLEXED_PROTOCOL_SERVICE_NAME:
|
||||
g_value_set_string (value, self->service_name);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* We don't have any other property... */
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
thrift_multiplexed_protocol_init (ThriftMultiplexedProtocol *protocol)
|
||||
{
|
||||
protocol->service_name = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_multiplexed_protocol_finalize (GObject *gobject)
|
||||
{
|
||||
ThriftMultiplexedProtocol *self = THRIFT_MULTIPLEXED_PROTOCOL (gobject);
|
||||
|
||||
if (self->service_name) {
|
||||
g_free(self->service_name);
|
||||
self->service_name = NULL;
|
||||
}
|
||||
|
||||
/* Always chain up to the parent class; as with dispose(), finalize()
|
||||
* is guaranteed to exist on the parent's class virtual function table
|
||||
*/
|
||||
G_OBJECT_CLASS (thrift_multiplexed_protocol_parent_class)->finalize(gobject);
|
||||
}
|
||||
|
||||
|
||||
/* initialize the class */
|
||||
static void
|
||||
thrift_multiplexed_protocol_class_init (ThriftMultiplexedProtocolClass *klass)
|
||||
{
|
||||
ThriftProtocolClass *cls = THRIFT_PROTOCOL_CLASS (klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
cls->write_message_begin = thrift_multiplexed_protocol_write_message_begin;
|
||||
|
||||
object_class->set_property = thrift_multiplexed_protocol_set_property;
|
||||
object_class->get_property = thrift_multiplexed_protocol_get_property;
|
||||
object_class->finalize = thrift_multiplexed_protocol_finalize;
|
||||
|
||||
thrift_multiplexed_protocol_obj_properties[PROP_THRIFT_MULTIPLEXED_PROTOCOL_SERVICE_NAME] =
|
||||
g_param_spec_string ("service-name",
|
||||
"Service name the protocol points to",
|
||||
"Set the service name",
|
||||
NULL,
|
||||
(G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_properties (object_class,
|
||||
PROP_THRIFT_MULTIPLEXED_PROTOCOL_END,
|
||||
thrift_multiplexed_protocol_obj_properties);
|
||||
}
|
||||
76
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_multiplexed_protocol.h
generated
vendored
Normal file
76
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_multiplexed_protocol.h
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_MULTIPLEXED_PROTOCOL_H
|
||||
#define _THRIFT_MULTIPLEXED_PROTOCOL_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/protocol/thrift_protocol.h>
|
||||
#include <thrift/c_glib/protocol/thrift_protocol_decorator.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_multiplexed_protocol.h
|
||||
* \brief Multiplexed protocol implementation of a Thrift protocol. Implements the
|
||||
* ThriftProtocol interface.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_MULTIPLEXED_PROTOCOL (thrift_multiplexed_protocol_get_type ())
|
||||
#define THRIFT_MULTIPLEXED_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_MULTIPLEXED_PROTOCOL, ThriftMultiplexedProtocol))
|
||||
#define THRIFT_IS_MULTIPLEXED_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_MULTIPLEXED_PROTOCOL))
|
||||
#define THRIFT_MULTIPLEXED_PROTOCOL_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_MULTIPLEXED_PROTOCOL, ThriftMultiplexedProtocolClass))
|
||||
#define THRIFT_IS_MULTIPLEXED_PROTOCOL_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_MULTIPLEXED_PROTOCOL))
|
||||
#define THRIFT_MULTIPLEXED_PROTOCOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_MULTIPLEXED_PROTOCOL, ThriftMultiplexedProtocolClass))
|
||||
|
||||
/* constant */
|
||||
#define THRIFT_MULTIPLEXED_PROTOCOL_DEFAULT_SEPARATOR ":"
|
||||
|
||||
typedef struct _ThriftMultiplexedProtocol ThriftMultiplexedProtocol;
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* Thrift Multiplexed Protocol instance.
|
||||
*/
|
||||
struct _ThriftMultiplexedProtocol
|
||||
{
|
||||
ThriftProtocolDecorator parent;
|
||||
|
||||
gchar *service_name;
|
||||
};
|
||||
|
||||
typedef struct _ThriftMultiplexedProtocolClass ThriftMultiplexedProtocolClass;
|
||||
|
||||
/*!
|
||||
* Thrift Multiplexed Protocol class.
|
||||
*/
|
||||
struct _ThriftMultiplexedProtocolClass
|
||||
{
|
||||
ThriftProtocolDecoratorClass parent;
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_MULTIPLEXED_PROTOCOL */
|
||||
GType thrift_multiplexed_protocol_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_MULTIPLEXED_PROTOCOL_H */
|
||||
620
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol.c
generated
vendored
Normal file
620
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol.c
generated
vendored
Normal file
@@ -0,0 +1,620 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/protocol/thrift_protocol.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
|
||||
/* define the GError domain string */
|
||||
#define THRIFT_PROTOCOL_ERROR_DOMAIN "thrift-protocol-error-quark"
|
||||
|
||||
/* object properties */
|
||||
enum _ThriftProtocolProperties
|
||||
{
|
||||
PROP_0,
|
||||
PROP_THRIFT_PROTOCOL_TRANSPORT
|
||||
};
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE(ThriftProtocol, thrift_protocol, G_TYPE_OBJECT)
|
||||
|
||||
void
|
||||
thrift_protocol_get_property (GObject *object, guint property_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftProtocol *protocol = THRIFT_PROTOCOL (object);
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_PROTOCOL_TRANSPORT:
|
||||
g_value_set_object (value, protocol->transport);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
thrift_protocol_set_property (GObject *object, guint property_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
|
||||
ThriftProtocol *protocol = THRIFT_PROTOCOL (object);
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_PROTOCOL_TRANSPORT:
|
||||
protocol->transport = g_value_dup_object (value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_message_begin (ThriftProtocol *protocol,
|
||||
const gchar *name,
|
||||
const ThriftMessageType message_type,
|
||||
const gint32 seqid, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_message_begin
|
||||
(protocol, name,
|
||||
message_type, seqid,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_message_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_message_end (protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_struct_begin (ThriftProtocol *protocol, const gchar *name,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_struct_begin (protocol,
|
||||
name, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_struct_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_struct_end (protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_field_begin (ThriftProtocol *protocol,
|
||||
const gchar *name,
|
||||
const ThriftType field_type,
|
||||
const gint16 field_id,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_field_begin (protocol,
|
||||
name, field_type,
|
||||
field_id, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_field_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_field_end (protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_field_stop (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_field_stop (protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_map_begin (ThriftProtocol *protocol,
|
||||
const ThriftType key_type,
|
||||
const ThriftType value_type,
|
||||
const guint32 size, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_map_begin (protocol,
|
||||
key_type, value_type,
|
||||
size, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_map_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_map_end (protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_list_begin (ThriftProtocol *protocol,
|
||||
const ThriftType element_type,
|
||||
const guint32 size, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_list_begin (protocol,
|
||||
element_type, size,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_list_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_list_end (protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_set_begin (ThriftProtocol *protocol,
|
||||
const ThriftType element_type,
|
||||
const guint32 size, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_set_begin (protocol,
|
||||
element_type, size,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_set_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_set_end (protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_bool (ThriftProtocol *protocol,
|
||||
const gboolean value, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_bool (protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_byte (ThriftProtocol *protocol, const gint8 value,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_byte (protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_i16 (ThriftProtocol *protocol, const gint16 value,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_i16 (protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_i32 (ThriftProtocol *protocol, const gint32 value,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_i32 (protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_i64 (ThriftProtocol *protocol, const gint64 value,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_i64 (protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_double (ThriftProtocol *protocol,
|
||||
const gdouble value, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_double (protocol,
|
||||
value, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_string (ThriftProtocol *protocol,
|
||||
const gchar *str, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_string (protocol, str,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_write_binary (ThriftProtocol *protocol, const gpointer buf,
|
||||
const guint32 len, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_binary (protocol, buf,
|
||||
len, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_message_begin (ThriftProtocol *protocol,
|
||||
gchar **name,
|
||||
ThriftMessageType *message_type,
|
||||
gint32 *seqid, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_message_begin (protocol,
|
||||
name, message_type,
|
||||
seqid, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_message_end (ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_message_end (protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_struct_begin (ThriftProtocol *protocol,
|
||||
gchar **name,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_struct_begin (protocol,
|
||||
name,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_struct_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_struct_end (protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_field_begin (ThriftProtocol *protocol,
|
||||
gchar **name,
|
||||
ThriftType *field_type,
|
||||
gint16 *field_id,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_field_begin (protocol,
|
||||
name,
|
||||
field_type,
|
||||
field_id,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_field_end (ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_field_end (protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_map_begin (ThriftProtocol *protocol,
|
||||
ThriftType *key_type,
|
||||
ThriftType *value_type, guint32 *size,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_map_begin (protocol,
|
||||
key_type,
|
||||
value_type,
|
||||
size,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_map_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_map_end (protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_list_begin (ThriftProtocol *protocol,
|
||||
ThriftType *element_type,
|
||||
guint32 *size, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_list_begin (protocol,
|
||||
element_type,
|
||||
size, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_list_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_list_end (protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_set_begin (ThriftProtocol *protocol,
|
||||
ThriftType *element_type,
|
||||
guint32 *size, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_set_begin (protocol,
|
||||
element_type,
|
||||
size, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_set_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_set_end (protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_bool (ThriftProtocol *protocol, gboolean *value,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_bool (protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_byte (ThriftProtocol *protocol, gint8 *value,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_byte (protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_i16 (ThriftProtocol *protocol, gint16 *value,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_i16 (protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_i32 (ThriftProtocol *protocol, gint32 *value,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_i32 (protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_i64 (ThriftProtocol *protocol, gint64 *value,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_i64 (protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_double (ThriftProtocol *protocol,
|
||||
gdouble *value, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_double (protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_string (ThriftProtocol *protocol,
|
||||
gchar **str, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_string (protocol, str,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_read_binary (ThriftProtocol *protocol, gpointer *buf,
|
||||
guint32 *len, GError **error)
|
||||
{
|
||||
return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_binary (protocol, buf,
|
||||
len, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_skip (ThriftProtocol *protocol, ThriftType type, GError **error)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case T_BOOL:
|
||||
{
|
||||
gboolean boolv;
|
||||
return thrift_protocol_read_bool (protocol, &boolv, error);
|
||||
}
|
||||
case T_BYTE:
|
||||
{
|
||||
gint8 bytev;
|
||||
return thrift_protocol_read_byte (protocol, &bytev, error);
|
||||
}
|
||||
|
||||
case T_I16:
|
||||
{
|
||||
gint16 i16;
|
||||
return thrift_protocol_read_i16 (protocol, &i16, error);
|
||||
}
|
||||
case T_I32:
|
||||
{
|
||||
gint32 i32;
|
||||
return thrift_protocol_read_i32 (protocol, &i32, error);
|
||||
}
|
||||
case T_I64:
|
||||
{
|
||||
gint64 i64;
|
||||
return thrift_protocol_read_i64 (protocol, &i64, error);
|
||||
}
|
||||
case T_DOUBLE:
|
||||
{
|
||||
gdouble dub;
|
||||
return thrift_protocol_read_double (protocol, &dub, error);
|
||||
}
|
||||
case T_STRING:
|
||||
{
|
||||
gpointer data;
|
||||
guint32 len;
|
||||
gint32 ret = thrift_protocol_read_binary (protocol, &data, &len, error);
|
||||
g_free (data);
|
||||
return ret;
|
||||
}
|
||||
case T_STRUCT:
|
||||
{
|
||||
guint32 result = 0;
|
||||
gchar *name;
|
||||
gint16 fid;
|
||||
ThriftType ftype;
|
||||
result += thrift_protocol_read_struct_begin (protocol, &name, error);
|
||||
|
||||
while (1)
|
||||
{
|
||||
result += thrift_protocol_read_field_begin (protocol, &name, &ftype,
|
||||
&fid, error);
|
||||
if (ftype == T_STOP)
|
||||
{
|
||||
break;
|
||||
}
|
||||
result += thrift_protocol_skip (protocol, ftype, error);
|
||||
result += thrift_protocol_read_field_end (protocol, error);
|
||||
}
|
||||
result += thrift_protocol_read_struct_end (protocol, error);
|
||||
return result;
|
||||
}
|
||||
case T_SET:
|
||||
{
|
||||
guint32 result = 0;
|
||||
ThriftType elem_type;
|
||||
guint32 i, size;
|
||||
result += thrift_protocol_read_set_begin (protocol, &elem_type, &size,
|
||||
error);
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
result += thrift_protocol_skip (protocol, elem_type, error);
|
||||
}
|
||||
result += thrift_protocol_read_set_end (protocol, error);
|
||||
return result;
|
||||
}
|
||||
case T_MAP:
|
||||
{
|
||||
guint32 result = 0;
|
||||
ThriftType elem_type;
|
||||
ThriftType key_type;
|
||||
guint32 i, size;
|
||||
result += thrift_protocol_read_map_begin (protocol, &key_type, &elem_type, &size,
|
||||
error);
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
result += thrift_protocol_skip (protocol, key_type, error);
|
||||
result += thrift_protocol_skip (protocol, elem_type, error);
|
||||
}
|
||||
result += thrift_protocol_read_map_end (protocol, error);
|
||||
return result;
|
||||
}
|
||||
case T_LIST:
|
||||
{
|
||||
guint32 result = 0;
|
||||
ThriftType elem_type;
|
||||
guint32 i, size;
|
||||
result += thrift_protocol_read_list_begin (protocol, &elem_type, &size,
|
||||
error);
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
result += thrift_protocol_skip (protocol, elem_type, error);
|
||||
}
|
||||
result += thrift_protocol_read_list_end (protocol, error);
|
||||
return result;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* define the GError domain for Thrift protocols */
|
||||
GQuark
|
||||
thrift_protocol_error_quark (void)
|
||||
{
|
||||
return g_quark_from_static_string (THRIFT_PROTOCOL_ERROR_DOMAIN);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
thrift_protocol_init (ThriftProtocol *protocol)
|
||||
{
|
||||
protocol->transport = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_protocol_dispose (GObject *gobject)
|
||||
{
|
||||
ThriftProtocol *self = THRIFT_PROTOCOL (gobject);
|
||||
|
||||
g_clear_object(&self->transport);
|
||||
|
||||
/* Always chain up to the parent class; there is no need to check if
|
||||
* the parent class implements the dispose() virtual function: it is
|
||||
* always guaranteed to do so
|
||||
*/
|
||||
G_OBJECT_CLASS (thrift_protocol_parent_class)->dispose(gobject);
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_protocol_class_init (ThriftProtocolClass *cls)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
|
||||
|
||||
gobject_class->get_property = thrift_protocol_get_property;
|
||||
gobject_class->set_property = thrift_protocol_set_property;
|
||||
gobject_class->dispose = thrift_protocol_dispose;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_PROTOCOL_TRANSPORT,
|
||||
g_param_spec_object ("transport", "Transport", "Thrift Transport",
|
||||
THRIFT_TYPE_TRANSPORT,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
cls->write_message_begin = thrift_protocol_write_message_begin;
|
||||
cls->write_message_end = thrift_protocol_write_message_end;
|
||||
cls->write_struct_begin = thrift_protocol_write_struct_begin;
|
||||
cls->write_struct_end = thrift_protocol_write_struct_end;
|
||||
cls->write_field_begin = thrift_protocol_write_field_begin;
|
||||
cls->write_field_end = thrift_protocol_write_field_end;
|
||||
cls->write_field_stop = thrift_protocol_write_field_stop;
|
||||
cls->write_map_begin = thrift_protocol_write_map_begin;
|
||||
cls->write_map_end = thrift_protocol_write_map_end;
|
||||
cls->write_list_begin = thrift_protocol_write_list_begin;
|
||||
cls->write_list_end = thrift_protocol_write_list_end;
|
||||
cls->write_set_begin = thrift_protocol_write_set_begin;
|
||||
cls->write_set_end = thrift_protocol_write_set_end;
|
||||
cls->write_bool = thrift_protocol_write_bool;
|
||||
cls->write_byte = thrift_protocol_write_byte;
|
||||
cls->write_i16 = thrift_protocol_write_i16;
|
||||
cls->write_i32 = thrift_protocol_write_i32;
|
||||
cls->write_i64 = thrift_protocol_write_i64;
|
||||
cls->write_double = thrift_protocol_write_double;
|
||||
cls->write_string = thrift_protocol_write_string;
|
||||
cls->write_binary = thrift_protocol_write_binary;
|
||||
cls->read_message_begin = thrift_protocol_read_message_begin;
|
||||
cls->read_message_end = thrift_protocol_read_message_end;
|
||||
cls->read_struct_begin = thrift_protocol_read_struct_begin;
|
||||
cls->read_struct_end = thrift_protocol_read_struct_end;
|
||||
cls->read_field_begin = thrift_protocol_read_field_begin;
|
||||
cls->read_field_end = thrift_protocol_read_field_end;
|
||||
cls->read_map_begin = thrift_protocol_read_map_begin;
|
||||
cls->read_map_end = thrift_protocol_read_map_end;
|
||||
cls->read_list_begin = thrift_protocol_read_list_begin;
|
||||
cls->read_set_begin = thrift_protocol_read_set_begin;
|
||||
cls->read_set_end = thrift_protocol_read_set_end;
|
||||
cls->read_bool = thrift_protocol_read_bool;
|
||||
cls->read_byte = thrift_protocol_read_byte;
|
||||
cls->read_i16 = thrift_protocol_read_i16;
|
||||
cls->read_i32 = thrift_protocol_read_i32;
|
||||
cls->read_i64 = thrift_protocol_read_i64;
|
||||
cls->read_double = thrift_protocol_read_double;
|
||||
cls->read_string = thrift_protocol_read_string;
|
||||
cls->read_binary = thrift_protocol_read_binary;
|
||||
}
|
||||
341
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol.h
generated
vendored
Normal file
341
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol.h
generated
vendored
Normal file
@@ -0,0 +1,341 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_PROTOCOL_H
|
||||
#define _THRIFT_PROTOCOL_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_protocol.h
|
||||
* \brief Abstract class for Thrift protocol implementations.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Enumerated definition of the types that the Thrift protocol supports.
|
||||
* Take special note of the T_END type which is used specifically to mark
|
||||
* the end of a sequence of fields.
|
||||
*/
|
||||
typedef enum {
|
||||
T_STOP = 0,
|
||||
T_VOID = 1,
|
||||
T_BOOL = 2,
|
||||
T_BYTE = 3,
|
||||
T_I08 = 3,
|
||||
T_I16 = 6,
|
||||
T_I32 = 8,
|
||||
T_U64 = 9,
|
||||
T_I64 = 10,
|
||||
T_DOUBLE = 4,
|
||||
T_STRING = 11,
|
||||
T_UTF7 = 11,
|
||||
T_STRUCT = 12,
|
||||
T_MAP = 13,
|
||||
T_SET = 14,
|
||||
T_LIST = 15,
|
||||
T_UTF8 = 16,
|
||||
T_UTF16 = 17
|
||||
} ThriftType;
|
||||
|
||||
/**
|
||||
* Enumerated definition of the message types that the Thrift protocol
|
||||
* supports.
|
||||
*/
|
||||
typedef enum {
|
||||
T_CALL = 1,
|
||||
T_REPLY = 2,
|
||||
T_EXCEPTION = 3,
|
||||
T_ONEWAY = 4
|
||||
} ThriftMessageType;
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_PROTOCOL (thrift_protocol_get_type ())
|
||||
#define THRIFT_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_PROTOCOL, ThriftProtocol))
|
||||
#define THRIFT_IS_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_PROTOCOL))
|
||||
#define THRIFT_PROTOCOL_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_PROTOCOL, ThriftProtocolClass))
|
||||
#define THRIFT_IS_PROTOCOL_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_PROTOCOL))
|
||||
#define THRIFT_PROTOCOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_PROTOCOL, ThriftProtocolClass))
|
||||
|
||||
typedef struct _ThriftProtocol ThriftProtocol;
|
||||
|
||||
/*!
|
||||
* Thrift Protocol object
|
||||
*/
|
||||
struct _ThriftProtocol
|
||||
{
|
||||
GObject parent;
|
||||
|
||||
/* protected */
|
||||
ThriftTransport *transport;
|
||||
};
|
||||
|
||||
typedef struct _ThriftProtocolClass ThriftProtocolClass;
|
||||
|
||||
/*!
|
||||
* Thrift Protocol class
|
||||
*/
|
||||
struct _ThriftProtocolClass
|
||||
{
|
||||
GObjectClass parent;
|
||||
|
||||
gint32 (*write_message_begin) (ThriftProtocol *protocol, const gchar *name,
|
||||
const ThriftMessageType message_type,
|
||||
const gint32 seqid, GError **error);
|
||||
gint32 (*write_message_end) (ThriftProtocol *protocol, GError **error);
|
||||
gint32 (*write_struct_begin) (ThriftProtocol *protocol, const gchar *name,
|
||||
GError **error);
|
||||
gint32 (*write_struct_end) (ThriftProtocol *protocol, GError **error);
|
||||
gint32 (*write_field_begin) (ThriftProtocol *protocol, const gchar *name,
|
||||
const ThriftType field_type,
|
||||
const gint16 field_id, GError **error);
|
||||
gint32 (*write_field_end) (ThriftProtocol *protocol, GError **error);
|
||||
gint32 (*write_field_stop) (ThriftProtocol *protocol, GError **error);
|
||||
gint32 (*write_map_begin) (ThriftProtocol *protocol,
|
||||
const ThriftType key_type,
|
||||
const ThriftType value_type,
|
||||
const guint32 size, GError **error);
|
||||
gint32 (*write_map_end) (ThriftProtocol *protocol, GError **error);
|
||||
gint32 (*write_list_begin) (ThriftProtocol *protocol,
|
||||
const ThriftType element_type,
|
||||
const guint32 size, GError **error);
|
||||
gint32 (*write_list_end) (ThriftProtocol *protocol, GError **error);
|
||||
gint32 (*write_set_begin) (ThriftProtocol *protocol,
|
||||
const ThriftType element_type,
|
||||
const guint32 size, GError **error);
|
||||
gint32 (*write_set_end) (ThriftProtocol *protocol, GError **error);
|
||||
gint32 (*write_bool) (ThriftProtocol *protocol, const gboolean value,
|
||||
GError **error);
|
||||
gint32 (*write_byte) (ThriftProtocol *protocol, const gint8 value,
|
||||
GError **error);
|
||||
gint32 (*write_i16) (ThriftProtocol *protocol, const gint16 value,
|
||||
GError **error);
|
||||
gint32 (*write_i32) (ThriftProtocol *protocol, const gint32 value,
|
||||
GError **error);
|
||||
gint32 (*write_i64) (ThriftProtocol *protocol, const gint64 value,
|
||||
GError **error);
|
||||
gint32 (*write_double) (ThriftProtocol *protocol, const gdouble value,
|
||||
GError **error);
|
||||
gint32 (*write_string) (ThriftProtocol *protocol, const gchar *str,
|
||||
GError **error);
|
||||
gint32 (*write_binary) (ThriftProtocol *protocol, const gpointer buf,
|
||||
const guint32 len, GError **error);
|
||||
|
||||
gint32 (*read_message_begin) (ThriftProtocol *thrift_protocol, gchar **name,
|
||||
ThriftMessageType *message_type,
|
||||
gint32 *seqid, GError **error);
|
||||
gint32 (*read_message_end) (ThriftProtocol *protocol, GError **error);
|
||||
gint32 (*read_struct_begin) (ThriftProtocol *protocol, gchar **name,
|
||||
GError **error);
|
||||
gint32 (*read_struct_end) (ThriftProtocol *protocol, GError **error);
|
||||
gint32 (*read_field_begin) (ThriftProtocol *protocol, gchar **name,
|
||||
ThriftType *field_type, gint16 *field_id,
|
||||
GError **error);
|
||||
gint32 (*read_field_end) (ThriftProtocol *protocol, GError **error);
|
||||
gint32 (*read_map_begin) (ThriftProtocol *protocol, ThriftType *key_type,
|
||||
ThriftType *value_type, guint32 *size,
|
||||
GError **error);
|
||||
gint32 (*read_map_end) (ThriftProtocol *protocol, GError **error);
|
||||
gint32 (*read_list_begin) (ThriftProtocol *protocol, ThriftType *element_type,
|
||||
guint32 *size, GError **error);
|
||||
gint32 (*read_list_end) (ThriftProtocol *protocol, GError **error);
|
||||
gint32 (*read_set_begin) (ThriftProtocol *protocol, ThriftType *element_type,
|
||||
guint32 *size, GError **error);
|
||||
gint32 (*read_set_end) (ThriftProtocol *protocol, GError **error);
|
||||
gint32 (*read_bool) (ThriftProtocol *protocol, gboolean *value,
|
||||
GError **error);
|
||||
gint32 (*read_byte) (ThriftProtocol *protocol, gint8 *value, GError **error);
|
||||
gint32 (*read_i16) (ThriftProtocol *protocol, gint16 *value, GError **error);
|
||||
gint32 (*read_i32) (ThriftProtocol *protocol, gint32 *value, GError **error);
|
||||
gint32 (*read_i64) (ThriftProtocol *protocol, gint64 *value, GError **error);
|
||||
gint32 (*read_double) (ThriftProtocol *protocol, gdouble *value,
|
||||
GError **error);
|
||||
gint32 (*read_string) (ThriftProtocol *protocol, gchar **str, GError **error);
|
||||
gint32 (*read_binary) (ThriftProtocol *protocol, gpointer *buf,
|
||||
guint32 *len, GError **error);
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_PROTOCOL */
|
||||
GType thrift_protocol_get_type (void);
|
||||
|
||||
/* virtual public methods */
|
||||
gint32 thrift_protocol_write_message_begin (ThriftProtocol *protocol,
|
||||
const gchar *name, const ThriftMessageType message_type,
|
||||
const gint32 seqid, GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_message_end (ThriftProtocol *protocol,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_struct_begin (ThriftProtocol *protocol,
|
||||
const gchar *name,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_struct_end (ThriftProtocol *protocol,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_field_begin (ThriftProtocol *protocol,
|
||||
const gchar *name,
|
||||
const ThriftType field_type,
|
||||
const gint16 field_id,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_field_end (ThriftProtocol *protocol,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_field_stop (ThriftProtocol *protocol,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_map_begin (ThriftProtocol *protocol,
|
||||
const ThriftType key_type,
|
||||
const ThriftType value_type,
|
||||
const guint32 size, GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_map_end (ThriftProtocol *protocol, GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_list_begin (ThriftProtocol *protocol,
|
||||
const ThriftType element_type,
|
||||
const guint32 size, GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_list_end (ThriftProtocol *protocol,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_set_begin (ThriftProtocol *protocol,
|
||||
const ThriftType element_type,
|
||||
const guint32 size, GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_set_end (ThriftProtocol *protocol,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_bool (ThriftProtocol *protocol,
|
||||
const gboolean value, GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_byte (ThriftProtocol *protocol, const gint8 value,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_i16 (ThriftProtocol *protocol, const gint16 value,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_i32 (ThriftProtocol *protocol, const gint32 value,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_i64 (ThriftProtocol *protocol, const gint64 value,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_double (ThriftProtocol *protocol,
|
||||
const gdouble value, GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_string (ThriftProtocol *protocol,
|
||||
const gchar *str, GError **error);
|
||||
|
||||
gint32 thrift_protocol_write_binary (ThriftProtocol *protocol,
|
||||
const gpointer buf,
|
||||
const guint32 len, GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_message_begin (ThriftProtocol *thrift_protocol,
|
||||
gchar **name,
|
||||
ThriftMessageType *message_type,
|
||||
gint32 *seqid, GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_message_end (ThriftProtocol *protocol,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_struct_begin (ThriftProtocol *protocol,
|
||||
gchar **name,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_struct_end (ThriftProtocol *protocol,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_field_begin (ThriftProtocol *protocol,
|
||||
gchar **name,
|
||||
ThriftType *field_type,
|
||||
gint16 *field_id,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_field_end (ThriftProtocol *protocol,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_map_begin (ThriftProtocol *protocol,
|
||||
ThriftType *key_type,
|
||||
ThriftType *value_type, guint32 *size,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_map_end (ThriftProtocol *protocol, GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_list_begin (ThriftProtocol *protocol,
|
||||
ThriftType *element_type,
|
||||
guint32 *size, GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_list_end (ThriftProtocol *protocol, GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_set_begin (ThriftProtocol *protocol,
|
||||
ThriftType *element_type,
|
||||
guint32 *size, GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_set_end (ThriftProtocol *protocol, GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_bool (ThriftProtocol *protocol, gboolean *value,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_byte (ThriftProtocol *protocol, gint8 *value,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_i16 (ThriftProtocol *protocol, gint16 *value,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_i32 (ThriftProtocol *protocol, gint32 *value,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_i64 (ThriftProtocol *protocol, gint64 *value,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_double (ThriftProtocol *protocol,
|
||||
gdouble *value, GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_string (ThriftProtocol *protocol,
|
||||
gchar **str, GError **error);
|
||||
|
||||
gint32 thrift_protocol_read_binary (ThriftProtocol *protocol,
|
||||
gpointer *buf, guint32 *len,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_protocol_skip (ThriftProtocol *protocol, ThriftType type,
|
||||
GError **error);
|
||||
|
||||
/* define error types */
|
||||
typedef enum
|
||||
{
|
||||
THRIFT_PROTOCOL_ERROR_UNKNOWN,
|
||||
THRIFT_PROTOCOL_ERROR_INVALID_DATA,
|
||||
THRIFT_PROTOCOL_ERROR_NEGATIVE_SIZE,
|
||||
THRIFT_PROTOCOL_ERROR_SIZE_LIMIT,
|
||||
THRIFT_PROTOCOL_ERROR_BAD_VERSION,
|
||||
THRIFT_PROTOCOL_ERROR_NOT_IMPLEMENTED,
|
||||
THRIFT_PROTOCOL_ERROR_DEPTH_LIMIT
|
||||
} ThriftProtocolError;
|
||||
|
||||
/* define an error domain for GError to use */
|
||||
GQuark thrift_protocol_error_quark (void);
|
||||
#define THRIFT_PROTOCOL_ERROR (thrift_protocol_error_quark ())
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_PROTOCOL_H */
|
||||
626
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol_decorator.c
generated
vendored
Normal file
626
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol_decorator.c
generated
vendored
Normal file
@@ -0,0 +1,626 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/protocol/thrift_protocol.h>
|
||||
#include <thrift/c_glib/protocol/thrift_binary_protocol.h>
|
||||
#include <thrift/c_glib/protocol/thrift_protocol_decorator.h>
|
||||
|
||||
G_DEFINE_TYPE(ThriftProtocolDecorator, thrift_protocol_decorator, THRIFT_TYPE_PROTOCOL)
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_THRIFT_TYPE_PROTOCOL_DECORATOR_CONCRETE_PROTOCOL = 1,
|
||||
PROP_THRIFT_TYPE_PROTOCOL_DECORATOR_END
|
||||
};
|
||||
|
||||
static GParamSpec *thrift_protocol_decorator_obj_properties[PROP_THRIFT_TYPE_PROTOCOL_DECORATOR_END] = { NULL, };
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_message_begin (ThriftProtocol *protocol,
|
||||
const gchar *name,
|
||||
const ThriftMessageType message_type,
|
||||
const gint32 seqid, GError **error)
|
||||
{
|
||||
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
ThriftProtocolClass *proto = THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol);
|
||||
|
||||
g_debug("Concrete protocol %p | %p", self->concrete_protocol, proto);
|
||||
|
||||
return proto->write_message_begin (self->concrete_protocol, name,
|
||||
message_type, seqid,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_message_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_message_end (self->concrete_protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_struct_begin (ThriftProtocol *protocol, const gchar *name,
|
||||
GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_struct_begin (self->concrete_protocol,
|
||||
name, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_struct_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_struct_end (self->concrete_protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_field_begin (ThriftProtocol *protocol,
|
||||
const gchar *name,
|
||||
const ThriftType field_type,
|
||||
const gint16 field_id,
|
||||
GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_field_begin (self->concrete_protocol,
|
||||
name, field_type,
|
||||
field_id, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_field_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_field_end (self->concrete_protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_field_stop (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_field_stop (self->concrete_protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_map_begin (ThriftProtocol *protocol,
|
||||
const ThriftType key_type,
|
||||
const ThriftType value_type,
|
||||
const guint32 size, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_map_begin (self->concrete_protocol,
|
||||
key_type, value_type,
|
||||
size, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_map_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_map_end (self->concrete_protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_list_begin (ThriftProtocol *protocol,
|
||||
const ThriftType element_type,
|
||||
const guint32 size, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_list_begin (self->concrete_protocol,
|
||||
element_type, size,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_list_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_list_end (self->concrete_protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_set_begin (ThriftProtocol *protocol,
|
||||
const ThriftType element_type,
|
||||
const guint32 size, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_set_begin (self->concrete_protocol,
|
||||
element_type, size,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_set_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_set_end (self->concrete_protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_bool (ThriftProtocol *protocol,
|
||||
const gboolean value, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_bool (self->concrete_protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_byte (ThriftProtocol *protocol, const gint8 value,
|
||||
GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_byte (self->concrete_protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_i16 (ThriftProtocol *protocol, const gint16 value,
|
||||
GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_i16 (self->concrete_protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_i32 (ThriftProtocol *protocol, const gint32 value,
|
||||
GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_i32 (self->concrete_protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_i64 (ThriftProtocol *protocol, const gint64 value,
|
||||
GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_i64 (self->concrete_protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_double (ThriftProtocol *protocol,
|
||||
const gdouble value, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_double (self->concrete_protocol,
|
||||
value, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_string (ThriftProtocol *protocol,
|
||||
const gchar *str, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_string (self->concrete_protocol, str,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_write_binary (ThriftProtocol *protocol, const gpointer buf,
|
||||
const guint32 len, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->write_binary (self->concrete_protocol, buf,
|
||||
len, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_message_begin (ThriftProtocol *protocol,
|
||||
gchar **name,
|
||||
ThriftMessageType *message_type,
|
||||
gint32 *seqid, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_message_begin (self->concrete_protocol,
|
||||
name, message_type,
|
||||
seqid, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_message_end (ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_message_end (self->concrete_protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_struct_begin (ThriftProtocol *protocol,
|
||||
gchar **name,
|
||||
GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_struct_begin (self->concrete_protocol,
|
||||
name,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_struct_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_struct_end (self->concrete_protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_field_begin (ThriftProtocol *protocol,
|
||||
gchar **name,
|
||||
ThriftType *field_type,
|
||||
gint16 *field_id,
|
||||
GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_field_begin (self->concrete_protocol,
|
||||
name,
|
||||
field_type,
|
||||
field_id,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_field_end (ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_field_end (self->concrete_protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_map_begin (ThriftProtocol *protocol,
|
||||
ThriftType *key_type,
|
||||
ThriftType *value_type, guint32 *size,
|
||||
GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_map_begin (self->concrete_protocol,
|
||||
key_type,
|
||||
value_type,
|
||||
size,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_map_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_map_end (self->concrete_protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_list_begin (ThriftProtocol *protocol,
|
||||
ThriftType *element_type,
|
||||
guint32 *size, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_list_begin (self->concrete_protocol,
|
||||
element_type,
|
||||
size, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_list_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_list_end (self->concrete_protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_set_begin (ThriftProtocol *protocol,
|
||||
ThriftType *element_type,
|
||||
guint32 *size, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_set_begin (self->concrete_protocol,
|
||||
element_type,
|
||||
size, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_set_end (ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_set_end (self->concrete_protocol,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_bool (ThriftProtocol *protocol, gboolean *value,
|
||||
GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_bool (self->concrete_protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_byte (ThriftProtocol *protocol, gint8 *value,
|
||||
GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_byte (self->concrete_protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_i16 (ThriftProtocol *protocol, gint16 *value,
|
||||
GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_i16 (self->concrete_protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_i32 (ThriftProtocol *protocol, gint32 *value,
|
||||
GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_i32 (self->concrete_protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_i64 (ThriftProtocol *protocol, gint64 *value,
|
||||
GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_i64 (self->concrete_protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_double (ThriftProtocol *protocol,
|
||||
gdouble *value, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_double (self->concrete_protocol, value,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_string (ThriftProtocol *protocol,
|
||||
gchar **str, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_string (self->concrete_protocol, str,
|
||||
error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_protocol_decorator_read_binary (ThriftProtocol *protocol, gpointer *buf,
|
||||
guint32 *len, GError **error)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (protocol);
|
||||
|
||||
return THRIFT_PROTOCOL_GET_CLASS (self->concrete_protocol)->read_binary (self->concrete_protocol, buf,
|
||||
len, error);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
thrift_protocol_decorator_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (object);
|
||||
g_debug("Is protocol decorator %i", THRIFT_IS_PROTOCOL_DECORATOR(object));
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_TYPE_PROTOCOL_DECORATOR_CONCRETE_PROTOCOL:
|
||||
self->concrete_protocol = g_value_dup_object (value);
|
||||
g_debug("Setting concrete protocol %p to %p in %s", self, self->concrete_protocol, g_type_name(G_TYPE_FROM_INSTANCE(object)));
|
||||
break;
|
||||
|
||||
default:
|
||||
/* We don't have any other property... */
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_protocol_decorator_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (object);
|
||||
g_debug("Is protocol decorator %i", THRIFT_IS_PROTOCOL_DECORATOR(object));
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_TYPE_PROTOCOL_DECORATOR_CONCRETE_PROTOCOL:
|
||||
g_value_set_object (value, self->concrete_protocol);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* We don't have any other property... */
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ThriftProtocol *
|
||||
thrift_protocol_decorator_get_concrete_protocol(ThriftProtocolDecorator *protocol)
|
||||
{
|
||||
ThriftProtocol *retval = NULL;
|
||||
if(!THRIFT_IS_PROTOCOL_DECORATOR(protocol)){
|
||||
g_warning("The type is not protocol decorator");
|
||||
return NULL;
|
||||
}
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR(protocol);
|
||||
g_debug("Getting concrete protocol from %X -> %X", self, self->concrete_protocol);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
thrift_protocol_decorator_init (ThriftProtocolDecorator *protocol)
|
||||
{
|
||||
protocol->concrete_protocol = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_protocol_decorator_dispose (GObject *gobject)
|
||||
{
|
||||
ThriftProtocolDecorator *self = THRIFT_PROTOCOL_DECORATOR (gobject);
|
||||
|
||||
g_clear_object(&self->concrete_protocol);
|
||||
|
||||
/* Always chain up to the parent class; there is no need to check if
|
||||
* the parent class implements the dispose() virtual function: it is
|
||||
* always guaranteed to do so
|
||||
*/
|
||||
G_OBJECT_CLASS (thrift_protocol_decorator_parent_class)->dispose(gobject);
|
||||
}
|
||||
|
||||
/* initialize the class */
|
||||
static void
|
||||
thrift_protocol_decorator_class_init (ThriftProtocolDecoratorClass *klass)
|
||||
{
|
||||
ThriftProtocolClass *cls = THRIFT_PROTOCOL_CLASS (klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
object_class->set_property = thrift_protocol_decorator_set_property;
|
||||
object_class->get_property = thrift_protocol_decorator_get_property;
|
||||
object_class->dispose = thrift_protocol_decorator_dispose;
|
||||
|
||||
thrift_protocol_decorator_obj_properties[PROP_THRIFT_TYPE_PROTOCOL_DECORATOR_CONCRETE_PROTOCOL] =
|
||||
g_param_spec_object ("protocol",
|
||||
"Protocol",
|
||||
"Set the protocol to be implemented", THRIFT_TYPE_PROTOCOL,
|
||||
(G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_properties (object_class,
|
||||
PROP_THRIFT_TYPE_PROTOCOL_DECORATOR_END,
|
||||
thrift_protocol_decorator_obj_properties);
|
||||
|
||||
g_debug("Current decorator write_message_begin addr %p, new %p", cls->write_message_begin, thrift_protocol_decorator_write_message_begin);
|
||||
|
||||
cls->write_message_begin = thrift_protocol_decorator_write_message_begin;
|
||||
cls->write_message_end = thrift_protocol_decorator_write_message_end;
|
||||
cls->write_struct_begin = thrift_protocol_decorator_write_struct_begin;
|
||||
cls->write_struct_end = thrift_protocol_decorator_write_struct_end;
|
||||
cls->write_field_begin = thrift_protocol_decorator_write_field_begin;
|
||||
cls->write_field_end = thrift_protocol_decorator_write_field_end;
|
||||
cls->write_field_stop = thrift_protocol_decorator_write_field_stop;
|
||||
cls->write_map_begin = thrift_protocol_decorator_write_map_begin;
|
||||
cls->write_map_end = thrift_protocol_decorator_write_map_end;
|
||||
cls->write_list_begin = thrift_protocol_decorator_write_list_begin;
|
||||
cls->write_list_end = thrift_protocol_decorator_write_list_end;
|
||||
cls->write_set_begin = thrift_protocol_decorator_write_set_begin;
|
||||
cls->write_set_end = thrift_protocol_decorator_write_set_end;
|
||||
cls->write_bool = thrift_protocol_decorator_write_bool;
|
||||
cls->write_byte = thrift_protocol_decorator_write_byte;
|
||||
cls->write_i16 = thrift_protocol_decorator_write_i16;
|
||||
cls->write_i32 = thrift_protocol_decorator_write_i32;
|
||||
cls->write_i64 = thrift_protocol_decorator_write_i64;
|
||||
cls->write_double = thrift_protocol_decorator_write_double;
|
||||
cls->write_string = thrift_protocol_decorator_write_string;
|
||||
cls->write_binary = thrift_protocol_decorator_write_binary;
|
||||
cls->read_message_begin = thrift_protocol_decorator_read_message_begin;
|
||||
cls->read_message_end = thrift_protocol_decorator_read_message_end;
|
||||
cls->read_struct_begin = thrift_protocol_decorator_read_struct_begin;
|
||||
cls->read_struct_end = thrift_protocol_decorator_read_struct_end;
|
||||
cls->read_field_begin = thrift_protocol_decorator_read_field_begin;
|
||||
cls->read_field_end = thrift_protocol_decorator_read_field_end;
|
||||
cls->read_map_begin = thrift_protocol_decorator_read_map_begin;
|
||||
cls->read_map_end = thrift_protocol_decorator_read_map_end;
|
||||
cls->read_list_begin = thrift_protocol_decorator_read_list_begin;
|
||||
cls->read_list_end = thrift_protocol_decorator_read_list_end;
|
||||
cls->read_set_begin = thrift_protocol_decorator_read_set_begin;
|
||||
cls->read_set_end = thrift_protocol_decorator_read_set_end;
|
||||
cls->read_bool = thrift_protocol_decorator_read_bool;
|
||||
cls->read_byte = thrift_protocol_decorator_read_byte;
|
||||
cls->read_i16 = thrift_protocol_decorator_read_i16;
|
||||
cls->read_i32 = thrift_protocol_decorator_read_i32;
|
||||
cls->read_i64 = thrift_protocol_decorator_read_i64;
|
||||
cls->read_double = thrift_protocol_decorator_read_double;
|
||||
cls->read_string = thrift_protocol_decorator_read_string;
|
||||
cls->read_binary = thrift_protocol_decorator_read_binary;
|
||||
}
|
||||
72
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol_decorator.h
generated
vendored
Normal file
72
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol_decorator.h
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_PROTOCOL_DECORATOR_H
|
||||
#define _THRIFT_PROTOCOL_DECORATOR_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/protocol/thrift_protocol.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_protocol_decorator.h
|
||||
* \brief Multiplexed protocol implementation of a Thrift protocol. Implements the
|
||||
* ThriftProtocol interface.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_PROTOCOL_DECORATOR (thrift_protocol_decorator_get_type ())
|
||||
#define THRIFT_PROTOCOL_DECORATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_PROTOCOL_DECORATOR, ThriftProtocolDecorator))
|
||||
#define THRIFT_IS_PROTOCOL_DECORATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_PROTOCOL_DECORATOR))
|
||||
#define THRIFT_PROTOCOL_DECORATOR_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_PROTOCOL_DECORATOR, ThriftProtocolDecoratorClass))
|
||||
#define THRIFT_IS_PROTOCOL_DECORATOR_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_PROTOCOL_DECORATOR))
|
||||
#define THRIFT_PROTOCOL_DECORATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_PROTOCOL_DECORATOR, ThriftProtocolDecoratorClass))
|
||||
|
||||
typedef struct _ThriftProtocolDecorator ThriftProtocolDecorator;
|
||||
|
||||
|
||||
/*!
|
||||
* Thrift Protocol Decorator instance.
|
||||
*/
|
||||
struct _ThriftProtocolDecorator
|
||||
{
|
||||
ThriftProtocol parent;
|
||||
|
||||
ThriftProtocol *concrete_protocol;
|
||||
};
|
||||
|
||||
typedef struct _ThriftProtocolDecoratorClass ThriftProtocolDecoratorClass;
|
||||
|
||||
/*!
|
||||
* Thrift Protocol Decorator class.
|
||||
*/
|
||||
struct _ThriftProtocolDecoratorClass
|
||||
{
|
||||
ThriftProtocolClass parent;
|
||||
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_PROTOCOL_DECORATOR */
|
||||
GType thrift_protocol_decorator_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_PROTOCOL_DECORATOR_H */
|
||||
43
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol_factory.c
generated
vendored
Normal file
43
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol_factory.c
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/protocol/thrift_protocol_factory.h>
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE(ThriftProtocolFactory, thrift_protocol_factory, G_TYPE_OBJECT)
|
||||
|
||||
ThriftProtocol *
|
||||
thrift_protocol_factory_get_protocol(ThriftProtocolFactory *factory,
|
||||
ThriftTransport *transport)
|
||||
{
|
||||
return THRIFT_PROTOCOL_FACTORY_GET_CLASS (factory)->get_protocol (factory,
|
||||
transport);
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_protocol_factory_init (ThriftProtocolFactory *factory)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (factory);
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_protocol_factory_class_init (ThriftProtocolFactoryClass *cls)
|
||||
{
|
||||
cls->get_protocol = thrift_protocol_factory_get_protocol;
|
||||
}
|
||||
73
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol_factory.h
generated
vendored
Normal file
73
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol_factory.h
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_PROTOCOL_FACTORY_H
|
||||
#define _THRIFT_PROTOCOL_FACTORY_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
#include <thrift/c_glib/protocol/thrift_protocol.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_protocol_factory.h
|
||||
* \brief Abstract class for Thrift protocol factory implementations.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_PROTOCOL_FACTORY (thrift_protocol_factory_get_type ())
|
||||
#define THRIFT_PROTOCOL_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_PROTOCOL_FACTORY, ThriftProtocolFactory))
|
||||
#define THRIFT_IS_PROTOCOL_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_PROTOCOL_FACTORY))
|
||||
#define THRIFT_PROTOCOL_FACTORY_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_PROTOCOL_FACTORY, ThriftProtocolFactoryClass))
|
||||
#define THRIFT_IS_PROTOCOL_FACTORY_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_PROTOCOL_FACTORY))
|
||||
#define THRIFT_PROTOCOL_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_PROTOCOL_FACTORY, ThriftProtocolFactoryClass))
|
||||
|
||||
typedef struct _ThriftProtocolFactory ThriftProtocolFactory;
|
||||
|
||||
/*!
|
||||
* Thrift Protocol Factory object
|
||||
*/
|
||||
struct _ThriftProtocolFactory
|
||||
{
|
||||
GObject parent;
|
||||
};
|
||||
|
||||
typedef struct _ThriftProtocolFactoryClass ThriftProtocolFactoryClass;
|
||||
|
||||
/*!
|
||||
* Thrift Protocol Factory class
|
||||
*/
|
||||
struct _ThriftProtocolFactoryClass
|
||||
{
|
||||
GObjectClass parent;
|
||||
|
||||
ThriftProtocol *(*get_protocol) (ThriftProtocolFactory *factory,
|
||||
ThriftTransport *transport);
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_PROTOCOL_FACTORY */
|
||||
GType thrift_protocol_factory_get_type (void);
|
||||
|
||||
/* virtual public methods */
|
||||
ThriftProtocol *thrift_protocol_factory_get_protocol(ThriftProtocolFactory *factory, ThriftTransport *transport);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_PROTOCOL_FACTORY_H */
|
||||
195
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/server/thrift_server.c
generated
vendored
Normal file
195
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/server/thrift_server.c
generated
vendored
Normal file
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include "thrift_server.h"
|
||||
|
||||
/* object properties */
|
||||
enum _ThriftServerProperties
|
||||
{
|
||||
PROP_0,
|
||||
PROP_THRIFT_SERVER_PROCESSOR,
|
||||
PROP_THRIFT_SERVER_SERVER_TRANSPORT,
|
||||
PROP_THRIFT_SERVER_INPUT_TRANSPORT_FACTORY,
|
||||
PROP_THRIFT_SERVER_OUTPUT_TRANSPORT_FACTORY,
|
||||
PROP_THRIFT_SERVER_INPUT_PROTOCOL_FACTORY,
|
||||
PROP_THRIFT_SERVER_OUTPUT_PROTOCOL_FACTORY
|
||||
};
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE(ThriftServer, thrift_server, G_TYPE_OBJECT)
|
||||
|
||||
void
|
||||
thrift_server_get_property (GObject *object, guint property_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftServer *server = THRIFT_SERVER (object);
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_SERVER_PROCESSOR:
|
||||
g_value_set_object (value, server->processor);
|
||||
break;
|
||||
case PROP_THRIFT_SERVER_SERVER_TRANSPORT:
|
||||
g_value_set_object (value, server->server_transport);
|
||||
break;
|
||||
case PROP_THRIFT_SERVER_INPUT_TRANSPORT_FACTORY:
|
||||
g_value_set_object (value, server->input_transport_factory);
|
||||
break;
|
||||
case PROP_THRIFT_SERVER_OUTPUT_TRANSPORT_FACTORY:
|
||||
g_value_set_object (value, server->output_transport_factory);
|
||||
break;
|
||||
case PROP_THRIFT_SERVER_INPUT_PROTOCOL_FACTORY:
|
||||
g_value_set_object (value, server->input_protocol_factory);
|
||||
break;
|
||||
case PROP_THRIFT_SERVER_OUTPUT_PROTOCOL_FACTORY:
|
||||
g_value_set_object (value, server->output_protocol_factory);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
thrift_server_set_property (GObject *object, guint property_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftServer *server = THRIFT_SERVER (object);
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_SERVER_PROCESSOR:
|
||||
server->processor = g_value_dup_object (value);
|
||||
break;
|
||||
case PROP_THRIFT_SERVER_SERVER_TRANSPORT:
|
||||
server->server_transport = g_value_dup_object (value);
|
||||
break;
|
||||
case PROP_THRIFT_SERVER_INPUT_TRANSPORT_FACTORY:
|
||||
server->input_transport_factory = g_value_dup_object (value);
|
||||
break;
|
||||
case PROP_THRIFT_SERVER_OUTPUT_TRANSPORT_FACTORY:
|
||||
server->output_transport_factory = g_value_dup_object (value);
|
||||
break;
|
||||
case PROP_THRIFT_SERVER_INPUT_PROTOCOL_FACTORY:
|
||||
server->input_protocol_factory = g_value_dup_object (value);
|
||||
break;
|
||||
case PROP_THRIFT_SERVER_OUTPUT_PROTOCOL_FACTORY:
|
||||
server->output_protocol_factory = g_value_dup_object (value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
thrift_server_serve (ThriftServer *server, GError **error)
|
||||
{
|
||||
return THRIFT_SERVER_GET_CLASS (server)->serve (server, error);
|
||||
}
|
||||
|
||||
void
|
||||
thrift_server_stop (ThriftServer *server)
|
||||
{
|
||||
THRIFT_SERVER_GET_CLASS (server)->stop (server);
|
||||
}
|
||||
|
||||
/* instance initializer for Thrift Server */
|
||||
static void
|
||||
thrift_server_init (ThriftServer *server)
|
||||
{
|
||||
server->processor = NULL;
|
||||
server->server_transport = NULL;
|
||||
server->input_transport_factory = NULL;
|
||||
server->output_transport_factory = NULL;
|
||||
server->input_protocol_factory = NULL;
|
||||
server->output_protocol_factory = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_server_dispose (GObject *gobject)
|
||||
{
|
||||
ThriftServer *self = THRIFT_SERVER (gobject);
|
||||
|
||||
g_clear_object(&self->output_protocol_factory);
|
||||
g_clear_object(&self->input_protocol_factory);
|
||||
g_clear_object(&self->output_transport_factory);
|
||||
g_clear_object(&self->input_transport_factory);
|
||||
g_clear_object(&self->server_transport);
|
||||
g_clear_object(&self->processor);
|
||||
|
||||
/* Always chain up to the parent class; there is no need to check if
|
||||
* the parent class implements the dispose() virtual function: it is
|
||||
* always guaranteed to do so
|
||||
*/
|
||||
G_OBJECT_CLASS (thrift_server_parent_class)->dispose(gobject);
|
||||
}
|
||||
|
||||
/*
|
||||
* class initializer for ThriftServer
|
||||
* TODO: implement ServerEventHandler as a GClosure
|
||||
*/
|
||||
static void
|
||||
thrift_server_class_init (ThriftServerClass *cls)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
|
||||
|
||||
gobject_class->get_property = thrift_server_get_property;
|
||||
gobject_class->set_property = thrift_server_set_property;
|
||||
gobject_class->dispose = thrift_server_dispose;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_SERVER_PROCESSOR,
|
||||
g_param_spec_object ("processor", "Processor", "Thrift Processor",
|
||||
THRIFT_TYPE_PROCESSOR,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_SERVER_SERVER_TRANSPORT,
|
||||
g_param_spec_object ("server_transport", "Server Transport",
|
||||
"Thrift Server Transport",
|
||||
THRIFT_TYPE_SERVER_TRANSPORT,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_SERVER_INPUT_TRANSPORT_FACTORY,
|
||||
g_param_spec_object ("input_transport_factory", "Input Transport Factory",
|
||||
"Thrift Server Input Transport Factory",
|
||||
THRIFT_TYPE_TRANSPORT_FACTORY,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_SERVER_OUTPUT_TRANSPORT_FACTORY,
|
||||
g_param_spec_object ("output_transport_factory",
|
||||
"Output Transport Factory",
|
||||
"Thrift Server Output Transport Factory",
|
||||
THRIFT_TYPE_TRANSPORT_FACTORY,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_SERVER_INPUT_PROTOCOL_FACTORY,
|
||||
g_param_spec_object ("input_protocol_factory", "Input Protocol Factory",
|
||||
"Thrift Server Input Protocol Factory",
|
||||
THRIFT_TYPE_PROTOCOL_FACTORY,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_SERVER_OUTPUT_PROTOCOL_FACTORY,
|
||||
g_param_spec_object ("output_protocol_factory", "Output Protocol Factory",
|
||||
"Thrift Server Output Protocol Factory",
|
||||
THRIFT_TYPE_PROTOCOL_FACTORY,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
/* set these as virtual methods to be implemented by a subclass */
|
||||
cls->serve = thrift_server_serve;
|
||||
cls->stop = thrift_server_stop;
|
||||
}
|
||||
93
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/server/thrift_server.h
generated
vendored
Normal file
93
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/server/thrift_server.h
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_SERVER_H
|
||||
#define _THRIFT_SERVER_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/processor/thrift_processor.h>
|
||||
#include <thrift/c_glib/transport/thrift_server_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport_factory.h>
|
||||
#include <thrift/c_glib/protocol/thrift_protocol_factory.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_server.h
|
||||
* \brief Abstract class for Thrift servers.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_SERVER (thrift_server_get_type ())
|
||||
#define THRIFT_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_SERVER, ThriftServer))
|
||||
#define THRIFT_IS_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_SERVER))
|
||||
#define THRIFT_SERVER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_SERVER, ThriftServerClass))
|
||||
#define THRIFT_IS_SERVER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_SERVER))
|
||||
#define THRIFT_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_SERVER, ThriftServerClass))
|
||||
|
||||
typedef struct _ThriftServer ThriftServer;
|
||||
|
||||
/*!
|
||||
* Thrift Server object
|
||||
*/
|
||||
struct _ThriftServer
|
||||
{
|
||||
GObject parent;
|
||||
|
||||
/* protected */
|
||||
ThriftProcessor *processor;
|
||||
ThriftServerTransport *server_transport;
|
||||
ThriftTransportFactory *input_transport_factory;
|
||||
ThriftTransportFactory *output_transport_factory;
|
||||
ThriftProtocolFactory *input_protocol_factory;
|
||||
ThriftProtocolFactory *output_protocol_factory;
|
||||
};
|
||||
|
||||
typedef struct _ThriftServerClass ThriftServerClass;
|
||||
|
||||
/*!
|
||||
* Thrift Server class
|
||||
*/
|
||||
struct _ThriftServerClass
|
||||
{
|
||||
GObjectClass parent;
|
||||
|
||||
/* vtable */
|
||||
gboolean (*serve) (ThriftServer *server, GError **error);
|
||||
void (*stop) (ThriftServer *server);
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_SERVER */
|
||||
GType thrift_server_get_type (void);
|
||||
|
||||
/*!
|
||||
* Processes the request.
|
||||
* \public \memberof ThriftServerClass
|
||||
*/
|
||||
gboolean thrift_server_serve (ThriftServer *server, GError **error);
|
||||
|
||||
/*!
|
||||
* Stop handling requests.
|
||||
*/
|
||||
void thrift_server_stop (ThriftServer *server);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_SERVER_H */
|
||||
|
||||
138
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/server/thrift_simple_server.c
generated
vendored
Normal file
138
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/server/thrift_simple_server.c
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <thrift/c_glib/server/thrift_simple_server.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport_factory.h>
|
||||
#include <thrift/c_glib/protocol/thrift_protocol_factory.h>
|
||||
#include <thrift/c_glib/protocol/thrift_binary_protocol_factory.h>
|
||||
|
||||
G_DEFINE_TYPE(ThriftSimpleServer, thrift_simple_server, THRIFT_TYPE_SERVER)
|
||||
|
||||
gboolean
|
||||
thrift_simple_server_serve (ThriftServer *server, GError **error)
|
||||
{
|
||||
ThriftTransport *t = NULL;
|
||||
ThriftTransport *input_transport = NULL, *output_transport = NULL;
|
||||
ThriftProtocol *input_protocol = NULL, *output_protocol = NULL;
|
||||
ThriftSimpleServer *tss = THRIFT_SIMPLE_SERVER(server);
|
||||
GError *process_error = NULL;
|
||||
|
||||
g_return_val_if_fail (THRIFT_IS_SIMPLE_SERVER (server), FALSE);
|
||||
|
||||
if (thrift_server_transport_listen (server->server_transport, error)) {
|
||||
tss->running = TRUE;
|
||||
while (tss->running == TRUE)
|
||||
{
|
||||
t = thrift_server_transport_accept (server->server_transport,
|
||||
error);
|
||||
if (t != NULL && tss->running) {
|
||||
input_transport =
|
||||
THRIFT_TRANSPORT_FACTORY_GET_CLASS (server->input_transport_factory)
|
||||
->get_transport (server->input_transport_factory, t);
|
||||
output_transport =
|
||||
THRIFT_TRANSPORT_FACTORY_GET_CLASS (server->output_transport_factory)
|
||||
->get_transport (server->output_transport_factory, t);
|
||||
input_protocol =
|
||||
THRIFT_PROTOCOL_FACTORY_GET_CLASS (server->input_protocol_factory)
|
||||
->get_protocol (server->input_protocol_factory, input_transport);
|
||||
output_protocol =
|
||||
THRIFT_PROTOCOL_FACTORY_GET_CLASS (server->output_protocol_factory)
|
||||
->get_protocol (server->output_protocol_factory, output_transport);
|
||||
|
||||
while (THRIFT_PROCESSOR_GET_CLASS (server->processor)
|
||||
->process (server->processor,
|
||||
input_protocol,
|
||||
output_protocol,
|
||||
&process_error) &&
|
||||
thrift_transport_peek (input_transport, &process_error))
|
||||
{
|
||||
}
|
||||
|
||||
if (process_error != NULL)
|
||||
{
|
||||
g_message ("thrift_simple_server_serve: %s", process_error->message);
|
||||
g_clear_error (&process_error);
|
||||
|
||||
/* Note we do not propagate processing errors to the caller as they
|
||||
* normally are transient and not fatal to the server */
|
||||
}
|
||||
|
||||
/* TODO: handle exceptions */
|
||||
THRIFT_TRANSPORT_GET_CLASS (input_transport)->close (input_transport,
|
||||
NULL);
|
||||
THRIFT_TRANSPORT_GET_CLASS (output_transport)->close (output_transport,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* attempt to shutdown */
|
||||
THRIFT_SERVER_TRANSPORT_GET_CLASS (server->server_transport)
|
||||
->close (server->server_transport, NULL);
|
||||
}
|
||||
|
||||
/* Since this method is designed to run forever, it can only ever return on
|
||||
* error */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
thrift_simple_server_stop (ThriftServer *server)
|
||||
{
|
||||
g_return_if_fail (THRIFT_IS_SIMPLE_SERVER (server));
|
||||
(THRIFT_SIMPLE_SERVER (server))->running = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_simple_server_init (ThriftSimpleServer *tss)
|
||||
{
|
||||
ThriftServer *server = THRIFT_SERVER(tss);
|
||||
|
||||
tss->running = FALSE;
|
||||
|
||||
if (server->input_transport_factory == NULL)
|
||||
{
|
||||
server->input_transport_factory =
|
||||
g_object_new (THRIFT_TYPE_TRANSPORT_FACTORY, NULL);
|
||||
}
|
||||
if (server->output_transport_factory == NULL)
|
||||
{
|
||||
server->output_transport_factory =
|
||||
g_object_new (THRIFT_TYPE_TRANSPORT_FACTORY, NULL);
|
||||
}
|
||||
if (server->input_protocol_factory == NULL)
|
||||
{
|
||||
server->input_protocol_factory =
|
||||
g_object_new (THRIFT_TYPE_BINARY_PROTOCOL_FACTORY, NULL);
|
||||
}
|
||||
if (server->output_protocol_factory == NULL)
|
||||
{
|
||||
server->output_protocol_factory =
|
||||
g_object_new (THRIFT_TYPE_BINARY_PROTOCOL_FACTORY, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* initialize the class */
|
||||
static void
|
||||
thrift_simple_server_class_init (ThriftSimpleServerClass *class)
|
||||
{
|
||||
ThriftServerClass *cls = THRIFT_SERVER_CLASS(class);
|
||||
|
||||
cls->serve = thrift_simple_server_serve;
|
||||
cls->stop = thrift_simple_server_stop;
|
||||
}
|
||||
70
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/server/thrift_simple_server.h
generated
vendored
Normal file
70
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/server/thrift_simple_server.h
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_SIMPLE_SERVER_H
|
||||
#define _THRIFT_SIMPLE_SERVER_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/server/thrift_server.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_simple_server.h
|
||||
* \brief A simple Thrift server, single-threaded.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_SIMPLE_SERVER (thrift_simple_server_get_type ())
|
||||
#define THRIFT_SIMPLE_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_SIMPLE_SERVER, ThriftSimpleServer))
|
||||
#define THRIFT_IS_SIMPLE_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_SIMPLE_SERVER))
|
||||
#define THRIFT_SIMPLE_SERVER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c) THRIFT_TYPE_SIMPLE_SERVER, ThriftSimpleServerClass))
|
||||
#define THRIFT_IS_SIMPLE_SERVER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_SIMPLE_SERVER))
|
||||
#define THRIFT_SIMPLE_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_SIMPLE_SERVER, ThriftSimpleServerClass))
|
||||
|
||||
typedef struct _ThriftSimpleServer ThriftSimpleServer;
|
||||
|
||||
/**
|
||||
* Thrift Simple Server instance.
|
||||
*/
|
||||
struct _ThriftSimpleServer
|
||||
{
|
||||
ThriftServer parent;
|
||||
|
||||
/* private */
|
||||
volatile gboolean running;
|
||||
};
|
||||
|
||||
typedef struct _ThriftSimpleServerClass ThriftSimpleServerClass;
|
||||
|
||||
/**
|
||||
* Thrift Simple Server class.
|
||||
*/
|
||||
struct _ThriftSimpleServerClass
|
||||
{
|
||||
ThriftServerClass parent;
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_SIMPLE_SERVER */
|
||||
GType thrift_simple_server_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_SIMPLE_SERVER_H */
|
||||
|
||||
101
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/thrift.c
generated
vendored
Normal file
101
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/thrift.c
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
|
||||
/**
|
||||
* GHashTable callback to add keys to a GList.
|
||||
*/
|
||||
void
|
||||
thrift_hash_table_get_keys (gpointer key, gpointer value, gpointer user_data)
|
||||
{
|
||||
GList **list = (GList **) user_data;
|
||||
|
||||
THRIFT_UNUSED_VAR (value);
|
||||
|
||||
*list = g_list_append (*list, key);
|
||||
}
|
||||
void thrift_safe_hash_table_destroy(GHashTable* hash_table)
|
||||
{
|
||||
if (hash_table)
|
||||
{
|
||||
g_hash_table_destroy(hash_table);
|
||||
}
|
||||
}
|
||||
|
||||
guint thrift_boolean_hash(gconstpointer v)
|
||||
{
|
||||
const gboolean* p = v;
|
||||
return p && *p ? 1 : 0;
|
||||
}
|
||||
gboolean thrift_boolean_equal(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
if (a == b) {
|
||||
return TRUE;
|
||||
}
|
||||
if (!a || !b) {
|
||||
return FALSE;
|
||||
}
|
||||
const gboolean* pa = a;
|
||||
const gboolean* pb = b;
|
||||
return *pa == *pb;
|
||||
}
|
||||
|
||||
guint thrift_int8_hash(gconstpointer v)
|
||||
{
|
||||
const gint8* p = v;
|
||||
return p ? *p : 0;
|
||||
}
|
||||
gboolean thrift_int8_equal(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
if (a == b) {
|
||||
return TRUE;
|
||||
}
|
||||
if (!a || !b) {
|
||||
return FALSE;
|
||||
}
|
||||
const gint8* pa = a;
|
||||
const gint8* pb = b;
|
||||
return *pa == *pb;
|
||||
}
|
||||
|
||||
guint thrift_int16_hash(gconstpointer v)
|
||||
{
|
||||
const gint16* p = v;
|
||||
return p ? *p : 0;
|
||||
}
|
||||
gboolean thrift_int16_equal(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
if (a == b) {
|
||||
return TRUE;
|
||||
}
|
||||
if (!a || !b) {
|
||||
return FALSE;
|
||||
}
|
||||
const gint16* pa = a;
|
||||
const gint16* pb = b;
|
||||
return *pa == *pb;
|
||||
}
|
||||
|
||||
void
|
||||
thrift_string_free (gpointer str)
|
||||
{
|
||||
GByteArray* ptr = str;
|
||||
g_byte_array_unref(ptr);
|
||||
}
|
||||
49
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/thrift.h
generated
vendored
Normal file
49
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/thrift.h
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_H
|
||||
#define _THRIFT_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
/* this macro is called to satisfy -Wall hardcore compilation */
|
||||
#ifndef THRIFT_UNUSED_VAR
|
||||
# define THRIFT_UNUSED_VAR(x) ((void) x)
|
||||
#endif
|
||||
|
||||
void thrift_hash_table_get_keys (gpointer key, gpointer value,
|
||||
gpointer user_data);
|
||||
void thrift_safe_hash_table_destroy(GHashTable* hash_table);
|
||||
|
||||
guint thrift_boolean_hash(gconstpointer v);
|
||||
gboolean thrift_boolean_equal(gconstpointer a, gconstpointer b);
|
||||
|
||||
guint thrift_int8_hash(gconstpointer v);
|
||||
gboolean thrift_int8_equal(gconstpointer a, gconstpointer b);
|
||||
|
||||
guint thrift_int16_hash(gconstpointer v);
|
||||
gboolean thrift_int16_equal(gconstpointer a, gconstpointer b);
|
||||
|
||||
void thrift_string_free (gpointer str);
|
||||
|
||||
#endif /* #ifndef _THRIFT_THRIFT_H */
|
||||
277
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/thrift_application_exception.c
generated
vendored
Normal file
277
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/thrift_application_exception.c
generated
vendored
Normal file
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include "thrift_application_exception.h"
|
||||
#include <thrift/c_glib/protocol/thrift_protocol.h>
|
||||
|
||||
/* object properties */
|
||||
enum _ThriftApplicationExceptionProperties
|
||||
{
|
||||
PROP_0,
|
||||
PROP_THRIFT_APPLICATION_EXCEPTION_TYPE,
|
||||
PROP_THRIFT_APPLICATION_EXCEPTION_MESSAGE
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ThriftApplicationException, thrift_application_exception, THRIFT_TYPE_STRUCT)
|
||||
|
||||
gint32
|
||||
thrift_application_exception_read (ThriftStruct *object,
|
||||
ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
gint32 xfer = 0;
|
||||
gchar *name;
|
||||
ThriftType ftype;
|
||||
gint16 fid;
|
||||
ThriftApplicationException *this = THRIFT_APPLICATION_EXCEPTION (object);
|
||||
|
||||
/* read the struct begin marker */
|
||||
if ((ret = thrift_protocol_read_struct_begin (protocol, &name, error)) < 0)
|
||||
{
|
||||
if (name) g_free (name);
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
if (name) g_free (name);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if ((ret = thrift_protocol_read_field_begin (protocol, &name, &ftype,
|
||||
&fid, error)) < 0)
|
||||
{
|
||||
if (name) g_free (name);
|
||||
return -1;
|
||||
}
|
||||
xfer += ret;
|
||||
if (name) g_free (name);
|
||||
|
||||
/* break if we get a STOP field */
|
||||
if (ftype == T_STOP)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
switch (fid)
|
||||
{
|
||||
case 1:
|
||||
if (ftype == T_STRING)
|
||||
{
|
||||
if ((ret = thrift_protocol_read_string (protocol, &this->message,
|
||||
error)) < 0)
|
||||
return -1;
|
||||
xfer += ret;
|
||||
this->__isset_message = TRUE;
|
||||
} else {
|
||||
if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
|
||||
return -1;
|
||||
xfer += ret;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (ftype == T_I32)
|
||||
{
|
||||
if ((ret = thrift_protocol_read_i32 (protocol, &this->type,
|
||||
error)) < 0)
|
||||
return -1;
|
||||
xfer += ret;
|
||||
this->__isset_type = TRUE;
|
||||
} else {
|
||||
if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
|
||||
return -1;
|
||||
xfer += ret;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
|
||||
return -1;
|
||||
xfer += ret;
|
||||
break;
|
||||
}
|
||||
if ((ret = thrift_protocol_read_field_end (protocol, error)) < 0)
|
||||
return -1;
|
||||
xfer += ret;
|
||||
}
|
||||
|
||||
if ((ret = thrift_protocol_read_struct_end (protocol, error)) < 0)
|
||||
return -1;
|
||||
xfer += ret;
|
||||
|
||||
return xfer;
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_application_exception_write (ThriftStruct *object,
|
||||
ThriftProtocol *protocol, GError **error)
|
||||
{
|
||||
gint32 ret;
|
||||
gint32 xfer = 0;
|
||||
|
||||
ThriftApplicationException *this = THRIFT_APPLICATION_EXCEPTION (object);
|
||||
|
||||
if ((ret = thrift_protocol_write_struct_begin (protocol,
|
||||
"TApplicationException",
|
||||
error)) < 0)
|
||||
return -1;
|
||||
xfer += ret;
|
||||
if ((ret = thrift_protocol_write_field_begin (protocol, "message",
|
||||
T_STRING, 1, error)) < 0)
|
||||
return -1;
|
||||
xfer += ret;
|
||||
if ((ret = thrift_protocol_write_string (protocol, this->message, error)) < 0)
|
||||
return -1;
|
||||
xfer += ret;
|
||||
if ((ret = thrift_protocol_write_field_end (protocol, error)) < 0)
|
||||
return -1;
|
||||
xfer += ret;
|
||||
if ((ret = thrift_protocol_write_field_begin (protocol, "type",
|
||||
T_I32, 2, error)) < 0)
|
||||
return -1;
|
||||
xfer += ret;
|
||||
if ((ret = thrift_protocol_write_i32 (protocol, this->type, error)) < 0)
|
||||
return -1;
|
||||
xfer += ret;
|
||||
if ((ret = thrift_protocol_write_field_end (protocol, error)) < 0)
|
||||
return -1;
|
||||
xfer += ret;
|
||||
if ((ret = thrift_protocol_write_field_stop (protocol, error)) < 0)
|
||||
return -1;
|
||||
xfer += ret;
|
||||
if ((ret = thrift_protocol_write_struct_end (protocol, error)) < 0)
|
||||
return -1;
|
||||
xfer += ret;
|
||||
|
||||
return xfer;
|
||||
}
|
||||
|
||||
|
||||
/* GError domain */
|
||||
#define THRIFT_APPLICATION_EXCEPTION_ERROR_DOMAIN "thrift-application-exception-error-quark"
|
||||
|
||||
GQuark
|
||||
thrift_application_exception_error_quark (void)
|
||||
{
|
||||
return g_quark_from_static_string (THRIFT_APPLICATION_EXCEPTION_ERROR_DOMAIN);
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_application_exception_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
ThriftApplicationException *tae = THRIFT_APPLICATION_EXCEPTION (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_APPLICATION_EXCEPTION_TYPE:
|
||||
g_value_set_int (value, tae->type);
|
||||
break;
|
||||
case PROP_THRIFT_APPLICATION_EXCEPTION_MESSAGE:
|
||||
g_value_set_string (value, tae->message);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_application_exception_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
ThriftApplicationException *tae = THRIFT_APPLICATION_EXCEPTION (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_APPLICATION_EXCEPTION_TYPE:
|
||||
tae->type = g_value_get_int (value);
|
||||
tae->__isset_type = TRUE;
|
||||
break;
|
||||
case PROP_THRIFT_APPLICATION_EXCEPTION_MESSAGE:
|
||||
if (tae->message != NULL)
|
||||
g_free (tae->message);
|
||||
|
||||
tae->message = g_value_dup_string (value);
|
||||
tae->__isset_message = TRUE;
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
thrift_application_exception_init (ThriftApplicationException *object)
|
||||
{
|
||||
object->type = 0;
|
||||
object->__isset_type = FALSE;
|
||||
object->message = NULL;
|
||||
object->__isset_message = FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
thrift_application_exception_finalize (GObject *object)
|
||||
{
|
||||
ThriftApplicationException *tae = THRIFT_APPLICATION_EXCEPTION (object);
|
||||
|
||||
if (tae->__isset_message) {
|
||||
g_free(tae->message);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
thrift_application_exception_class_init (ThriftApplicationExceptionClass *class)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS(class);
|
||||
ThriftStructClass *cls = THRIFT_STRUCT_CLASS(class);
|
||||
GParamSpec *param_spec;
|
||||
|
||||
cls->read = thrift_application_exception_read;
|
||||
cls->write = thrift_application_exception_write;
|
||||
|
||||
gobject_class->finalize = thrift_application_exception_finalize;
|
||||
gobject_class->get_property = thrift_application_exception_get_property;
|
||||
gobject_class->set_property = thrift_application_exception_set_property;
|
||||
|
||||
param_spec = g_param_spec_int ("type",
|
||||
"Exception type",
|
||||
"The type of the exception, one of the "
|
||||
"values defined by the "
|
||||
"ThriftApplicationExceptionError "
|
||||
"enumeration.",
|
||||
0,
|
||||
THRIFT_APPLICATION_EXCEPTION_ERROR_N - 1,
|
||||
0,
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_APPLICATION_EXCEPTION_TYPE,
|
||||
param_spec);
|
||||
|
||||
param_spec = g_param_spec_string ("message",
|
||||
"Exception message",
|
||||
"A string describing the exception that "
|
||||
"occurred.",
|
||||
NULL,
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_APPLICATION_EXCEPTION_MESSAGE,
|
||||
param_spec);
|
||||
}
|
||||
86
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/thrift_application_exception.h
generated
vendored
Normal file
86
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/thrift_application_exception.h
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_APPLICATION_EXCEPTION_H
|
||||
#define _THRIFT_APPLICATION_EXCEPTION_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include "thrift_struct.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_application_exception.h
|
||||
* \brief C Implementation of a TApplicationException.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_APPLICATION_EXCEPTION (thrift_application_exception_get_type ())
|
||||
#define THRIFT_APPLICATION_EXCEPTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_APPLICATION_EXCEPTION, ThriftApplicationException))
|
||||
#define THRIFT_IS_APPLICATION_EXCEPTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_APPLICATION_EXCEPTION))
|
||||
#define THRIFT_APPLICATION_EXCEPTION_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_APPLICATION_EXCEPTION, ThriftApplicationExceptionClass))
|
||||
#define THRIFT_IS_APPLICATION_EXCEPTION_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_APPLICATION_EXCEPTION))
|
||||
#define THRIFT_APPLICATION_EXCEPTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_APPLICATION_EXCEPTION, ThriftApplicationExceptionClass))
|
||||
|
||||
typedef struct _ThriftApplicationException ThriftApplicationException;
|
||||
|
||||
struct _ThriftApplicationException
|
||||
{
|
||||
ThriftStruct parent;
|
||||
|
||||
/* private */
|
||||
gint32 type;
|
||||
gboolean __isset_type;
|
||||
gchar *message;
|
||||
gboolean __isset_message;
|
||||
};
|
||||
|
||||
typedef struct _ThriftApplicationExceptionClass ThriftApplicationExceptionClass;
|
||||
|
||||
struct _ThriftApplicationExceptionClass
|
||||
{
|
||||
ThriftStructClass parent;
|
||||
};
|
||||
|
||||
GType thrift_application_exception_get_type (void);
|
||||
|
||||
/* gerror codes */
|
||||
typedef enum
|
||||
{
|
||||
THRIFT_APPLICATION_EXCEPTION_ERROR_UNKNOWN,
|
||||
THRIFT_APPLICATION_EXCEPTION_ERROR_UNKNOWN_METHOD,
|
||||
THRIFT_APPLICATION_EXCEPTION_ERROR_INVALID_MESSAGE_TYPE,
|
||||
THRIFT_APPLICATION_EXCEPTION_ERROR_WRONG_METHOD_NAME,
|
||||
THRIFT_APPLICATION_EXCEPTION_ERROR_BAD_SEQUENCE_ID,
|
||||
THRIFT_APPLICATION_EXCEPTION_ERROR_MISSING_RESULT,
|
||||
THRIFT_APPLICATION_EXCEPTION_ERROR_INTERNAL_ERROR,
|
||||
THRIFT_APPLICATION_EXCEPTION_ERROR_PROTOCOL_ERROR,
|
||||
THRIFT_APPLICATION_EXCEPTION_ERROR_INVALID_TRANSFORM,
|
||||
THRIFT_APPLICATION_EXCEPTION_ERROR_INVALID_PROTOCOL,
|
||||
THRIFT_APPLICATION_EXCEPTION_ERROR_UNSUPPORTED_CLIENT_TYPE,
|
||||
|
||||
THRIFT_APPLICATION_EXCEPTION_ERROR_N
|
||||
} ThriftApplicationExceptionError;
|
||||
|
||||
/* define error domain for GError */
|
||||
GQuark thrift_application_exception_error_quark (void);
|
||||
#define THRIFT_APPLICATION_EXCEPTION_ERROR (thrift_application_exception_error_quark ())
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_APPLICATION_EXCEPTION_H */
|
||||
52
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/thrift_struct.c
generated
vendored
Normal file
52
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/thrift_struct.c
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include "thrift_struct.h"
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE(ThriftStruct, thrift_struct, G_TYPE_OBJECT)
|
||||
|
||||
gint32
|
||||
thrift_struct_read (ThriftStruct *object, ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (THRIFT_IS_STRUCT (object), -1);
|
||||
return THRIFT_STRUCT_GET_CLASS (object)->read (object, protocol, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_struct_write (ThriftStruct *object, ThriftProtocol *protocol,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (THRIFT_IS_STRUCT (object), -1);
|
||||
return THRIFT_STRUCT_GET_CLASS (object)->write (object, protocol, error);
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_struct_class_init (ThriftStructClass *cls)
|
||||
{
|
||||
cls->read = thrift_struct_read;
|
||||
cls->write = thrift_struct_write;
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_struct_init (ThriftStruct *structure)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (structure);
|
||||
}
|
||||
68
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/thrift_struct.h
generated
vendored
Normal file
68
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/thrift_struct.h
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef THRIFT_STRUCT_H
|
||||
#define THRIFT_STRUCT_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/protocol/thrift_protocol.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define THRIFT_TYPE_STRUCT (thrift_struct_get_type ())
|
||||
#define THRIFT_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_STRUCT, ThriftStruct))
|
||||
#define THRIFT_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_STRUCT, ThriftStructClass))
|
||||
#define THRIFT_IS_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_STRUCT))
|
||||
#define THRIFT_IS_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_STRUCT))
|
||||
#define THRIFT_STRUCT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_STRUCT, ThriftStructClass))
|
||||
|
||||
typedef struct _ThriftStruct ThriftStruct;
|
||||
|
||||
/* struct */
|
||||
struct _ThriftStruct
|
||||
{
|
||||
GObject parent;
|
||||
|
||||
/* private */
|
||||
};
|
||||
|
||||
typedef struct _ThriftStructClass ThriftStructClass;
|
||||
|
||||
struct _ThriftStructClass
|
||||
{
|
||||
GObjectClass parent;
|
||||
|
||||
/* public */
|
||||
gint32 (*read) (ThriftStruct *object, ThriftProtocol *protocol,
|
||||
GError **error);
|
||||
gint32 (*write) (ThriftStruct *object, ThriftProtocol *protocol,
|
||||
GError **error);
|
||||
};
|
||||
|
||||
GType thrift_struct_get_type (void);
|
||||
|
||||
gint32 thrift_struct_read (ThriftStruct *object, ThriftProtocol *protocol,
|
||||
GError **error);
|
||||
|
||||
gint32 thrift_struct_write (ThriftStruct *object, ThriftProtocol *protocol,
|
||||
GError **error);
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
391
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_buffered_transport.c
generated
vendored
Normal file
391
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_buffered_transport.c
generated
vendored
Normal file
@@ -0,0 +1,391 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_buffered_transport.h>
|
||||
|
||||
/* object properties */
|
||||
enum _ThriftBufferedTransportProperties
|
||||
{
|
||||
PROP_0,
|
||||
PROP_THRIFT_BUFFERED_TRANSPORT_TRANSPORT,
|
||||
PROP_THRIFT_BUFFERED_TRANSPORT_READ_BUFFER_SIZE,
|
||||
PROP_THRIFT_BUFFERED_TRANSPORT_WRITE_BUFFER_SIZE
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ThriftBufferedTransport, thrift_buffered_transport, THRIFT_TYPE_TRANSPORT)
|
||||
|
||||
/* implements thrift_transport_is_open */
|
||||
gboolean
|
||||
thrift_buffered_transport_is_open (ThriftTransport *transport)
|
||||
{
|
||||
ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
|
||||
return THRIFT_TRANSPORT_GET_CLASS (t->transport)->is_open (t->transport);
|
||||
}
|
||||
|
||||
/* overrides thrift_transport_peek */
|
||||
gboolean
|
||||
thrift_buffered_transport_peek (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
|
||||
return (t->r_buf->len > 0) || thrift_transport_peek (t->transport, error);
|
||||
}
|
||||
|
||||
/* implements thrift_transport_open */
|
||||
gboolean
|
||||
thrift_buffered_transport_open (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
|
||||
return THRIFT_TRANSPORT_GET_CLASS (t->transport)->open (t->transport, error);
|
||||
}
|
||||
|
||||
/* implements thrift_transport_close */
|
||||
gboolean
|
||||
thrift_buffered_transport_close (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
|
||||
return THRIFT_TRANSPORT_GET_CLASS (t->transport)->close (t->transport, error);
|
||||
}
|
||||
|
||||
/* the actual read is "slow" because it calls the underlying transport */
|
||||
gint32
|
||||
thrift_buffered_transport_read_slow (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error)
|
||||
{
|
||||
ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
|
||||
gint ret = 0;
|
||||
guint32 want = len;
|
||||
guint32 got = 0;
|
||||
guchar *tmpdata = g_alloca (len);
|
||||
guint32 have = t->r_buf->len;
|
||||
|
||||
/* we shouldn't hit this unless the buffer doesn't have enough to read */
|
||||
assert (t->r_buf->len < want);
|
||||
|
||||
/* first copy what we have in our buffer. */
|
||||
if (have > 0)
|
||||
{
|
||||
memcpy (buf, t->r_buf, t->r_buf->len);
|
||||
want -= t->r_buf->len;
|
||||
t->r_buf = g_byte_array_remove_range (t->r_buf, 0, t->r_buf->len);
|
||||
}
|
||||
|
||||
/* if the buffer is still smaller than what we want to read, then just
|
||||
* read it directly. otherwise, fill the buffer and then give out
|
||||
* enough to satisfy the read. */
|
||||
if (t->r_buf_size < want)
|
||||
{
|
||||
if ((ret = THRIFT_TRANSPORT_GET_CLASS (t->transport)->read (t->transport,
|
||||
tmpdata,
|
||||
want,
|
||||
error)) < 0) {
|
||||
return ret;
|
||||
}
|
||||
got += ret;
|
||||
|
||||
/* copy the data starting from where we left off */
|
||||
memcpy ((guint8 *)buf + have, tmpdata, got);
|
||||
return got + have;
|
||||
} else {
|
||||
guint32 give;
|
||||
|
||||
if ((ret = THRIFT_TRANSPORT_GET_CLASS (t->transport)->read (t->transport,
|
||||
tmpdata,
|
||||
want,
|
||||
error)) < 0) {
|
||||
return ret;
|
||||
}
|
||||
got += ret;
|
||||
t->r_buf = g_byte_array_append (t->r_buf, tmpdata, got);
|
||||
|
||||
/* hand over what we have up to what the caller wants */
|
||||
give = want < t->r_buf->len ? want : t->r_buf->len;
|
||||
|
||||
|
||||
memcpy ((guint8 *)buf + len - want, t->r_buf->data, give);
|
||||
t->r_buf = g_byte_array_remove_range (t->r_buf, 0, give);
|
||||
want -= give;
|
||||
|
||||
return (len - want);
|
||||
}
|
||||
}
|
||||
|
||||
/* implements thrift_transport_read */
|
||||
gint32
|
||||
thrift_buffered_transport_read (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error)
|
||||
{
|
||||
ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
|
||||
|
||||
/* if we have enough buffer data to fulfill the read, just use
|
||||
* a memcpy */
|
||||
if (len <= t->r_buf->len)
|
||||
{
|
||||
memcpy (buf, t->r_buf->data, len);
|
||||
g_byte_array_remove_range (t->r_buf, 0, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
return thrift_buffered_transport_read_slow (transport, buf, len, error);
|
||||
}
|
||||
|
||||
/* implements thrift_transport_read_end
|
||||
* called when write is complete. nothing to do on our end. */
|
||||
gboolean
|
||||
thrift_buffered_transport_read_end (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
/* satisfy -Wall */
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
thrift_buffered_transport_write_slow (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error)
|
||||
{
|
||||
ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
|
||||
guint32 have_bytes = t->w_buf->len;
|
||||
guint32 space = t->w_buf_size - t->w_buf->len;
|
||||
|
||||
/* we need two syscalls because the buffered data plus the buffer itself
|
||||
* is too big. */
|
||||
if ((have_bytes + len >= 2*t->w_buf_size) || (have_bytes == 0))
|
||||
{
|
||||
if (have_bytes > 0)
|
||||
{
|
||||
if (!THRIFT_TRANSPORT_GET_CLASS (t->transport)->write (t->transport,
|
||||
t->w_buf->data,
|
||||
have_bytes,
|
||||
error)) {
|
||||
return FALSE;
|
||||
}
|
||||
t->w_buf = g_byte_array_remove_range (t->w_buf, 0, have_bytes);
|
||||
}
|
||||
if (!THRIFT_TRANSPORT_GET_CLASS (t->transport)->write (t->transport,
|
||||
buf, len, error)) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
t->w_buf = g_byte_array_append (t->w_buf, buf, space);
|
||||
if (!THRIFT_TRANSPORT_GET_CLASS (t->transport)->write (t->transport,
|
||||
t->w_buf->data,
|
||||
t->w_buf->len,
|
||||
error)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
t->w_buf = g_byte_array_remove_range (t->w_buf, 0, t->w_buf->len);
|
||||
t->w_buf = g_byte_array_append (t->w_buf, (guint8 *)buf + space, len-space);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_write */
|
||||
gboolean
|
||||
thrift_buffered_transport_write (ThriftTransport *transport,
|
||||
const gpointer buf,
|
||||
const guint32 len, GError **error)
|
||||
{
|
||||
ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
|
||||
|
||||
/* the length of the current buffer plus the length of the data being read */
|
||||
if (t->w_buf->len + len <= t->w_buf_size)
|
||||
{
|
||||
t->w_buf = g_byte_array_append (t->w_buf, buf, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
return thrift_buffered_transport_write_slow (transport, buf, len, error);
|
||||
}
|
||||
|
||||
/* implements thrift_transport_write_end
|
||||
* called when write is complete. nothing to do on our end. */
|
||||
gboolean
|
||||
thrift_buffered_transport_write_end (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
/* satisfy -Wall */
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_flush */
|
||||
gboolean
|
||||
thrift_buffered_transport_flush (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
|
||||
|
||||
if (t->w_buf != NULL && t->w_buf->len > 0)
|
||||
{
|
||||
/* write the buffer and then empty it */
|
||||
if (!THRIFT_TRANSPORT_GET_CLASS (t->transport)->write (t->transport,
|
||||
t->w_buf->data,
|
||||
t->w_buf->len,
|
||||
error)) {
|
||||
return FALSE;
|
||||
}
|
||||
t->w_buf = g_byte_array_remove_range (t->w_buf, 0, t->w_buf->len);
|
||||
}
|
||||
THRIFT_TRANSPORT_GET_CLASS (t->transport)->flush (t->transport,
|
||||
error);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* initializes the instance */
|
||||
static void
|
||||
thrift_buffered_transport_init (ThriftBufferedTransport *transport)
|
||||
{
|
||||
transport->transport = NULL;
|
||||
transport->r_buf = g_byte_array_new ();
|
||||
transport->w_buf = g_byte_array_new ();
|
||||
}
|
||||
|
||||
/* destructor */
|
||||
static void
|
||||
thrift_buffered_transport_finalize (GObject *object)
|
||||
{
|
||||
ThriftBufferedTransport *transport = THRIFT_BUFFERED_TRANSPORT (object);
|
||||
|
||||
if (transport->r_buf != NULL)
|
||||
{
|
||||
g_byte_array_free (transport->r_buf, TRUE);
|
||||
}
|
||||
transport->r_buf = NULL;
|
||||
|
||||
if (transport->w_buf != NULL)
|
||||
{
|
||||
g_byte_array_free (transport->w_buf, TRUE);
|
||||
}
|
||||
transport->w_buf = NULL;
|
||||
}
|
||||
|
||||
/* property accessor */
|
||||
void
|
||||
thrift_buffered_transport_get_property (GObject *object, guint property_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftBufferedTransport *transport = THRIFT_BUFFERED_TRANSPORT (object);
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_BUFFERED_TRANSPORT_TRANSPORT:
|
||||
g_value_set_object (value, transport->transport);
|
||||
break;
|
||||
case PROP_THRIFT_BUFFERED_TRANSPORT_READ_BUFFER_SIZE:
|
||||
g_value_set_uint (value, transport->r_buf_size);
|
||||
break;
|
||||
case PROP_THRIFT_BUFFERED_TRANSPORT_WRITE_BUFFER_SIZE:
|
||||
g_value_set_uint (value, transport->w_buf_size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* property mutator */
|
||||
void
|
||||
thrift_buffered_transport_set_property (GObject *object, guint property_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftBufferedTransport *transport = THRIFT_BUFFERED_TRANSPORT (object);
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_BUFFERED_TRANSPORT_TRANSPORT:
|
||||
transport->transport = g_value_get_object (value);
|
||||
break;
|
||||
case PROP_THRIFT_BUFFERED_TRANSPORT_READ_BUFFER_SIZE:
|
||||
transport->r_buf_size = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_THRIFT_BUFFERED_TRANSPORT_WRITE_BUFFER_SIZE:
|
||||
transport->w_buf_size = g_value_get_uint (value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* initializes the class */
|
||||
static void
|
||||
thrift_buffered_transport_class_init (ThriftBufferedTransportClass *cls)
|
||||
{
|
||||
ThriftTransportClass *ttc = THRIFT_TRANSPORT_CLASS (cls);
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
|
||||
GParamSpec *param_spec = NULL;
|
||||
|
||||
/* setup accessors and mutators */
|
||||
gobject_class->get_property = thrift_buffered_transport_get_property;
|
||||
gobject_class->set_property = thrift_buffered_transport_set_property;
|
||||
|
||||
param_spec = g_param_spec_object ("transport", "transport (construct)",
|
||||
"Thrift transport",
|
||||
THRIFT_TYPE_TRANSPORT,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_BUFFERED_TRANSPORT_TRANSPORT,
|
||||
param_spec);
|
||||
|
||||
param_spec = g_param_spec_uint ("r_buf_size",
|
||||
"read buffer size (construct)",
|
||||
"Set the read buffer size",
|
||||
0, /* min */
|
||||
1048576, /* max, 1024*1024 */
|
||||
512, /* default value */
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_BUFFERED_TRANSPORT_READ_BUFFER_SIZE,
|
||||
param_spec);
|
||||
|
||||
param_spec = g_param_spec_uint ("w_buf_size",
|
||||
"write buffer size (construct)",
|
||||
"Set the write buffer size",
|
||||
0, /* min */
|
||||
1048576, /* max, 1024*1024 */
|
||||
512, /* default value */
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_BUFFERED_TRANSPORT_WRITE_BUFFER_SIZE,
|
||||
param_spec);
|
||||
|
||||
|
||||
gobject_class->finalize = thrift_buffered_transport_finalize;
|
||||
ttc->is_open = thrift_buffered_transport_is_open;
|
||||
ttc->peek = thrift_buffered_transport_peek;
|
||||
ttc->open = thrift_buffered_transport_open;
|
||||
ttc->close = thrift_buffered_transport_close;
|
||||
ttc->read = thrift_buffered_transport_read;
|
||||
ttc->read_end = thrift_buffered_transport_read_end;
|
||||
ttc->write = thrift_buffered_transport_write;
|
||||
ttc->write_end = thrift_buffered_transport_write_end;
|
||||
ttc->flush = thrift_buffered_transport_flush;
|
||||
}
|
||||
77
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_buffered_transport.h
generated
vendored
Normal file
77
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_buffered_transport.h
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_BUFFERED_TRANSPORT_H
|
||||
#define _THRIFT_BUFFERED_TRANSPORT_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_buffered_transport.h
|
||||
* \brief Implementation of a Thrift buffered transport. Subclasses
|
||||
* the ThriftTransport class.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_BUFFERED_TRANSPORT (thrift_buffered_transport_get_type ())
|
||||
#define THRIFT_BUFFERED_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_BUFFERED_TRANSPORT, ThriftBufferedTransport))
|
||||
#define THRIFT_IS_BUFFERED_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_BUFFERED_TRANSPORT))
|
||||
#define THRIFT_BUFFERED_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_BUFFERED_TRANSPORT, ThriftBufferedTransportClass))
|
||||
#define THRIFT_IS_BUFFERED_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_BUFFERED_TRANSPORT)
|
||||
#define THRIFT_BUFFERED_TRANSPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_BUFFERED_TRANSPORT, ThriftBufferedTransportClass))
|
||||
|
||||
typedef struct _ThriftBufferedTransport ThriftBufferedTransport;
|
||||
|
||||
/*!
|
||||
* ThriftBufferedTransport instance.
|
||||
*/
|
||||
struct _ThriftBufferedTransport
|
||||
{
|
||||
ThriftTransport parent;
|
||||
|
||||
/* protected */
|
||||
ThriftTransport *transport;
|
||||
|
||||
/* private */
|
||||
GByteArray *r_buf;
|
||||
GByteArray *w_buf;
|
||||
guint32 r_buf_size;
|
||||
guint32 w_buf_size;
|
||||
};
|
||||
|
||||
typedef struct _ThriftBufferedTransportClass ThriftBufferedTransportClass;
|
||||
|
||||
/*!
|
||||
* ThriftBufferedTransport class.
|
||||
*/
|
||||
struct _ThriftBufferedTransportClass
|
||||
{
|
||||
ThriftTransportClass parent;
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_BUFFERED_TRANSPORT */
|
||||
GType thrift_buffered_transport_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
55
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_buffered_transport_factory.c
generated
vendored
Normal file
55
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_buffered_transport_factory.c
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/transport/thrift_buffered_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_buffered_transport_factory.h>
|
||||
|
||||
G_DEFINE_TYPE (ThriftBufferedTransportFactory,
|
||||
thrift_buffered_transport_factory,
|
||||
THRIFT_TYPE_TRANSPORT_FACTORY)
|
||||
|
||||
/* Wraps a transport with a ThriftBufferedTransport. */
|
||||
ThriftTransport *
|
||||
thrift_buffered_transport_factory_get_transport (ThriftTransportFactory *factory,
|
||||
ThriftTransport *transport)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (factory);
|
||||
|
||||
return THRIFT_TRANSPORT (g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT,
|
||||
"transport", transport,
|
||||
NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_buffered_transport_factory_init (ThriftBufferedTransportFactory *self)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (self);
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_buffered_transport_factory_class_init (ThriftBufferedTransportFactoryClass *klass)
|
||||
{
|
||||
ThriftTransportFactoryClass *base_class =
|
||||
THRIFT_TRANSPORT_FACTORY_CLASS (klass);
|
||||
|
||||
base_class->get_transport =
|
||||
klass->get_transport =
|
||||
thrift_buffered_transport_factory_get_transport;
|
||||
}
|
||||
86
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_buffered_transport_factory.h
generated
vendored
Normal file
86
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_buffered_transport_factory.h
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_BUFFERED_TRANSPORT_FACTORY_H
|
||||
#define _THRIFT_BUFFERED_TRANSPORT_FACTORY_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport_factory.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_buffered_transport_factory.h
|
||||
* \brief Wraps a transport with a ThriftBufferedTransport.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_BUFFERED_TRANSPORT_FACTORY \
|
||||
(thrift_buffered_transport_factory_get_type ())
|
||||
#define THRIFT_BUFFERED_TRANSPORT_FACTORY(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
|
||||
THRIFT_TYPE_BUFFERED_TRANSPORT_FACTORY, \
|
||||
ThriftBufferedTransportFactory))
|
||||
#define THRIFT_IS_BUFFERED_TRANSPORT_FACTORY(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
|
||||
THRIFT_TYPE_BUFFERED_TRANSPORT_FACTORY))
|
||||
#define THRIFT_BUFFERED_TRANSPORT_FACTORY_CLASS(c) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((c), \
|
||||
THRIFT_TYPE_BUFFERED_TRANSPORT_FACTORY, \
|
||||
ThriftBufferedTransportFactoryClass))
|
||||
#define THRIFT_IS_BUFFERED_TRANSPORT_FACTORY_CLASS(c) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((c), \
|
||||
THRIFT_TYPE_BUFFERED_TRANSPORT_FACTORY))
|
||||
#define THRIFT_BUFFERED_TRANSPORT_FACTORY_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
|
||||
THRIFT_TYPE_BUFFERED_TRANSPORT_FACTORY, \
|
||||
ThriftBufferedTransportFactoryClass))
|
||||
|
||||
typedef struct _ThriftBufferedTransportFactory ThriftBufferedTransportFactory;
|
||||
|
||||
/* Thrift Buffered-Transport Factory instance */
|
||||
struct _ThriftBufferedTransportFactory
|
||||
{
|
||||
ThriftTransportFactory parent;
|
||||
};
|
||||
|
||||
typedef struct _ThriftBufferedTransportFactoryClass ThriftBufferedTransportFactoryClass;
|
||||
|
||||
/* Thrift Buffered-Transport Factory class */
|
||||
struct _ThriftBufferedTransportFactoryClass
|
||||
{
|
||||
ThriftTransportFactoryClass parent;
|
||||
|
||||
/* vtable */
|
||||
ThriftTransport *(*get_transport) (ThriftTransportFactory *factory,
|
||||
ThriftTransport *transport);
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_BUFFERED_TRANSPORT_FACTORY */
|
||||
GType thrift_buffered_transport_factory_get_type (void);
|
||||
|
||||
/* virtual public methods */
|
||||
ThriftTransport *
|
||||
thrift_buffered_transport_factory_get_transport (ThriftTransportFactory *factory,
|
||||
ThriftTransport *transport);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_BUFFERED_TRANSPORT_FACTORY_H */
|
||||
265
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_fd_transport.c
generated
vendored
Normal file
265
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_fd_transport.c
generated
vendored
Normal file
@@ -0,0 +1,265 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_fd_transport.h>
|
||||
|
||||
/* object properties */
|
||||
enum _ThriftFDTransportProperties
|
||||
{
|
||||
PROP_0,
|
||||
PROP_THRIFT_FD_TRANSPORT_FD
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (ThriftFDTransport, thrift_fd_transport, THRIFT_TYPE_TRANSPORT)
|
||||
|
||||
/* implements thrift_transport_is_open */
|
||||
gboolean
|
||||
thrift_fd_transport_is_open (ThriftTransport *transport)
|
||||
{
|
||||
ThriftFDTransport *t;
|
||||
t = THRIFT_FD_TRANSPORT (transport);
|
||||
return t->fd >= 0 && ! (fcntl (t->fd, F_GETFL) == -1 && errno == EBADF);
|
||||
}
|
||||
|
||||
/* implements thrift_transport_open */
|
||||
gboolean
|
||||
thrift_fd_transport_open (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return thrift_fd_transport_is_open (transport);
|
||||
}
|
||||
|
||||
/* implements thrift_transport_close */
|
||||
gboolean
|
||||
thrift_fd_transport_close (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
ThriftFDTransport *t;
|
||||
t = THRIFT_FD_TRANSPORT (transport);
|
||||
|
||||
#if GLIB_CHECK_VERSION (2, 36, 0)
|
||||
return g_close (t->fd, error);
|
||||
#else
|
||||
if (close (t->fd) == 0) {
|
||||
g_clear_error (error);
|
||||
return TRUE;
|
||||
} else {
|
||||
g_set_error (error,
|
||||
THRIFT_TRANSPORT_ERROR,
|
||||
THRIFT_TRANSPORT_ERROR_CLOSE,
|
||||
strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* implements thrift_transport_read */
|
||||
gint32
|
||||
thrift_fd_transport_read (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error)
|
||||
{
|
||||
ThriftFDTransport *t;
|
||||
ssize_t n;
|
||||
|
||||
t = THRIFT_FD_TRANSPORT (transport);
|
||||
n = read (t->fd, (guint8 *) buf, len);
|
||||
if (n == -1) {
|
||||
g_set_error (error,
|
||||
THRIFT_TRANSPORT_ERROR,
|
||||
THRIFT_TRANSPORT_ERROR_RECEIVE,
|
||||
"Failed to read from fd: %s",
|
||||
strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_read_end
|
||||
* called when write is complete. nothing to do on our end. */
|
||||
gboolean
|
||||
thrift_fd_transport_read_end (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
/* satisfy -Wall */
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_write */
|
||||
gboolean
|
||||
thrift_fd_transport_write (ThriftTransport *transport,
|
||||
const gpointer buf,
|
||||
const guint32 len, GError **error)
|
||||
{
|
||||
ThriftFDTransport *t;
|
||||
guint8 *_buf;
|
||||
guint32 _len;
|
||||
ssize_t n;
|
||||
|
||||
t = THRIFT_FD_TRANSPORT (transport);
|
||||
_buf = (guint8 *) buf;
|
||||
_len = len;
|
||||
while (_len > 0) {
|
||||
n = write (t->fd, _buf, _len);
|
||||
if (n == -1) {
|
||||
g_set_error (error,
|
||||
THRIFT_TRANSPORT_ERROR,
|
||||
THRIFT_TRANSPORT_ERROR_SEND,
|
||||
"Failed to write from fd: %s",
|
||||
strerror (errno));
|
||||
return FALSE;
|
||||
} else {
|
||||
_buf += n;
|
||||
_len -= n;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_write_end
|
||||
* called when write is complete. nothing to do on our end. */
|
||||
gboolean
|
||||
thrift_fd_transport_write_end (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_flush */
|
||||
gboolean
|
||||
thrift_fd_transport_flush (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
ThriftFDTransport *t;
|
||||
t = THRIFT_FD_TRANSPORT (transport);
|
||||
if (fsync (t->fd) == -1) {
|
||||
g_set_error (error,
|
||||
THRIFT_TRANSPORT_ERROR,
|
||||
THRIFT_TRANSPORT_ERROR_UNKNOWN,
|
||||
"Failed to flush fd: %s",
|
||||
strerror (errno));
|
||||
return FALSE;
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* initializes the instance */
|
||||
static void
|
||||
thrift_fd_transport_init (ThriftFDTransport *transport)
|
||||
{
|
||||
transport->fd = -1;
|
||||
}
|
||||
|
||||
/* destructor */
|
||||
static void
|
||||
thrift_fd_transport_finalize (GObject *object)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (object);
|
||||
}
|
||||
|
||||
/* property accessor */
|
||||
void
|
||||
thrift_fd_transport_get_property (GObject *object, guint property_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftFDTransport *t;
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
t = THRIFT_FD_TRANSPORT (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_THRIFT_FD_TRANSPORT_FD:
|
||||
g_value_set_int (value, t->fd);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* property mutator */
|
||||
void
|
||||
thrift_fd_transport_set_property (GObject *object, guint property_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftFDTransport *t;
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
t = THRIFT_FD_TRANSPORT (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_THRIFT_FD_TRANSPORT_FD:
|
||||
t->fd = g_value_get_int (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* initializes the class */
|
||||
static void
|
||||
thrift_fd_transport_class_init (ThriftFDTransportClass *cls)
|
||||
{
|
||||
ThriftTransportClass *ttc;
|
||||
GObjectClass *gobject_class;
|
||||
GParamSpec *param_spec;
|
||||
|
||||
ttc = THRIFT_TRANSPORT_CLASS (cls);
|
||||
gobject_class = G_OBJECT_CLASS (cls);
|
||||
param_spec = NULL;
|
||||
|
||||
/* setup accessors and mutators */
|
||||
gobject_class->get_property = thrift_fd_transport_get_property;
|
||||
gobject_class->set_property = thrift_fd_transport_set_property;
|
||||
|
||||
param_spec = g_param_spec_int ("fd",
|
||||
"file descriptor (construct)",
|
||||
"Set the file descriptor",
|
||||
INT_MIN, /* min */
|
||||
INT_MAX, /* max, 1024*1024 */
|
||||
-1, /* default value */
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_FD_TRANSPORT_FD,
|
||||
param_spec);
|
||||
|
||||
gobject_class->finalize = thrift_fd_transport_finalize;
|
||||
ttc->is_open = thrift_fd_transport_is_open;
|
||||
ttc->open = thrift_fd_transport_open;
|
||||
ttc->close = thrift_fd_transport_close;
|
||||
ttc->read = thrift_fd_transport_read;
|
||||
ttc->read_end = thrift_fd_transport_read_end;
|
||||
ttc->write = thrift_fd_transport_write;
|
||||
ttc->write_end = thrift_fd_transport_write_end;
|
||||
ttc->flush = thrift_fd_transport_flush;
|
||||
}
|
||||
74
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_fd_transport.h
generated
vendored
Normal file
74
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_fd_transport.h
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_FD_TRANSPORT_H
|
||||
#define _THRIFT_FD_TRANSPORT_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "thrift_transport.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_fd_transport.h
|
||||
* \brief Class for Thrift file descriptor transports.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_FD_TRANSPORT (thrift_fd_transport_get_type ())
|
||||
#define THRIFT_FD_TRANSPORT(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_FD_TRANSPORT, \
|
||||
ThriftFDTransport))
|
||||
#define THRIFT_IS_FD_TRANSPORT(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_FD_TRANSPORT))
|
||||
#define THRIFT_FD_TRANSPORT_CLASS(c) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_FD_TRANSPORT, \
|
||||
ThriftFDTransportClass))
|
||||
#define THRIFT_IS_FD_TRANSPORT_CLASS(c) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_FD_TRANSPORT))
|
||||
#define THRIFT_FD_TRANSPORT_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_FD_TRANSPORT, \
|
||||
ThriftFDTransportClass))
|
||||
|
||||
typedef struct _ThriftFDTransport ThriftFDTransport;
|
||||
|
||||
struct _ThriftFDTransport
|
||||
{
|
||||
ThriftTransport parent;
|
||||
|
||||
/* protected */
|
||||
gint fd;
|
||||
};
|
||||
|
||||
typedef struct _ThriftFDTransportClass ThriftFDTransportClass;
|
||||
|
||||
/*!
|
||||
* Thrift Transport class
|
||||
*/
|
||||
struct _ThriftFDTransportClass
|
||||
{
|
||||
ThriftTransportClass parent;
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_FD_TRANSPORT */
|
||||
GType thrift_fd_transport_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_FD_TRANSPORT_H */
|
||||
384
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_framed_transport.c
generated
vendored
Normal file
384
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_framed_transport.c
generated
vendored
Normal file
@@ -0,0 +1,384 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_framed_transport.h>
|
||||
|
||||
/* object properties */
|
||||
enum _ThriftFramedTransportProperties
|
||||
{
|
||||
PROP_0,
|
||||
PROP_THRIFT_FRAMED_TRANSPORT_TRANSPORT,
|
||||
PROP_THRIFT_FRAMED_TRANSPORT_READ_BUFFER_SIZE,
|
||||
PROP_THRIFT_FRAMED_TRANSPORT_WRITE_BUFFER_SIZE
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ThriftFramedTransport, thrift_framed_transport, THRIFT_TYPE_TRANSPORT)
|
||||
|
||||
/* implements thrift_transport_is_open */
|
||||
gboolean
|
||||
thrift_framed_transport_is_open (ThriftTransport *transport)
|
||||
{
|
||||
ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
|
||||
return THRIFT_TRANSPORT_GET_CLASS (t->transport)->is_open (t->transport);
|
||||
}
|
||||
|
||||
/* overrides thrift_transport_peek */
|
||||
gboolean
|
||||
thrift_framed_transport_peek (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
|
||||
return (t->r_buf->len > 0) || thrift_transport_peek (t->transport, error);
|
||||
}
|
||||
|
||||
/* implements thrift_transport_open */
|
||||
gboolean
|
||||
thrift_framed_transport_open (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
|
||||
return THRIFT_TRANSPORT_GET_CLASS (t->transport)->open (t->transport, error);
|
||||
}
|
||||
|
||||
/* implements thrift_transport_close */
|
||||
gboolean
|
||||
thrift_framed_transport_close (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
|
||||
return THRIFT_TRANSPORT_GET_CLASS (t->transport)->close (t->transport, error);
|
||||
}
|
||||
|
||||
/* reads a frame and puts it into the buffer */
|
||||
gboolean
|
||||
thrift_framed_transport_read_frame (ThriftTransport *transport,
|
||||
GError **error)
|
||||
{
|
||||
ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
|
||||
guint32 sz;
|
||||
gint32 bytes;
|
||||
gboolean result = FALSE;
|
||||
|
||||
/* read the size */
|
||||
if (thrift_transport_read (t->transport,
|
||||
&sz,
|
||||
sizeof (sz),
|
||||
error) == sizeof (sz))
|
||||
{
|
||||
guchar *tmpdata;
|
||||
|
||||
sz = ntohl (sz);
|
||||
|
||||
/* create a buffer to hold the data and read that much data */
|
||||
tmpdata = g_alloca (sz);
|
||||
bytes = thrift_transport_read (t->transport, tmpdata, sz, error);
|
||||
|
||||
if (bytes > 0 && (error == NULL || *error == NULL))
|
||||
{
|
||||
/* add the data to the buffer */
|
||||
g_byte_array_append (t->r_buf, tmpdata, bytes);
|
||||
|
||||
result = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* the actual read is "slow" because it calls the underlying transport */
|
||||
gint32
|
||||
thrift_framed_transport_read_slow (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error)
|
||||
{
|
||||
ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
|
||||
guint32 want = len;
|
||||
guint32 have = t->r_buf->len;
|
||||
gint32 result = -1;
|
||||
|
||||
/* we shouldn't hit this unless the buffer doesn't have enough to read */
|
||||
assert (t->r_buf->len < want);
|
||||
|
||||
/* first copy what we have in our buffer, if there is anything left */
|
||||
if (have > 0)
|
||||
{
|
||||
memcpy (buf, t->r_buf, t->r_buf->len);
|
||||
want -= t->r_buf->len;
|
||||
t->r_buf = g_byte_array_remove_range (t->r_buf, 0, t->r_buf->len);
|
||||
}
|
||||
|
||||
/* read a frame of input and buffer it */
|
||||
if (thrift_framed_transport_read_frame (transport, error) == TRUE)
|
||||
{
|
||||
/* hand over what we have up to what the caller wants */
|
||||
guint32 give = want < t->r_buf->len ? want : t->r_buf->len;
|
||||
|
||||
/* copy the data into the buffer */
|
||||
memcpy ((guint8 *)buf + len - want, t->r_buf->data, give);
|
||||
t->r_buf = g_byte_array_remove_range (t->r_buf, 0, give);
|
||||
want -= give;
|
||||
|
||||
result = len - want;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_read */
|
||||
gint32
|
||||
thrift_framed_transport_read (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error)
|
||||
{
|
||||
ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
|
||||
|
||||
/* if we have enough buffer data to fulfill the read, just use
|
||||
* a memcpy from the buffer */
|
||||
if (len <= t->r_buf->len)
|
||||
{
|
||||
memcpy (buf, t->r_buf->data, len);
|
||||
g_byte_array_remove_range (t->r_buf, 0, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
return thrift_framed_transport_read_slow (transport, buf, len, error);
|
||||
}
|
||||
|
||||
/* implements thrift_transport_read_end
|
||||
* called when read is complete. nothing to do on our end. */
|
||||
gboolean
|
||||
thrift_framed_transport_read_end (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
/* satisfy -Wall */
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
thrift_framed_transport_write_slow (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error)
|
||||
{
|
||||
ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
|
||||
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
|
||||
/* append the data to the buffer and we're done */
|
||||
g_byte_array_append (t->w_buf, buf, len);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_write */
|
||||
gboolean
|
||||
thrift_framed_transport_write (ThriftTransport *transport,
|
||||
const gpointer buf,
|
||||
const guint32 len, GError **error)
|
||||
{
|
||||
ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
|
||||
|
||||
/* the length of the current buffer plus the length of the data being read */
|
||||
if (t->w_buf->len + len <= t->w_buf_size)
|
||||
{
|
||||
t->w_buf = g_byte_array_append (t->w_buf, buf, len);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return thrift_framed_transport_write_slow (transport, buf, len, error);
|
||||
}
|
||||
|
||||
/* implements thrift_transport_write_end
|
||||
* called when write is complete. nothing to do on our end. */
|
||||
gboolean
|
||||
thrift_framed_transport_write_end (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
/* satisfy -Wall */
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_flush */
|
||||
gboolean
|
||||
thrift_framed_transport_flush (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
|
||||
gint32 sz_hbo, sz_nbo;
|
||||
guchar *tmpdata;
|
||||
|
||||
/* get the size of the frame in host and network byte order */
|
||||
sz_hbo = t->w_buf->len + sizeof(sz_nbo);
|
||||
sz_nbo = (gint32) htonl ((guint32) t->w_buf->len);
|
||||
|
||||
/* copy the size of the frame and then the frame itself */
|
||||
tmpdata = g_alloca (sz_hbo);
|
||||
memcpy (tmpdata, (guint8 *) &sz_nbo, sizeof (sz_nbo));
|
||||
|
||||
if (t->w_buf->len > 0)
|
||||
{
|
||||
memcpy (tmpdata + sizeof (sz_nbo), t->w_buf->data, t->w_buf->len);
|
||||
t->w_buf = g_byte_array_remove_range (t->w_buf, 0, t->w_buf->len);
|
||||
}
|
||||
|
||||
/* write the buffer and then empty it */
|
||||
THRIFT_TRANSPORT_GET_CLASS (t->transport)->write (t->transport,
|
||||
tmpdata, sz_hbo,
|
||||
error);
|
||||
|
||||
THRIFT_TRANSPORT_GET_CLASS (t->transport)->flush (t->transport,
|
||||
error);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* initializes the instance */
|
||||
static void
|
||||
thrift_framed_transport_init (ThriftFramedTransport *transport)
|
||||
{
|
||||
transport->transport = NULL;
|
||||
transport->r_buf = g_byte_array_new ();
|
||||
transport->w_buf = g_byte_array_new ();
|
||||
}
|
||||
|
||||
/* destructor */
|
||||
static void
|
||||
thrift_framed_transport_finalize (GObject *object)
|
||||
{
|
||||
ThriftFramedTransport *transport = THRIFT_FRAMED_TRANSPORT (object);
|
||||
|
||||
if (transport->r_buf != NULL)
|
||||
{
|
||||
g_byte_array_free (transport->r_buf, TRUE);
|
||||
}
|
||||
transport->r_buf = NULL;
|
||||
|
||||
if (transport->w_buf != NULL)
|
||||
{
|
||||
g_byte_array_free (transport->w_buf, TRUE);
|
||||
}
|
||||
transport->w_buf = NULL;
|
||||
}
|
||||
|
||||
/* property accessor */
|
||||
void
|
||||
thrift_framed_transport_get_property (GObject *object, guint property_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftFramedTransport *transport = THRIFT_FRAMED_TRANSPORT (object);
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_FRAMED_TRANSPORT_TRANSPORT:
|
||||
g_value_set_object (value, transport->transport);
|
||||
break;
|
||||
case PROP_THRIFT_FRAMED_TRANSPORT_READ_BUFFER_SIZE:
|
||||
g_value_set_uint (value, transport->r_buf_size);
|
||||
break;
|
||||
case PROP_THRIFT_FRAMED_TRANSPORT_WRITE_BUFFER_SIZE:
|
||||
g_value_set_uint (value, transport->w_buf_size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* property mutator */
|
||||
void
|
||||
thrift_framed_transport_set_property (GObject *object, guint property_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftFramedTransport *transport = THRIFT_FRAMED_TRANSPORT (object);
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_FRAMED_TRANSPORT_TRANSPORT:
|
||||
transport->transport = g_value_get_object (value);
|
||||
break;
|
||||
case PROP_THRIFT_FRAMED_TRANSPORT_READ_BUFFER_SIZE:
|
||||
transport->r_buf_size = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_THRIFT_FRAMED_TRANSPORT_WRITE_BUFFER_SIZE:
|
||||
transport->w_buf_size = g_value_get_uint (value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* initializes the class */
|
||||
static void
|
||||
thrift_framed_transport_class_init (ThriftFramedTransportClass *cls)
|
||||
{
|
||||
ThriftTransportClass *ttc = THRIFT_TRANSPORT_CLASS (cls);
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
|
||||
GParamSpec *param_spec = NULL;
|
||||
|
||||
/* setup accessors and mutators */
|
||||
gobject_class->get_property = thrift_framed_transport_get_property;
|
||||
gobject_class->set_property = thrift_framed_transport_set_property;
|
||||
|
||||
param_spec = g_param_spec_object ("transport", "transport (construct)",
|
||||
"Thrift transport",
|
||||
THRIFT_TYPE_TRANSPORT,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_FRAMED_TRANSPORT_TRANSPORT,
|
||||
param_spec);
|
||||
|
||||
param_spec = g_param_spec_uint ("r_buf_size",
|
||||
"read buffer size (construct)",
|
||||
"Set the read buffer size",
|
||||
0, /* min */
|
||||
1048576, /* max, 1024*1024 */
|
||||
512, /* default value */
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_FRAMED_TRANSPORT_READ_BUFFER_SIZE,
|
||||
param_spec);
|
||||
|
||||
param_spec = g_param_spec_uint ("w_buf_size",
|
||||
"write buffer size (construct)",
|
||||
"Set the write buffer size",
|
||||
0, /* min */
|
||||
1048576, /* max, 1024*1024 */
|
||||
512, /* default value */
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_FRAMED_TRANSPORT_WRITE_BUFFER_SIZE,
|
||||
param_spec);
|
||||
|
||||
gobject_class->finalize = thrift_framed_transport_finalize;
|
||||
ttc->is_open = thrift_framed_transport_is_open;
|
||||
ttc->peek = thrift_framed_transport_peek;
|
||||
ttc->open = thrift_framed_transport_open;
|
||||
ttc->close = thrift_framed_transport_close;
|
||||
ttc->read = thrift_framed_transport_read;
|
||||
ttc->read_end = thrift_framed_transport_read_end;
|
||||
ttc->write = thrift_framed_transport_write;
|
||||
ttc->write_end = thrift_framed_transport_write_end;
|
||||
ttc->flush = thrift_framed_transport_flush;
|
||||
}
|
||||
77
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_framed_transport.h
generated
vendored
Normal file
77
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_framed_transport.h
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_FRAMED_TRANSPORT_H
|
||||
#define _THRIFT_FRAMED_TRANSPORT_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_framed_transport.h
|
||||
* \brief Implementation of a Thrift framed transport. Subclasses
|
||||
* the ThriftTransport class.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_FRAMED_TRANSPORT (thrift_framed_transport_get_type ())
|
||||
#define THRIFT_FRAMED_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_FRAMED_TRANSPORT, ThriftFramedTransport))
|
||||
#define THRIFT_IS_FRAMED_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_FRAMED_TRANSPORT))
|
||||
#define THRIFT_FRAMED_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_FRAMED_TRANSPORT, ThriftFramedTransportClass))
|
||||
#define THRIFT_IS_FRAMED_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_FRAMED_TRANSPORT)
|
||||
#define THRIFT_FRAMED_TRANSPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_FRAMED_TRANSPORT, ThriftFramedTransportClass))
|
||||
|
||||
typedef struct _ThriftFramedTransport ThriftFramedTransport;
|
||||
|
||||
/*!
|
||||
* ThriftFramedTransport instance.
|
||||
*/
|
||||
struct _ThriftFramedTransport
|
||||
{
|
||||
ThriftTransport parent;
|
||||
|
||||
/* protected */
|
||||
ThriftTransport *transport;
|
||||
|
||||
/* private */
|
||||
GByteArray *r_buf;
|
||||
GByteArray *w_buf;
|
||||
guint32 r_buf_size;
|
||||
guint32 w_buf_size;
|
||||
};
|
||||
|
||||
typedef struct _ThriftFramedTransportClass ThriftFramedTransportClass;
|
||||
|
||||
/*!
|
||||
* ThriftFramedTransport class.
|
||||
*/
|
||||
struct _ThriftFramedTransportClass
|
||||
{
|
||||
ThriftTransportClass parent;
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_FRAMED_TRANSPORT */
|
||||
GType thrift_framed_transport_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
55
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_framed_transport_factory.c
generated
vendored
Normal file
55
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_framed_transport_factory.c
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/transport/thrift_framed_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_framed_transport_factory.h>
|
||||
|
||||
G_DEFINE_TYPE (ThriftFramedTransportFactory,
|
||||
thrift_framed_transport_factory,
|
||||
THRIFT_TYPE_TRANSPORT_FACTORY)
|
||||
|
||||
/* Wraps a transport with a ThriftFramedTransport. */
|
||||
ThriftTransport *
|
||||
thrift_framed_transport_factory_get_transport (ThriftTransportFactory *factory,
|
||||
ThriftTransport *transport)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (factory);
|
||||
|
||||
return THRIFT_TRANSPORT (g_object_new (THRIFT_TYPE_FRAMED_TRANSPORT,
|
||||
"transport", transport,
|
||||
NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_framed_transport_factory_init (ThriftFramedTransportFactory *self)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (self);
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_framed_transport_factory_class_init (ThriftFramedTransportFactoryClass *klass)
|
||||
{
|
||||
ThriftTransportFactoryClass *base_class =
|
||||
THRIFT_TRANSPORT_FACTORY_CLASS (klass);
|
||||
|
||||
base_class->get_transport =
|
||||
klass->get_transport =
|
||||
thrift_framed_transport_factory_get_transport;
|
||||
}
|
||||
86
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_framed_transport_factory.h
generated
vendored
Normal file
86
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_framed_transport_factory.h
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_FRAMED_TRANSPORT_FACTORY_H
|
||||
#define _THRIFT_FRAMED_TRANSPORT_FACTORY_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport_factory.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_framed_transport_factory.h
|
||||
* \brief Wraps a transport with a ThriftFramedTransport.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_FRAMED_TRANSPORT_FACTORY \
|
||||
(thrift_framed_transport_factory_get_type ())
|
||||
#define THRIFT_FRAMED_TRANSPORT_FACTORY(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
|
||||
THRIFT_TYPE_FRAMED_TRANSPORT_FACTORY, \
|
||||
ThriftFramedTransportFactory))
|
||||
#define THRIFT_IS_FRAMED_TRANSPORT_FACTORY(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
|
||||
THRIFT_TYPE_FRAMED_TRANSPORT_FACTORY))
|
||||
#define THRIFT_FRAMED_TRANSPORT_FACTORY_CLASS(c) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((c), \
|
||||
THRIFT_TYPE_FRAMED_TRANSPORT_FACTORY, \
|
||||
ThriftFramedTransportFactoryClass))
|
||||
#define THRIFT_IS_FRAMED_TRANSPORT_FACTORY_CLASS(c) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((c), \
|
||||
THRIFT_TYPE_FRAMED_TRANSPORT_FACTORY))
|
||||
#define THRIFT_FRAMED_TRANSPORT_FACTORY_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
|
||||
THRIFT_TYPE_FRAMED_TRANSPORT_FACTORY, \
|
||||
ThriftFramedTransportFactoryClass))
|
||||
|
||||
typedef struct _ThriftFramedTransportFactory ThriftFramedTransportFactory;
|
||||
|
||||
/* Thrift Framed-Transport Factory instance */
|
||||
struct _ThriftFramedTransportFactory
|
||||
{
|
||||
ThriftTransportFactory parent;
|
||||
};
|
||||
|
||||
typedef struct _ThriftFramedTransportFactoryClass ThriftFramedTransportFactoryClass;
|
||||
|
||||
/* Thrift Framed-Transport Factory class */
|
||||
struct _ThriftFramedTransportFactoryClass
|
||||
{
|
||||
ThriftTransportFactoryClass parent;
|
||||
|
||||
/* vtable */
|
||||
ThriftTransport *(*get_transport) (ThriftTransportFactory *factory,
|
||||
ThriftTransport *transport);
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_FRAMED_TRANSPORT_FACTORY */
|
||||
GType thrift_framed_transport_factory_get_type (void);
|
||||
|
||||
/* virtual public methods */
|
||||
ThriftTransport *
|
||||
thrift_framed_transport_factory_get_transport (ThriftTransportFactory *factory,
|
||||
ThriftTransport *transport);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_FRAMED_TRANSPORT_FACTORY_H */
|
||||
286
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_memory_buffer.c
generated
vendored
Normal file
286
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_memory_buffer.c
generated
vendored
Normal file
@@ -0,0 +1,286 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_memory_buffer.h>
|
||||
|
||||
/* object properties */
|
||||
enum _ThriftMemoryBufferProperties
|
||||
{
|
||||
PROP_0,
|
||||
PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE,
|
||||
PROP_THRIFT_MEMORY_BUFFER_BUFFER,
|
||||
PROP_THRIFT_MEMORY_BUFFER_OWNER
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ThriftMemoryBuffer, thrift_memory_buffer, THRIFT_TYPE_TRANSPORT)
|
||||
|
||||
/* implements thrift_transport_is_open */
|
||||
gboolean
|
||||
thrift_memory_buffer_is_open (ThriftTransport *transport)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_open */
|
||||
gboolean
|
||||
thrift_memory_buffer_open (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_close */
|
||||
gboolean
|
||||
thrift_memory_buffer_close (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_read */
|
||||
gint32
|
||||
thrift_memory_buffer_read (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error)
|
||||
{
|
||||
ThriftMemoryBuffer *t = THRIFT_MEMORY_BUFFER (transport);
|
||||
guint32 give = len;
|
||||
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
|
||||
/* if the requested bytes are more than what we have available,
|
||||
* just give all that we have the buffer */
|
||||
if (t->buf->len < len)
|
||||
{
|
||||
give = t->buf->len;
|
||||
}
|
||||
|
||||
memcpy (buf, t->buf->data, give);
|
||||
g_byte_array_remove_range (t->buf, 0, give);
|
||||
|
||||
return give;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_read_end
|
||||
* called when read is complete. nothing to do on our end. */
|
||||
gboolean
|
||||
thrift_memory_buffer_read_end (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
/* satisfy -Wall */
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_write */
|
||||
gboolean
|
||||
thrift_memory_buffer_write (ThriftTransport *transport,
|
||||
const gpointer buf,
|
||||
const guint32 len, GError **error)
|
||||
{
|
||||
ThriftMemoryBuffer *t = THRIFT_MEMORY_BUFFER (transport);
|
||||
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
|
||||
/* return an exception if the buffer doesn't have enough space. */
|
||||
if (len > t->buf_size - t->buf->len)
|
||||
{
|
||||
g_set_error (error, THRIFT_TRANSPORT_ERROR, THRIFT_TRANSPORT_ERROR_SEND,
|
||||
"unable to write %d bytes to buffer of length %d",
|
||||
len, t->buf_size);
|
||||
return FALSE;
|
||||
} else {
|
||||
t->buf = g_byte_array_append (t->buf, buf, len);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* implements thrift_transport_write_end
|
||||
* called when write is complete. nothing to do on our end. */
|
||||
gboolean
|
||||
thrift_memory_buffer_write_end (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
/* satisfy -Wall */
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_flush */
|
||||
gboolean
|
||||
thrift_memory_buffer_flush (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* initializes class before constructor properties are set */
|
||||
static void
|
||||
thrift_memory_buffer_init (ThriftMemoryBuffer *t)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (t);
|
||||
}
|
||||
|
||||
/* destructor */
|
||||
static void
|
||||
thrift_memory_buffer_finalize (GObject *object)
|
||||
{
|
||||
ThriftMemoryBuffer *t = THRIFT_MEMORY_BUFFER (object);
|
||||
|
||||
if (t->owner && t->buf != NULL)
|
||||
{
|
||||
g_byte_array_unref (t->buf);
|
||||
}
|
||||
t->buf = NULL;
|
||||
}
|
||||
|
||||
/* property accessor */
|
||||
void
|
||||
thrift_memory_buffer_get_property (GObject *object, guint property_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftMemoryBuffer *t = THRIFT_MEMORY_BUFFER (object);
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE:
|
||||
g_value_set_uint (value, t->buf_size);
|
||||
break;
|
||||
case PROP_THRIFT_MEMORY_BUFFER_BUFFER:
|
||||
g_value_set_pointer (value, (gpointer) (t->buf));
|
||||
break;
|
||||
case PROP_THRIFT_MEMORY_BUFFER_OWNER:
|
||||
g_value_set_boolean (value, t->owner);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* property mutator */
|
||||
void
|
||||
thrift_memory_buffer_set_property (GObject *object, guint property_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftMemoryBuffer *t = THRIFT_MEMORY_BUFFER (object);
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE:
|
||||
t->buf_size = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_THRIFT_MEMORY_BUFFER_BUFFER:
|
||||
t->buf = (GByteArray*) g_value_get_pointer (value);
|
||||
break;
|
||||
case PROP_THRIFT_MEMORY_BUFFER_OWNER:
|
||||
t->owner = g_value_get_boolean (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* initializes class after constructor properties are set */
|
||||
static void
|
||||
thrift_memory_buffer_constructed (GObject *object)
|
||||
{
|
||||
ThriftMemoryBuffer *t = THRIFT_MEMORY_BUFFER (object);
|
||||
|
||||
if (t->buf == NULL) {
|
||||
t->buf = g_byte_array_new ();
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (thrift_memory_buffer_parent_class)->constructed (object);
|
||||
}
|
||||
|
||||
/* initializes the class */
|
||||
static void
|
||||
thrift_memory_buffer_class_init (ThriftMemoryBufferClass *cls)
|
||||
{
|
||||
ThriftTransportClass *ttc = THRIFT_TRANSPORT_CLASS (cls);
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
|
||||
GParamSpec *param_spec = NULL;
|
||||
|
||||
/* setup accessors and mutators */
|
||||
gobject_class->get_property = thrift_memory_buffer_get_property;
|
||||
gobject_class->set_property = thrift_memory_buffer_set_property;
|
||||
|
||||
param_spec = g_param_spec_uint ("buf_size",
|
||||
"buffer size (construct)",
|
||||
"Set the read/write buffer size limit",
|
||||
0, /* min */
|
||||
G_MAXUINT32, /* max */
|
||||
G_MAXUINT32, /* default */
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE,
|
||||
param_spec);
|
||||
|
||||
param_spec = g_param_spec_pointer ("buf",
|
||||
"internal buffer (GByteArray)",
|
||||
"Set the internal buffer (GByteArray)",
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_MEMORY_BUFFER_BUFFER,
|
||||
param_spec);
|
||||
|
||||
param_spec = g_param_spec_boolean ("owner",
|
||||
"internal buffer memory management policy",
|
||||
"Set whether internal buffer should be"
|
||||
" unreferenced when thrift_memory_buffer"
|
||||
" is finalized",
|
||||
TRUE,
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_MEMORY_BUFFER_OWNER,
|
||||
param_spec);
|
||||
|
||||
gobject_class->constructed = thrift_memory_buffer_constructed;
|
||||
gobject_class->finalize = thrift_memory_buffer_finalize;
|
||||
ttc->is_open = thrift_memory_buffer_is_open;
|
||||
ttc->open = thrift_memory_buffer_open;
|
||||
ttc->close = thrift_memory_buffer_close;
|
||||
ttc->read = thrift_memory_buffer_read;
|
||||
ttc->read_end = thrift_memory_buffer_read_end;
|
||||
ttc->write = thrift_memory_buffer_write;
|
||||
ttc->write_end = thrift_memory_buffer_write_end;
|
||||
ttc->flush = thrift_memory_buffer_flush;
|
||||
}
|
||||
72
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_memory_buffer.h
generated
vendored
Normal file
72
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_memory_buffer.h
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_MEMORY_BUFFER_H
|
||||
#define _THRIFT_MEMORY_BUFFER_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_memory_buffer.h
|
||||
* \brief Implementation of a Thrift memory buffer transport.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_MEMORY_BUFFER (thrift_memory_buffer_get_type ())
|
||||
#define THRIFT_MEMORY_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_MEMORY_BUFFER, ThriftMemoryBuffer))
|
||||
#define THRIFT_IS_MEMORY_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_MEMORY_BUFFER))
|
||||
#define THRIFT_MEMORY_BUFFER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_MEMORY_BUFFER, ThriftMemoryBufferClass))
|
||||
#define THRIFT_IS_MEMORY_BUFFER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_MEMORY_BUFFER)
|
||||
#define THRIFT_MEMORY_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_MEMORY_BUFFER, ThriftMemoryBufferClass))
|
||||
|
||||
typedef struct _ThriftMemoryBuffer ThriftMemoryBuffer;
|
||||
|
||||
/*!
|
||||
* ThriftMemoryBuffer instance.
|
||||
*/
|
||||
struct _ThriftMemoryBuffer
|
||||
{
|
||||
ThriftTransport parent;
|
||||
|
||||
/* private */
|
||||
GByteArray *buf;
|
||||
guint32 buf_size;
|
||||
gboolean owner;
|
||||
};
|
||||
|
||||
typedef struct _ThriftMemoryBufferClass ThriftMemoryBufferClass;
|
||||
|
||||
/*!
|
||||
* ThriftMemoryBuffer class.
|
||||
*/
|
||||
struct _ThriftMemoryBufferClass
|
||||
{
|
||||
ThriftTransportClass parent;
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_MEMORY_BUFFER */
|
||||
GType thrift_memory_buffer_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
120
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_platform_socket.h
generated
vendored
Normal file
120
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_platform_socket.h
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
// clang-format off
|
||||
|
||||
#ifndef _THRIFT_TRANSPORT_PLATFORM_SOCKET_H_
|
||||
# define _THRIFT_TRANSPORT_PLATFORM_SOCKET_H_
|
||||
|
||||
#ifdef _WIN32
|
||||
# define THRIFT_GET_SOCKET_ERROR ::WSAGetLastError()
|
||||
# define THRIFT_ERRNO (*_errno())
|
||||
# define THRIFT_EINPROGRESS WSAEINPROGRESS
|
||||
# define THRIFT_EAGAIN WSAEWOULDBLOCK
|
||||
# define THRIFT_EINTR WSAEINTR
|
||||
# define THRIFT_ECONNRESET WSAECONNRESET
|
||||
# define THRIFT_ENOTCONN WSAENOTCONN
|
||||
# define THRIFT_ETIMEDOUT WSAETIMEDOUT
|
||||
# define THRIFT_EWOULDBLOCK WSAEWOULDBLOCK
|
||||
# define THRIFT_EPIPE WSAECONNRESET
|
||||
# define THRIFT_NO_SOCKET_CACHING SO_EXCLUSIVEADDRUSE
|
||||
# define THRIFT_INVALID_SOCKET INVALID_SOCKET
|
||||
# define THRIFT_SOCKETPAIR thrift_socketpair
|
||||
# define THRIFT_FCNTL thrift_fcntl
|
||||
# define THRIFT_O_NONBLOCK 1
|
||||
# define THRIFT_F_GETFL 0
|
||||
# define THRIFT_F_SETFL 1
|
||||
# define THRIFT_GETTIMEOFDAY thrift_gettimeofday
|
||||
# define THRIFT_CLOSESOCKET closesocket
|
||||
# define THRIFT_CLOSE _close
|
||||
# define THRIFT_OPEN _open
|
||||
# define THRIFT_FTRUNCATE _chsize_s
|
||||
# define THRIFT_FSYNC _commit
|
||||
# define THRIFT_LSEEK _lseek
|
||||
# define THRIFT_WRITE _write
|
||||
# define THRIFT_READ _read
|
||||
# define THRIFT_FSTAT _fstat
|
||||
# define THRIFT_STAT _stat
|
||||
# ifdef _WIN32_WCE
|
||||
# define THRIFT_GAI_STRERROR(...) thrift_wstr2str(gai_strerrorW(__VA_ARGS__))
|
||||
# else
|
||||
# define THRIFT_GAI_STRERROR gai_strerrorA
|
||||
# endif
|
||||
# define THRIFT_SSIZET ptrdiff_t
|
||||
# define THRIFT_SNPRINTF _snprintf
|
||||
# define THRIFT_SLEEP_SEC thrift_sleep
|
||||
# define THRIFT_SLEEP_USEC thrift_usleep
|
||||
# define THRIFT_TIMESPEC thrift_timespec
|
||||
# define THRIFT_CTIME_R thrift_ctime_r
|
||||
# define THRIFT_POLL thrift_poll
|
||||
# if WINVER <= 0x0502 //XP, Server2003
|
||||
# define THRIFT_POLLFD thrift_pollfd
|
||||
# define THRIFT_POLLIN 0x0300
|
||||
# define THRIFT_POLLOUT 0x0010
|
||||
# else //Vista, Win7...
|
||||
# define THRIFT_POLLFD pollfd
|
||||
# define THRIFT_POLLIN POLLIN
|
||||
# define THRIFT_POLLOUT POLLOUT
|
||||
# endif //WINVER
|
||||
# define THRIFT_SHUT_RDWR SD_BOTH
|
||||
#else //not _WIN32
|
||||
# include <errno.h>
|
||||
# define THRIFT_GET_SOCKET_ERROR errno
|
||||
# define THRIFT_ERRNO errno
|
||||
# define THRIFT_EINTR EINTR
|
||||
# define THRIFT_EINPROGRESS EINPROGRESS
|
||||
# define THRIFT_ECONNRESET ECONNRESET
|
||||
# define THRIFT_ENOTCONN ENOTCONN
|
||||
# define THRIFT_ETIMEDOUT ETIMEDOUT
|
||||
# define THRIFT_EWOULDBLOCK EWOULDBLOCK
|
||||
# define THRIFT_EAGAIN EAGAIN
|
||||
# define THRIFT_EPIPE EPIPE
|
||||
# define THRIFT_NO_SOCKET_CACHING SO_REUSEADDR
|
||||
# define THRIFT_INVALID_SOCKET (-1)
|
||||
# define THRIFT_SOCKETPAIR socketpair
|
||||
# define THRIFT_FCNTL fcntl
|
||||
# define THRIFT_O_NONBLOCK O_NONBLOCK
|
||||
# define THRIFT_F_GETFL F_GETFL
|
||||
# define THRIFT_F_SETFL F_SETFL
|
||||
# define THRIFT_GETTIMEOFDAY gettimeofday
|
||||
# define THRIFT_CLOSESOCKET close
|
||||
# define THRIFT_CLOSE close
|
||||
# define THRIFT_OPEN open
|
||||
# define THRIFT_FTRUNCATE ftruncate
|
||||
# define THRIFT_FSYNC fsync
|
||||
# define THRIFT_LSEEK lseek
|
||||
# define THRIFT_WRITE write
|
||||
# define THRIFT_READ read
|
||||
# define THRIFT_STAT stat
|
||||
# define THRIFT_FSTAT fstat
|
||||
# define THRIFT_GAI_STRERROR gai_strerror
|
||||
# define THRIFT_SSIZET ssize_t
|
||||
# define THRIFT_SNPRINTF snprintf
|
||||
# define THRIFT_SLEEP_SEC sleep
|
||||
# define THRIFT_SLEEP_USEC usleep
|
||||
# define THRIFT_TIMESPEC timespec
|
||||
# define THRIFT_CTIME_R ctime_r
|
||||
# define THRIFT_POLL poll
|
||||
# define THRIFT_POLLFD pollfd
|
||||
# define THRIFT_POLLIN POLLIN
|
||||
# define THRIFT_POLLOUT POLLOUT
|
||||
# define THRIFT_SHUT_RDWR SHUT_RDWR
|
||||
#endif
|
||||
|
||||
#endif // _THRIFT_TRANSPORT_PLATFORM_SOCKET_H_
|
||||
253
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_server_socket.c
generated
vendored
Normal file
253
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_server_socket.c
generated
vendored
Normal file
@@ -0,0 +1,253 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/transport/thrift_socket.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_server_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_server_socket.h>
|
||||
|
||||
/* object properties */
|
||||
enum _ThriftServerSocketProperties
|
||||
{
|
||||
PROP_0,
|
||||
PROP_THRIFT_SERVER_SOCKET_PORT,
|
||||
PROP_THRIFT_SERVER_SOCKET_BACKLOG
|
||||
};
|
||||
|
||||
/* define the GError domain string */
|
||||
#define THRIFT_SERVER_SOCKET_ERROR_DOMAIN "thrift-server-socket-error-quark"
|
||||
|
||||
G_DEFINE_TYPE(ThriftServerSocket, thrift_server_socket, THRIFT_TYPE_SERVER_TRANSPORT)
|
||||
|
||||
gboolean
|
||||
thrift_server_socket_listen (ThriftServerTransport *transport, GError **error)
|
||||
{
|
||||
int enabled = 1; /* for setsockopt() */
|
||||
struct sockaddr_in pin;
|
||||
ThriftServerSocket *tsocket = THRIFT_SERVER_SOCKET (transport);
|
||||
|
||||
/* create a address structure */
|
||||
memset (&pin, 0, sizeof(pin));
|
||||
pin.sin_family = AF_INET;
|
||||
pin.sin_addr.s_addr = INADDR_ANY;
|
||||
pin.sin_port = htons(tsocket->port);
|
||||
|
||||
/* create a socket */
|
||||
if ((tsocket->sd = socket (AF_INET, SOCK_STREAM, 0)) == -1)
|
||||
{
|
||||
g_set_error (error, THRIFT_SERVER_SOCKET_ERROR,
|
||||
THRIFT_SERVER_SOCKET_ERROR_SOCKET,
|
||||
"failed to create socket - %s", strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (setsockopt(tsocket->sd, SOL_SOCKET, SO_REUSEADDR, &enabled,
|
||||
sizeof(enabled)) == -1)
|
||||
{
|
||||
g_set_error (error, THRIFT_SERVER_SOCKET_ERROR,
|
||||
THRIFT_SERVER_SOCKET_ERROR_SETSOCKOPT,
|
||||
"unable to set SO_REUSEADDR - %s", strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* bind to the socket */
|
||||
if (bind(tsocket->sd, (struct sockaddr *) &pin, sizeof(pin)) == -1)
|
||||
{
|
||||
g_set_error (error, THRIFT_SERVER_SOCKET_ERROR,
|
||||
THRIFT_SERVER_SOCKET_ERROR_BIND,
|
||||
"failed to bind to port %d - %s",
|
||||
tsocket->port, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (listen(tsocket->sd, tsocket->backlog) == -1)
|
||||
{
|
||||
g_set_error (error, THRIFT_SERVER_SOCKET_ERROR,
|
||||
THRIFT_SERVER_SOCKET_ERROR_LISTEN,
|
||||
"failed to listen to port %d - %s",
|
||||
tsocket->port, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ThriftTransport *
|
||||
thrift_server_socket_accept (ThriftServerTransport *transport, GError **error)
|
||||
{
|
||||
int sd = THRIFT_INVALID_SOCKET;
|
||||
guint addrlen = 0;
|
||||
struct sockaddr_in address;
|
||||
ThriftSocket *socket = NULL;
|
||||
|
||||
ThriftServerSocket *tsocket = THRIFT_SERVER_SOCKET (transport);
|
||||
|
||||
if ((sd = accept(tsocket->sd, (struct sockaddr *) &address, &addrlen)) == -1)
|
||||
{
|
||||
g_set_error (error, THRIFT_SERVER_SOCKET_ERROR,
|
||||
THRIFT_SERVER_SOCKET_ERROR_ACCEPT,
|
||||
"failed to accept connection - %s",
|
||||
strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
socket = g_object_new (THRIFT_TYPE_SOCKET, NULL);
|
||||
socket->sd = sd;
|
||||
|
||||
return THRIFT_TRANSPORT(socket);
|
||||
}
|
||||
|
||||
gboolean
|
||||
thrift_server_socket_close (ThriftServerTransport *transport, GError **error)
|
||||
{
|
||||
ThriftServerSocket *tsocket = THRIFT_SERVER_SOCKET (transport);
|
||||
|
||||
if (close (tsocket->sd) == -1)
|
||||
{
|
||||
g_set_error (error, THRIFT_SERVER_SOCKET_ERROR,
|
||||
THRIFT_SERVER_SOCKET_ERROR_CLOSE,
|
||||
"unable to close socket - %s", strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
tsocket->sd = THRIFT_INVALID_SOCKET;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* define the GError domain for this implementation */
|
||||
GQuark
|
||||
thrift_server_socket_error_quark (void)
|
||||
{
|
||||
return g_quark_from_static_string(THRIFT_SERVER_SOCKET_ERROR_DOMAIN);
|
||||
}
|
||||
|
||||
/* initializes the instance */
|
||||
static void
|
||||
thrift_server_socket_init (ThriftServerSocket *socket)
|
||||
{
|
||||
socket->sd = THRIFT_INVALID_SOCKET;
|
||||
}
|
||||
|
||||
/* destructor */
|
||||
static void
|
||||
thrift_server_socket_finalize (GObject *object)
|
||||
{
|
||||
ThriftServerSocket *socket = THRIFT_SERVER_SOCKET (object);
|
||||
|
||||
if (socket->sd != THRIFT_INVALID_SOCKET)
|
||||
{
|
||||
close (socket->sd);
|
||||
}
|
||||
socket->sd = THRIFT_INVALID_SOCKET;
|
||||
}
|
||||
|
||||
/* property accessor */
|
||||
void
|
||||
thrift_server_socket_get_property (GObject *object, guint property_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftServerSocket *socket = THRIFT_SERVER_SOCKET (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_SERVER_SOCKET_PORT:
|
||||
g_value_set_uint (value, socket->port);
|
||||
break;
|
||||
case PROP_THRIFT_SERVER_SOCKET_BACKLOG:
|
||||
g_value_set_uint (value, socket->backlog);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* property mutator */
|
||||
void
|
||||
thrift_server_socket_set_property (GObject *object, guint property_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftServerSocket *socket = THRIFT_SERVER_SOCKET (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_SERVER_SOCKET_PORT:
|
||||
socket->port = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_THRIFT_SERVER_SOCKET_BACKLOG:
|
||||
socket->backlog = g_value_get_uint (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* initializes the class */
|
||||
static void
|
||||
thrift_server_socket_class_init (ThriftServerSocketClass *cls)
|
||||
{
|
||||
ThriftServerTransportClass *tstc = THRIFT_SERVER_TRANSPORT_CLASS (cls);
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
|
||||
GParamSpec *param_spec = NULL;
|
||||
|
||||
/* setup accessors and mutators */
|
||||
gobject_class->get_property = thrift_server_socket_get_property;
|
||||
gobject_class->set_property = thrift_server_socket_set_property;
|
||||
|
||||
param_spec = g_param_spec_uint ("port",
|
||||
"port (construct)",
|
||||
"Set the port to listen to",
|
||||
0, /* min */
|
||||
65535, /* max */
|
||||
9090, /* default by convention */
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_SERVER_SOCKET_PORT,
|
||||
param_spec);
|
||||
|
||||
param_spec = g_param_spec_uint ("backlog",
|
||||
"backlog (construct)",
|
||||
"Set the accept backlog",
|
||||
0, /* max */
|
||||
65534, /* max */
|
||||
1024, /* default */
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_THRIFT_SERVER_SOCKET_BACKLOG,
|
||||
param_spec);
|
||||
|
||||
gobject_class->finalize = thrift_server_socket_finalize;
|
||||
|
||||
tstc->listen = thrift_server_socket_listen;
|
||||
tstc->accept = thrift_server_socket_accept;
|
||||
tstc->close = thrift_server_socket_close;
|
||||
}
|
||||
|
||||
90
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_server_socket.h
generated
vendored
Normal file
90
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_server_socket.h
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_SERVER_SOCKET_H
|
||||
#define _THRIFT_SERVER_SOCKET_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "thrift_server_transport.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_server_socket.h
|
||||
* \brief Socket implementation of a Thrift server transport. Implements the
|
||||
* ThriftServerTransport class.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_SERVER_SOCKET (thrift_server_socket_get_type ())
|
||||
#define THRIFT_SERVER_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_SERVER_SOCKET, ThriftServerSocket))
|
||||
#define THRIFT_IS_SERVER_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_SERVER_SOCKET))
|
||||
#define THRIFT_SERVER_SOCKET_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_SERVER_SOCKET, ThriftServerSocketClass))
|
||||
#define THRIFT_IS_SERVER_SOCKET_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_SERVER_SOCKET))
|
||||
#define THRIFT_SERVER_SOCKET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_SERVER_SOCKET, ThriftServerSocketClass))
|
||||
|
||||
typedef struct _ThriftServerSocket ThriftServerSocket;
|
||||
|
||||
/*!
|
||||
* Thrift ServerSocket instance.
|
||||
*/
|
||||
struct _ThriftServerSocket
|
||||
{
|
||||
ThriftServerTransport parent;
|
||||
|
||||
/* private */
|
||||
guint port;
|
||||
gshort backlog;
|
||||
int sd;
|
||||
guint8 *buf;
|
||||
guint32 buf_size;
|
||||
guint32 buf_len;
|
||||
};
|
||||
|
||||
typedef struct _ThriftServerSocketClass ThriftServerSocketClass;
|
||||
|
||||
/*!
|
||||
* Thrift ServerSocket class.
|
||||
*/
|
||||
struct _ThriftServerSocketClass
|
||||
{
|
||||
ThriftServerTransportClass parent;
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_SERVER_SOCKET */
|
||||
GType thrift_server_socket_get_type (void);
|
||||
|
||||
/* define error/exception types */
|
||||
typedef enum
|
||||
{
|
||||
THRIFT_SERVER_SOCKET_ERROR_SOCKET,
|
||||
THRIFT_SERVER_SOCKET_ERROR_SETSOCKOPT,
|
||||
THRIFT_SERVER_SOCKET_ERROR_BIND,
|
||||
THRIFT_SERVER_SOCKET_ERROR_LISTEN,
|
||||
THRIFT_SERVER_SOCKET_ERROR_ACCEPT,
|
||||
THRIFT_SERVER_SOCKET_ERROR_CLOSE
|
||||
} ThriftServerSocketError;
|
||||
|
||||
/* define a error domain for GError to use */
|
||||
GQuark thrift_server_socket_error_quark (void);
|
||||
#define THRIFT_SERVER_SOCKET_ERROR (thrift_server_socket_error_quark ())
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
62
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_server_transport.c
generated
vendored
Normal file
62
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_server_transport.c
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_server_transport.h>
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE(ThriftServerTransport, thrift_server_transport, G_TYPE_OBJECT)
|
||||
|
||||
/* base initializer for the server transport interface */
|
||||
static void
|
||||
thrift_server_transport_class_init (ThriftServerTransportClass *c)
|
||||
{
|
||||
c->listen = thrift_server_transport_listen;
|
||||
c->accept = thrift_server_transport_accept;
|
||||
c->close = thrift_server_transport_close;
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_server_transport_init (ThriftServerTransport *transport)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
}
|
||||
|
||||
gboolean
|
||||
thrift_server_transport_listen (ThriftServerTransport *transport,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_SERVER_TRANSPORT_GET_CLASS (transport)->listen (transport,
|
||||
error);
|
||||
}
|
||||
|
||||
ThriftTransport *
|
||||
thrift_server_transport_accept (ThriftServerTransport *transport,
|
||||
GError **error)
|
||||
{
|
||||
return THRIFT_SERVER_TRANSPORT_GET_CLASS (transport)->accept (transport,
|
||||
error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
thrift_server_transport_close (ThriftServerTransport *transport, GError **error)
|
||||
{
|
||||
return THRIFT_SERVER_TRANSPORT_GET_CLASS (transport)->close (transport,
|
||||
error);
|
||||
}
|
||||
89
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_server_transport.h
generated
vendored
Normal file
89
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_server_transport.h
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_SERVER_TRANSPORT_H
|
||||
#define _THRIFT_SERVER_TRANSPORT_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "thrift_transport.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_server_transport.h
|
||||
* \brief Abstract class for Thrift server transports.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_SERVER_TRANSPORT (thrift_server_transport_get_type ())
|
||||
#define THRIFT_SERVER_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_SERVER_TRANSPORT, ThriftServerTransport))
|
||||
#define THRIFT_IS_SERVER_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_SERVER_TRANSPORT))
|
||||
#define THRIFT_SERVER_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_SERVER_TRANSPORT, ThriftServerTransportClass))
|
||||
#define THRIFT_IS_SERVER_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_SERVER_TRANSPORT))
|
||||
#define THRIFT_SERVER_TRANSPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_SERVER_TRANSPORT, ThriftServerTransportClass))
|
||||
|
||||
typedef struct _ThriftServerTransport ThriftServerTransport;
|
||||
|
||||
struct _ThriftServerTransport
|
||||
{
|
||||
GObject parent;
|
||||
};
|
||||
|
||||
typedef struct _ThriftServerTransportClass ThriftServerTransportClass;
|
||||
|
||||
/*!
|
||||
* Thrift Transport class
|
||||
*/
|
||||
struct _ThriftServerTransportClass
|
||||
{
|
||||
GObjectClass parent;
|
||||
|
||||
/* vtable */
|
||||
gboolean (*listen) (ThriftServerTransport *transport, GError **error);
|
||||
ThriftTransport *(*accept) (ThriftServerTransport *transport, GError **error);
|
||||
gboolean (*close) (ThriftServerTransport *transport, GError **error);
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_SERVER_TRANSPORT */
|
||||
GType thrift_server_transport_get_type (void);
|
||||
|
||||
/*!
|
||||
* Listen for new connections.
|
||||
* \public \memberof ThriftServerTransportClass
|
||||
*/
|
||||
gboolean thrift_server_transport_listen (ThriftServerTransport *transport,
|
||||
GError **error);
|
||||
|
||||
/*!
|
||||
* Accept a connection.
|
||||
* \public \memberof ThriftServerTransportClass
|
||||
*/
|
||||
ThriftTransport *thrift_server_transport_accept
|
||||
(ThriftServerTransport *transport, GError **error);
|
||||
|
||||
/*!
|
||||
* Close the transport.
|
||||
* \public \memberof ThriftServerTransportClass
|
||||
*/
|
||||
gboolean thrift_server_transport_close (ThriftServerTransport *transport,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_SERVER_TRANSPORT_H */
|
||||
371
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_socket.c
generated
vendored
Normal file
371
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_socket.c
generated
vendored
Normal file
@@ -0,0 +1,371 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_socket.h>
|
||||
|
||||
/* object properties */
|
||||
enum _ThriftSocketProperties
|
||||
{
|
||||
PROP_0,
|
||||
PROP_THRIFT_SOCKET_HOSTNAME,
|
||||
PROP_THRIFT_SOCKET_PORT
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ThriftSocket, thrift_socket, THRIFT_TYPE_TRANSPORT)
|
||||
|
||||
/* implements thrift_transport_is_open */
|
||||
gboolean
|
||||
thrift_socket_is_open (ThriftTransport *transport)
|
||||
{
|
||||
ThriftSocket *socket = THRIFT_SOCKET (transport);
|
||||
return socket->sd != THRIFT_INVALID_SOCKET;
|
||||
}
|
||||
|
||||
/* overrides thrift_transport_peek */
|
||||
gboolean
|
||||
thrift_socket_peek (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
gboolean result = FALSE;
|
||||
guint8 buf;
|
||||
int r;
|
||||
int errno_copy;
|
||||
|
||||
ThriftSocket *socket = THRIFT_SOCKET (transport);
|
||||
|
||||
if (thrift_socket_is_open (transport))
|
||||
{
|
||||
r = recv (socket->sd, &buf, 1, MSG_PEEK);
|
||||
if (r == -1)
|
||||
{
|
||||
errno_copy = errno;
|
||||
|
||||
#if defined __FreeBSD__ || defined __MACH__
|
||||
/* FreeBSD returns -1 and ECONNRESET if the socket was closed by the other
|
||||
side */
|
||||
if (errno_copy == ECONNRESET)
|
||||
{
|
||||
thrift_socket_close (transport, error);
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
|
||||
g_set_error (error,
|
||||
THRIFT_TRANSPORT_ERROR,
|
||||
THRIFT_TRANSPORT_ERROR_SOCKET,
|
||||
"failed to peek at socket - %s",
|
||||
strerror (errno_copy));
|
||||
|
||||
#if defined __FreeBSD__ || defined __MACH__
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (r > 0)
|
||||
{
|
||||
result = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_open */
|
||||
gboolean
|
||||
thrift_socket_open (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
struct hostent *hp = NULL;
|
||||
struct sockaddr_in pin;
|
||||
int err;
|
||||
#if defined(HAVE_GETHOSTBYNAME_R)
|
||||
struct hostent he;
|
||||
char buf[1024];
|
||||
#endif
|
||||
|
||||
ThriftSocket *tsocket = THRIFT_SOCKET (transport);
|
||||
g_return_val_if_fail (tsocket->sd == THRIFT_INVALID_SOCKET, FALSE);
|
||||
|
||||
/* lookup the destination host */
|
||||
#if defined(HAVE_GETHOSTBYNAME_R)
|
||||
if (gethostbyname_r (tsocket->hostname, &he, buf, 1024, &hp, &err) != 0 || hp == NULL)
|
||||
#else
|
||||
if ((hp = gethostbyname (tsocket->hostname)) == NULL && (err = h_errno))
|
||||
#endif
|
||||
{
|
||||
/* host lookup failed, bail out with an error */
|
||||
g_set_error (error, THRIFT_TRANSPORT_ERROR, THRIFT_TRANSPORT_ERROR_HOST,
|
||||
"host lookup failed for %s:%d - %s",
|
||||
tsocket->hostname, tsocket->port,
|
||||
hstrerror (err));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* create a socket structure */
|
||||
memset (&pin, 0, sizeof(pin));
|
||||
pin.sin_family = AF_INET;
|
||||
pin.sin_addr.s_addr = ((struct in_addr *) (hp->h_addr))->s_addr;
|
||||
pin.sin_port = htons (tsocket->port);
|
||||
|
||||
/* create the socket */
|
||||
if ((tsocket->sd = socket (AF_INET, SOCK_STREAM, 0)) == -1)
|
||||
{
|
||||
g_set_error (error, THRIFT_TRANSPORT_ERROR, THRIFT_TRANSPORT_ERROR_SOCKET,
|
||||
"failed to create socket for host %s:%d - %s",
|
||||
tsocket->hostname, tsocket->port,
|
||||
strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* open a connection */
|
||||
if (connect (tsocket->sd, (struct sockaddr *) &pin, sizeof(pin)) == -1)
|
||||
{
|
||||
g_set_error (error, THRIFT_TRANSPORT_ERROR, THRIFT_TRANSPORT_ERROR_CONNECT,
|
||||
"failed to connect to host %s:%d - %s",
|
||||
tsocket->hostname, tsocket->port, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_close */
|
||||
gboolean
|
||||
thrift_socket_close (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
ThriftSocket *socket = THRIFT_SOCKET (transport);
|
||||
|
||||
if (close (socket->sd) == -1)
|
||||
{
|
||||
g_set_error (error, THRIFT_TRANSPORT_ERROR, THRIFT_TRANSPORT_ERROR_CLOSE,
|
||||
"unable to close socket - %s",
|
||||
strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
socket->sd = THRIFT_INVALID_SOCKET;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_read */
|
||||
gint32
|
||||
thrift_socket_read (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error)
|
||||
{
|
||||
gint ret = 0;
|
||||
guint got = 0;
|
||||
|
||||
ThriftSocket *socket = THRIFT_SOCKET (transport);
|
||||
|
||||
while (got < len)
|
||||
{
|
||||
ret = recv (socket->sd, (guint8 *)buf + got, len-got, 0);
|
||||
if (ret <= 0)
|
||||
{
|
||||
g_set_error (error, THRIFT_TRANSPORT_ERROR,
|
||||
THRIFT_TRANSPORT_ERROR_RECEIVE,
|
||||
"failed to read %d bytes - %s", len, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
got += ret;
|
||||
}
|
||||
|
||||
return got;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_read_end
|
||||
* called when write is complete. nothing to do on our end. */
|
||||
gboolean
|
||||
thrift_socket_read_end (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
/* satisfy -Wall */
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_write */
|
||||
gboolean
|
||||
thrift_socket_write (ThriftTransport *transport, const gpointer buf,
|
||||
const guint32 len, GError **error)
|
||||
{
|
||||
gint ret = 0;
|
||||
guint sent = 0;
|
||||
|
||||
ThriftSocket *socket = THRIFT_SOCKET (transport);
|
||||
g_return_val_if_fail (socket->sd != THRIFT_INVALID_SOCKET, FALSE);
|
||||
|
||||
while (sent < len)
|
||||
{
|
||||
ret = send (socket->sd, (guint8 *)buf + sent, len - sent, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
g_set_error (error, THRIFT_TRANSPORT_ERROR,
|
||||
THRIFT_TRANSPORT_ERROR_SEND,
|
||||
"failed to send %d bytes - %s", len, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
sent += ret;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_write_end
|
||||
* called when write is complete. nothing to do on our end. */
|
||||
gboolean
|
||||
thrift_socket_write_end (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
/* satisfy -Wall */
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_flush
|
||||
* flush pending data. since we are not buffered, this is a no-op */
|
||||
gboolean
|
||||
thrift_socket_flush (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
/* satisfy -Wall */
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* initializes the instance */
|
||||
static void
|
||||
thrift_socket_init (ThriftSocket *socket)
|
||||
{
|
||||
socket->sd = THRIFT_INVALID_SOCKET;
|
||||
}
|
||||
|
||||
/* destructor */
|
||||
static void
|
||||
thrift_socket_finalize (GObject *object)
|
||||
{
|
||||
ThriftSocket *socket = THRIFT_SOCKET (object);
|
||||
|
||||
if (socket->hostname != NULL)
|
||||
{
|
||||
g_free (socket->hostname);
|
||||
}
|
||||
socket->hostname = NULL;
|
||||
|
||||
if (socket->sd != THRIFT_INVALID_SOCKET)
|
||||
{
|
||||
close (socket->sd);
|
||||
}
|
||||
socket->sd = THRIFT_INVALID_SOCKET;
|
||||
}
|
||||
|
||||
/* property accessor */
|
||||
void
|
||||
thrift_socket_get_property (GObject *object, guint property_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftSocket *socket = THRIFT_SOCKET (object);
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_SOCKET_HOSTNAME:
|
||||
g_value_set_string (value, socket->hostname);
|
||||
break;
|
||||
case PROP_THRIFT_SOCKET_PORT:
|
||||
g_value_set_uint (value, socket->port);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* property mutator */
|
||||
void
|
||||
thrift_socket_set_property (GObject *object, guint property_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftSocket *socket = THRIFT_SOCKET (object);
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_SOCKET_HOSTNAME:
|
||||
if (socket->hostname) {
|
||||
g_free(socket->hostname);
|
||||
}
|
||||
socket->hostname = g_strdup (g_value_get_string (value));
|
||||
break;
|
||||
case PROP_THRIFT_SOCKET_PORT:
|
||||
socket->port = g_value_get_uint (value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* initializes the class */
|
||||
static void
|
||||
thrift_socket_class_init (ThriftSocketClass *cls)
|
||||
{
|
||||
ThriftTransportClass *ttc = THRIFT_TRANSPORT_CLASS (cls);
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
|
||||
GParamSpec *param_spec = NULL;
|
||||
|
||||
/* setup accessors and mutators */
|
||||
gobject_class->get_property = thrift_socket_get_property;
|
||||
gobject_class->set_property = thrift_socket_set_property;
|
||||
|
||||
param_spec = g_param_spec_string ("hostname",
|
||||
"hostname (construct)",
|
||||
"Set the hostname of the remote host",
|
||||
"localhost", /* default value */
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class, PROP_THRIFT_SOCKET_HOSTNAME,
|
||||
param_spec);
|
||||
|
||||
param_spec = g_param_spec_uint ("port",
|
||||
"port (construct)",
|
||||
"Set the port of the remote host",
|
||||
0u, /* min */
|
||||
65535u, /* max */
|
||||
9090, /* default by convention */
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class, PROP_THRIFT_SOCKET_PORT,
|
||||
param_spec);
|
||||
|
||||
gobject_class->finalize = thrift_socket_finalize;
|
||||
ttc->is_open = thrift_socket_is_open;
|
||||
ttc->peek = thrift_socket_peek;
|
||||
ttc->open = thrift_socket_open;
|
||||
ttc->close = thrift_socket_close;
|
||||
ttc->read = thrift_socket_read;
|
||||
ttc->read_end = thrift_socket_read_end;
|
||||
ttc->write = thrift_socket_write;
|
||||
ttc->write_end = thrift_socket_write_end;
|
||||
ttc->flush = thrift_socket_flush;
|
||||
}
|
||||
72
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_socket.h
generated
vendored
Normal file
72
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_socket.h
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_SOCKET_H
|
||||
#define _THRIFT_SOCKET_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_socket.h
|
||||
* \brief Socket implementation of a Thrift transport. Subclasses the
|
||||
* ThriftTransport class.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_SOCKET (thrift_socket_get_type ())
|
||||
#define THRIFT_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_SOCKET, ThriftSocket))
|
||||
#define THRIFT_IS_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_SOCKET))
|
||||
#define THRIFT_SOCKET_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_SOCKET, ThriftSocketClass))
|
||||
#define THRIFT_IS_SOCKET_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_SOCKET))
|
||||
#define THRIFT_SOCKET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_SOCKET, ThriftSocketClass))
|
||||
|
||||
typedef struct _ThriftSocket ThriftSocket;
|
||||
|
||||
/*!
|
||||
* Thrift Socket instance.
|
||||
*/
|
||||
struct _ThriftSocket
|
||||
{
|
||||
ThriftTransport parent;
|
||||
|
||||
/* private */
|
||||
gchar *hostname;
|
||||
guint port;
|
||||
int sd;
|
||||
};
|
||||
|
||||
typedef struct _ThriftSocketClass ThriftSocketClass;
|
||||
|
||||
/*!
|
||||
* Thrift Socket class.
|
||||
*/
|
||||
struct _ThriftSocketClass
|
||||
{
|
||||
ThriftTransportClass parent;
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_SOCKET */
|
||||
GType thrift_socket_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
738
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_ssl_socket.c
generated
vendored
Normal file
738
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_ssl_socket.c
generated
vendored
Normal file
@@ -0,0 +1,738 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_socket.h>
|
||||
#include <thrift/c_glib/transport/thrift_ssl_socket.h>
|
||||
|
||||
|
||||
#if defined(WIN32)
|
||||
#define MUTEX_TYPE HANDLE
|
||||
#define MUTEX_SETUP(x) (x) = CreateMutex(NULL, FALSE, NULL)
|
||||
#define MUTEX_CLEANUP(x) CloseHandle(x)
|
||||
#define MUTEX_LOCK(x) WaitForSingleObject((x), INFINITE)
|
||||
#define MUTEX_UNLOCK(x) ReleaseMutex(x)
|
||||
#else
|
||||
#define MUTEX_TYPE pthread_mutex_t
|
||||
#define MUTEX_SETUP(x) pthread_mutex_init(&(x), NULL)
|
||||
#define MUTEX_CLEANUP(x) pthread_mutex_destroy(&(x))
|
||||
#define MUTEX_LOCK(x) pthread_mutex_lock(&(x))
|
||||
#define MUTEX_UNLOCK(x) pthread_mutex_unlock(&(x))
|
||||
#endif
|
||||
|
||||
#define OPENSSL_VERSION_NO_THREAD_ID 0x10000000L
|
||||
|
||||
|
||||
/* object properties */
|
||||
enum _ThriftSSLSocketProperties
|
||||
{
|
||||
PROP_THRIFT_SSL_SOCKET_CONTEXT = 3,
|
||||
PROP_THRIFT_SSL_SELF_SIGNED
|
||||
};
|
||||
|
||||
/* To hold a global state management of openssl for all instances */
|
||||
static gboolean thrift_ssl_socket_openssl_initialized=FALSE;
|
||||
/* This array will store all of the mutexes available to OpenSSL. */
|
||||
static MUTEX_TYPE *thrift_ssl_socket_global_mutex_buf=NULL;
|
||||
|
||||
|
||||
/**
|
||||
* OpenSSL uniq id function.
|
||||
*
|
||||
* @return thread id
|
||||
*/
|
||||
static unsigned long thrift_ssl_socket_static_id_function(void)
|
||||
{
|
||||
#if defined(WIN32)
|
||||
return GetCurrentThreadId();
|
||||
#else
|
||||
return ((unsigned long) pthread_self());
|
||||
#endif
|
||||
}
|
||||
|
||||
static void thrift_ssl_socket_static_locking_callback(int mode, int n, const char* unk, int id) {
|
||||
if (mode & CRYPTO_LOCK)
|
||||
MUTEX_LOCK(thrift_ssl_socket_global_mutex_buf[n]);
|
||||
else
|
||||
MUTEX_UNLOCK(thrift_ssl_socket_global_mutex_buf[n]);
|
||||
}
|
||||
|
||||
static int thrift_ssl_socket_static_thread_setup(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
thrift_ssl_socket_global_mutex_buf = malloc(CRYPTO_num_locks() * sizeof(MUTEX_TYPE));
|
||||
if (!thrift_ssl_socket_global_mutex_buf)
|
||||
return 0;
|
||||
for (i = 0; i < CRYPTO_num_locks( ); i++)
|
||||
MUTEX_SETUP(thrift_ssl_socket_global_mutex_buf[i]);
|
||||
CRYPTO_set_id_callback(thrift_ssl_socket_static_id_function);
|
||||
CRYPTO_set_locking_callback(thrift_ssl_socket_static_locking_callback);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int thrift_ssl_socket_static_thread_cleanup(void)
|
||||
{
|
||||
int i;
|
||||
if (!thrift_ssl_socket_global_mutex_buf)
|
||||
return 0;
|
||||
CRYPTO_set_id_callback(NULL);
|
||||
CRYPTO_set_locking_callback(NULL);
|
||||
for (i = 0; i < CRYPTO_num_locks( ); i++)
|
||||
MUTEX_CLEANUP(thrift_ssl_socket_global_mutex_buf[i]);
|
||||
free(thrift_ssl_socket_global_mutex_buf);
|
||||
thrift_ssl_socket_global_mutex_buf = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
static void* thrift_ssl_socket_dyn_lock_create_callback(const char* unk, int id) {
|
||||
g_print("We should create a lock\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void thrift_ssl_socket_dyn_lock_callback(int mode, void* lock, const char* unk, int id) {
|
||||
if (lock != NULL) {
|
||||
if (mode & CRYPTO_LOCK) {
|
||||
g_printf("We should lock thread %d\n");
|
||||
} else {
|
||||
g_printf("We should unlock thread %d\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void thrift_ssl_socket_dyn_lock_destroy_callback(void* lock, const char* unk, int id) {
|
||||
g_printf("We must destroy the lock\n");
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
G_DEFINE_TYPE(ThriftSSLSocket, thrift_ssl_socket, THRIFT_TYPE_SOCKET)
|
||||
|
||||
|
||||
/* implements thrift_transport_is_open */
|
||||
gboolean
|
||||
thrift_ssl_socket_is_open (ThriftTransport *transport)
|
||||
{
|
||||
return thrift_socket_is_open(transport);
|
||||
}
|
||||
|
||||
/* overrides thrift_transport_peek */
|
||||
gboolean
|
||||
thrift_ssl_socket_peek (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
gboolean retval = FALSE;
|
||||
ThriftSSLSocket *ssl_socket = THRIFT_SSL_SOCKET (transport);
|
||||
if (thrift_ssl_socket_is_open (transport))
|
||||
{
|
||||
int rc;
|
||||
gchar byte;
|
||||
rc = SSL_peek(ssl_socket->ssl, &byte, 1);
|
||||
if (rc < 0) {
|
||||
g_set_error (error,
|
||||
THRIFT_TRANSPORT_ERROR,
|
||||
THRIFT_SSL_SOCKET_ERROR_SSL,
|
||||
"failed to peek at socket - id?");
|
||||
}
|
||||
if (rc == 0) {
|
||||
ERR_clear_error();
|
||||
}
|
||||
retval = (rc > 0);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_open */
|
||||
gboolean
|
||||
thrift_ssl_socket_open (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
if (!thrift_socket_open(transport, error)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!THRIFT_SSL_SOCKET_GET_CLASS(transport)->handle_handshake(transport, error)) {
|
||||
GError *tmperr;
|
||||
thrift_socket_close(transport, &tmperr);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_close */
|
||||
gboolean
|
||||
thrift_ssl_socket_close (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
gboolean retval = FALSE;
|
||||
if(THRIFT_SSL_SOCKET(transport)->ssl) {
|
||||
int rc = SSL_shutdown(THRIFT_SSL_SOCKET(transport)->ssl);
|
||||
if (rc < 0) {
|
||||
int errno_copy = THRIFT_SSL_SOCKET_ERROR_SSL;
|
||||
}
|
||||
SSL_free(THRIFT_SSL_SOCKET(transport)->ssl);
|
||||
THRIFT_SSL_SOCKET(transport)->ssl = NULL;
|
||||
ERR_remove_state(0);
|
||||
}
|
||||
return thrift_socket_close(transport, error);
|
||||
}
|
||||
|
||||
/* implements thrift_transport_read */
|
||||
gint32
|
||||
thrift_ssl_socket_read (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error)
|
||||
{
|
||||
guint maxRecvRetries_ = 10;
|
||||
ThriftSSLSocket *ssl_socket = THRIFT_SSL_SOCKET (transport);
|
||||
guint bytes = 0;
|
||||
guint retries = 0;
|
||||
for (retries=0; retries < maxRecvRetries_; retries++) {
|
||||
bytes = SSL_read(ssl_socket->ssl, buf, len);
|
||||
if (bytes >= 0)
|
||||
break;
|
||||
int errno_copy = THRIFT_GET_SOCKET_ERROR;
|
||||
if (SSL_get_error(ssl_socket->ssl, bytes) == SSL_ERROR_SYSCALL) {
|
||||
if (ERR_get_error() == 0 && errno_copy == THRIFT_EINTR) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
g_set_error (error, THRIFT_TRANSPORT_ERROR,
|
||||
THRIFT_TRANSPORT_ERROR_RECEIVE,
|
||||
"failed to read %d bytes - %s", len, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_read_end
|
||||
* called when write is complete. nothing to do on our end. */
|
||||
gboolean
|
||||
thrift_ssl_socket_read_end (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
/* satisfy -Wall */
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_write */
|
||||
gboolean
|
||||
thrift_ssl_socket_write (ThriftTransport *transport, const gpointer buf,
|
||||
const guint32 len, GError **error)
|
||||
{
|
||||
ThriftSSLSocket *ssl_socket = THRIFT_SSL_SOCKET (transport);
|
||||
gint ret = 0;
|
||||
guint sent = 0;
|
||||
ThriftSocket *socket = THRIFT_SSL_SOCKET (transport);
|
||||
g_return_val_if_fail (socket->sd != THRIFT_INVALID_SOCKET, FALSE);
|
||||
|
||||
while (sent < len)
|
||||
{
|
||||
ret = SSL_write (ssl_socket->ssl, (guint8 *)buf + sent, len - sent);
|
||||
if (ret < 0)
|
||||
{
|
||||
g_set_error (error, THRIFT_TRANSPORT_ERROR,
|
||||
THRIFT_TRANSPORT_ERROR_SEND,
|
||||
"failed to send %d bytes - %s", len, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
sent += ret;
|
||||
}
|
||||
|
||||
return sent==len;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_write_end
|
||||
* called when write is complete. nothing to do on our end. */
|
||||
gboolean
|
||||
thrift_ssl_socket_write_end (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
/* satisfy -Wall */
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* implements thrift_transport_flush
|
||||
* flush pending data. since we are not buffered, this is a no-op */
|
||||
gboolean
|
||||
thrift_ssl_socket_flush (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
ThriftSSLSocket *ssl_socket = THRIFT_SSL_SOCKET (transport);
|
||||
gint ret = 0;
|
||||
guint sent = 0;
|
||||
BIO* bio = SSL_get_wbio(ssl_socket->ssl);
|
||||
if (bio == NULL) {
|
||||
g_set_error (error, THRIFT_TRANSPORT_ERROR,
|
||||
THRIFT_TRANSPORT_ERROR_SEND,
|
||||
"failed to flush, wbio returned null");
|
||||
return FALSE;
|
||||
}
|
||||
if (BIO_flush(bio) != 1) {
|
||||
g_set_error (error, THRIFT_TRANSPORT_ERROR,
|
||||
THRIFT_TRANSPORT_ERROR_SEND,
|
||||
"failed to flush it returned error");
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
thrift_ssl_socket_handle_handshake(ThriftTransport * transport, GError **error)
|
||||
{
|
||||
ThriftSSLSocket *ssl_socket = THRIFT_SSL_SOCKET (transport);
|
||||
ThriftSocket *socket = THRIFT_SOCKET (transport);
|
||||
g_return_val_if_fail (thrift_transport_is_open (transport), FALSE);
|
||||
|
||||
if(THRIFT_SSL_SOCKET_GET_CLASS(ssl_socket)->create_ssl_context(transport, error)){
|
||||
/*Context created*/
|
||||
SSL_set_fd(ssl_socket->ssl, socket->sd);
|
||||
int rc;
|
||||
if(ssl_socket->server){
|
||||
rc = SSL_accept(ssl_socket->ssl);
|
||||
}else{
|
||||
rc = SSL_connect(ssl_socket->ssl);
|
||||
}
|
||||
if (rc <= 0) {
|
||||
fprintf(stderr,"The error returned was %d\n", SSL_get_error(ssl_socket->ssl, rc));
|
||||
thrift_ssl_socket_get_error(error, "Not possible to connect", THRIFT_SSL_SOCKET_ERROR_CIPHER_NOT_AVAILABLE);
|
||||
return FALSE;
|
||||
}
|
||||
}else
|
||||
return FALSE;
|
||||
|
||||
return thrift_ssl_socket_authorize(transport, error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
thrift_ssl_socket_create_ssl_context(ThriftTransport * transport, GError **error)
|
||||
{
|
||||
ThriftSSLSocket *socket = THRIFT_SSL_SOCKET (transport);
|
||||
|
||||
if(socket->ctx!=NULL){
|
||||
if(socket->ssl!=NULL) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
socket->ssl = SSL_new(socket->ctx);
|
||||
if (socket->ssl == NULL) {
|
||||
g_set_error (error, THRIFT_TRANSPORT_ERROR,
|
||||
THRIFT_SSL_SOCKET_ERROR_TRANSPORT,
|
||||
"Unable to create default SSL context");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
gboolean thrift_ssl_load_cert_from_file(ThriftSSLSocket *ssl_socket, const char *file_name)
|
||||
{
|
||||
char error_buffer[255];
|
||||
if (!thrift_ssl_socket_openssl_initialized) {
|
||||
g_error("OpenSSL is not initialized yet");
|
||||
return FALSE;
|
||||
}
|
||||
int rc = SSL_CTX_load_verify_locations(ssl_socket->ctx, file_name, NULL);
|
||||
if (rc != 1) { /*verify authentication result*/
|
||||
ERR_error_string_n(ERR_get_error(), error_buffer, 254);
|
||||
g_warning("Load of certificates failed: %s!", error_buffer);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
gboolean thrift_ssl_load_cert_from_buffer(ThriftSSLSocket *ssl_socket, const char chain_certs[])
|
||||
{
|
||||
gboolean retval = FALSE;
|
||||
/* Load chain of certs*/
|
||||
X509 *cacert=NULL;
|
||||
BIO *mem = BIO_new_mem_buf(chain_certs,strlen(chain_certs));
|
||||
X509_STORE *cert_store = SSL_CTX_get_cert_store(ssl_socket->ctx);
|
||||
|
||||
if(cert_store!=NULL){
|
||||
int index = 0;
|
||||
while ((cacert = PEM_read_bio_X509(mem, NULL, 0, NULL))!=NULL) {
|
||||
if(cacert) {
|
||||
g_debug("Our certificate name is %s", cacert->name);
|
||||
X509_STORE_add_cert(cert_store, cacert);
|
||||
X509_free(cacert);
|
||||
cacert=NULL;
|
||||
} /* Free immediately */
|
||||
index++;
|
||||
}
|
||||
retval=TRUE;
|
||||
}
|
||||
BIO_free(mem);
|
||||
return retval;
|
||||
}
|
||||
|
||||
gboolean
|
||||
thrift_ssl_socket_authorize(ThriftTransport * transport, GError **error)
|
||||
{
|
||||
ThriftSocket *socket = THRIFT_SOCKET (transport);
|
||||
ThriftSSLSocket *ssl_socket = THRIFT_SSL_SOCKET (transport);
|
||||
ThriftSSLSocketClass *cls = THRIFT_SSL_SOCKET_GET_CLASS(ssl_socket);
|
||||
gboolean authorization_result = FALSE;
|
||||
|
||||
if(cls!=NULL && ssl_socket->ssl!=NULL){
|
||||
int rc = SSL_get_verify_result(ssl_socket->ssl);
|
||||
if (rc != X509_V_OK) { /* verify authentication result */
|
||||
if (rc == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT && ssl_socket->allow_selfsigned) {
|
||||
g_debug("The certificate is a self-signed certificate and configuration allows it");
|
||||
} else {
|
||||
g_error("The certificate verification failed: %s (%d)", X509_verify_cert_error_string(rc), rc);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
X509* cert = SSL_get_peer_certificate(ssl_socket->ssl);
|
||||
if (cert == NULL) {
|
||||
if (SSL_get_verify_mode(ssl_socket->ssl) & SSL_VERIFY_FAIL_IF_NO_PEER_CERT) {
|
||||
g_error("No certificate present");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_debug("No certificate required");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* certificate is present, since we don't support access manager we are done */
|
||||
if (cls->authorize_peer == NULL) {
|
||||
X509_free(cert);
|
||||
g_debug("Certificate presented but we're not checking it");
|
||||
return TRUE;
|
||||
} else {
|
||||
/* both certificate and access manager are present */
|
||||
struct sockaddr_storage sa;
|
||||
socklen_t saLength = sizeof(struct sockaddr_storage);
|
||||
|
||||
if (getpeername(socket->sd, (struct sockaddr*)&sa, &saLength) != 0) {
|
||||
sa.ss_family = AF_UNSPEC;
|
||||
}
|
||||
|
||||
authorization_result = cls->authorize_peer(transport, cert, &sa, error);
|
||||
}
|
||||
|
||||
if(cert != NULL) {
|
||||
X509_free(cert);
|
||||
}
|
||||
}
|
||||
|
||||
return authorization_result;
|
||||
}
|
||||
|
||||
|
||||
/* initializes the instance */
|
||||
static void
|
||||
thrift_ssl_socket_init (ThriftSSLSocket *socket)
|
||||
{
|
||||
GError *error = NULL;
|
||||
socket->ssl = NULL;
|
||||
socket->ctx = thrift_ssl_socket_context_initialize(SSLTLS, &error);
|
||||
if(socket->ctx == NULL) {
|
||||
g_info("The SSL context was not automatically initialized with protocol %d", SSLTLS);
|
||||
if(error!=NULL){
|
||||
g_info("Reported reason %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
}
|
||||
socket->server = FALSE;
|
||||
socket->allow_selfsigned = FALSE;
|
||||
|
||||
}
|
||||
|
||||
/* destructor */
|
||||
static void
|
||||
thrift_ssl_socket_finalize (GObject *object)
|
||||
{
|
||||
ThriftSSLSocket *socket = THRIFT_SSL_SOCKET (object);
|
||||
GError *error=NULL;
|
||||
if(socket!=NULL){
|
||||
g_debug("Instance %p destroyed", (void *)socket);
|
||||
if(socket->ssl != NULL)
|
||||
{
|
||||
thrift_ssl_socket_close(THRIFT_TRANSPORT(object), &error);
|
||||
socket->ssl=NULL;
|
||||
}
|
||||
|
||||
if(socket->ctx!=NULL){
|
||||
g_debug("Freeing the context for the instance");
|
||||
SSL_CTX_free(socket->ctx);
|
||||
}
|
||||
socket->ctx=NULL;
|
||||
}
|
||||
|
||||
if (G_OBJECT_CLASS (thrift_ssl_socket_parent_class)->finalize)
|
||||
(*G_OBJECT_CLASS (thrift_ssl_socket_parent_class)->finalize) (object);
|
||||
}
|
||||
|
||||
/* property accessor */
|
||||
void
|
||||
thrift_ssl_socket_get_property (GObject *object, guint property_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftSSLSocket *socket = THRIFT_SSL_SOCKET (object);
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_SSL_SOCKET_CONTEXT:
|
||||
g_value_set_pointer (value, socket->ctx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* property mutator */
|
||||
void
|
||||
thrift_ssl_socket_set_property (GObject *object, guint property_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ThriftSSLSocket *socket = THRIFT_SSL_SOCKET (object);
|
||||
|
||||
THRIFT_UNUSED_VAR (pspec);
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_THRIFT_SSL_SOCKET_CONTEXT:
|
||||
if(socket->ctx!=NULL){
|
||||
g_debug("Freeing the context since we are setting a new one");
|
||||
SSL_CTX_free(socket->ctx);
|
||||
}
|
||||
socket->ctx = g_value_get_pointer(value); // We copy the context
|
||||
break;
|
||||
|
||||
case PROP_THRIFT_SSL_SELF_SIGNED:
|
||||
socket->allow_selfsigned = g_value_get_boolean(value);
|
||||
break;
|
||||
default:
|
||||
g_warning("Trying to set property %i that doesn't exists!", property_id);
|
||||
/* thrift_socket_set_property(object, property_id, value, pspec); */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
thrift_ssl_socket_initialize_openssl(void)
|
||||
{
|
||||
if(thrift_ssl_socket_openssl_initialized){
|
||||
return;
|
||||
}
|
||||
thrift_ssl_socket_openssl_initialized=TRUE;
|
||||
SSL_library_init();
|
||||
ERR_load_crypto_strings();
|
||||
SSL_load_error_strings();
|
||||
ERR_load_BIO_strings();
|
||||
|
||||
/* Setup locking */
|
||||
g_debug("We setup %d threads locks", thrift_ssl_socket_static_thread_setup());
|
||||
|
||||
/* dynamic locking
|
||||
CRYPTO_set_dynlock_create_callback(thrift_ssl_socket_dyn_lock_create_callback);
|
||||
CRYPTO_set_dynlock_lock_callback(thrift_ssl_socket_dyn_lock_callback);
|
||||
CRYPTO_set_dynlock_destroy_callback(thrift_ssl_socket_dyn_lock_destroy_callback);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void thrift_ssl_socket_finalize_openssl(void)
|
||||
{
|
||||
if (!thrift_ssl_socket_openssl_initialized) {
|
||||
return;
|
||||
}
|
||||
thrift_ssl_socket_openssl_initialized = FALSE;
|
||||
|
||||
g_debug("We cleared %d threads locks", thrift_ssl_socket_static_thread_cleanup());
|
||||
/* Not supported
|
||||
CRYPTO_set_locking_callback(NULL);
|
||||
CRYPTO_set_dynlock_create_callback(NULL);
|
||||
CRYPTO_set_dynlock_lock_callback(NULL);
|
||||
CRYPTO_set_dynlock_destroy_callback(NULL);
|
||||
*/
|
||||
ERR_free_strings();
|
||||
EVP_cleanup();
|
||||
CRYPTO_cleanup_all_ex_data();
|
||||
ERR_remove_state(0);
|
||||
}
|
||||
|
||||
|
||||
/* initializes the class */
|
||||
static void
|
||||
thrift_ssl_socket_class_init (ThriftSSLSocketClass *cls)
|
||||
{
|
||||
ThriftTransportClass *ttc = THRIFT_TRANSPORT_CLASS (cls);
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
|
||||
GParamSpec *param_spec = NULL;
|
||||
|
||||
g_debug("Initialization of ThriftSSLSocketClass");
|
||||
/* setup accessors and mutators */
|
||||
gobject_class->get_property = thrift_ssl_socket_get_property;
|
||||
gobject_class->set_property = thrift_ssl_socket_set_property;
|
||||
param_spec = g_param_spec_pointer ("ssl_context",
|
||||
"SSLContext",
|
||||
"Set the SSL context for handshake with the remote host",
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class, PROP_THRIFT_SSL_SOCKET_CONTEXT,
|
||||
param_spec);
|
||||
param_spec = g_param_spec_boolean ("ssl_accept_selfsigned",
|
||||
"Accept Self Signed",
|
||||
"Whether or not accept self signed certificate",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class, PROP_THRIFT_SSL_SELF_SIGNED,
|
||||
param_spec);
|
||||
/* Class methods */
|
||||
cls->handle_handshake = thrift_ssl_socket_handle_handshake;
|
||||
cls->create_ssl_context = thrift_ssl_socket_create_ssl_context;
|
||||
|
||||
/* Override */
|
||||
gobject_class->finalize = thrift_ssl_socket_finalize;
|
||||
ttc->is_open = thrift_ssl_socket_is_open;
|
||||
ttc->peek = thrift_ssl_socket_peek;
|
||||
ttc->open = thrift_ssl_socket_open;
|
||||
ttc->close = thrift_ssl_socket_close;
|
||||
ttc->read = thrift_ssl_socket_read;
|
||||
ttc->read_end = thrift_ssl_socket_read_end;
|
||||
ttc->write = thrift_ssl_socket_write;
|
||||
ttc->write_end = thrift_ssl_socket_write_end;
|
||||
ttc->flush = thrift_ssl_socket_flush;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Public API
|
||||
*/
|
||||
ThriftSSLSocket*
|
||||
thrift_ssl_socket_new(ThriftSSLSocketProtocol ssl_protocol, GError **error)
|
||||
{
|
||||
ThriftSSLSocket *thriftSSLSocket = NULL;
|
||||
SSL_CTX *ssl_context = NULL;
|
||||
/* Create the context */
|
||||
if((ssl_context=thrift_ssl_socket_context_initialize(ssl_protocol, error))==NULL){
|
||||
g_warning("We cannot initialize context for protocol %d", ssl_protocol);
|
||||
return thriftSSLSocket;
|
||||
}
|
||||
|
||||
/* FIXME if the protocol is different? */
|
||||
thriftSSLSocket = g_object_new (THRIFT_TYPE_SSL_SOCKET, "ssl_context", ssl_context, NULL);
|
||||
return thriftSSLSocket;
|
||||
}
|
||||
|
||||
ThriftSSLSocket*
|
||||
thrift_ssl_socket_new_with_host(ThriftSSLSocketProtocol ssl_protocol, gchar *hostname, guint port, GError **error)
|
||||
{
|
||||
ThriftSSLSocket *thriftSSLSocket = NULL;
|
||||
SSL_CTX *ssl_context = NULL;
|
||||
/* Create the context */
|
||||
if((ssl_context=thrift_ssl_socket_context_initialize(ssl_protocol, error))==NULL){
|
||||
// FIXME Do error control
|
||||
return thriftSSLSocket;
|
||||
}
|
||||
/* FIXME if the protocol is different? */
|
||||
thriftSSLSocket = g_object_new (THRIFT_TYPE_SSL_SOCKET, "ssl_context", ssl_context, "hostname", hostname, "port", port, NULL);
|
||||
return thriftSSLSocket;
|
||||
}
|
||||
|
||||
void thrift_ssl_socket_set_manager(ThriftSSLSocket *ssl_socket, AUTHORIZATION_MANAGER_CALLBACK callback)
|
||||
{
|
||||
ThriftSSLSocketClass *sslSocketClass = THRIFT_SSL_SOCKET_GET_CLASS (ssl_socket);
|
||||
if(sslSocketClass){
|
||||
sslSocketClass->authorize_peer = callback;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SSL_CTX*
|
||||
thrift_ssl_socket_context_initialize(ThriftSSLSocketProtocol ssl_protocol, GError **error)
|
||||
{
|
||||
SSL_CTX* context = NULL;
|
||||
switch(ssl_protocol){
|
||||
case SSLTLS:
|
||||
context = SSL_CTX_new(SSLv23_method());
|
||||
break;
|
||||
#ifndef OPENSSL_NO_SSL3
|
||||
case SSLv3:
|
||||
context = SSL_CTX_new(SSLv3_method());
|
||||
break;
|
||||
#endif
|
||||
case TLSv1_0:
|
||||
context = SSL_CTX_new(TLSv1_method());
|
||||
break;
|
||||
case TLSv1_1:
|
||||
context = SSL_CTX_new(TLSv1_1_method());
|
||||
break;
|
||||
case TLSv1_2:
|
||||
context = SSL_CTX_new(TLSv1_2_method());
|
||||
break;
|
||||
default:
|
||||
g_set_error (error, THRIFT_TRANSPORT_ERROR,
|
||||
THRIFT_SSL_SOCKET_ERROR_CIPHER_NOT_AVAILABLE,
|
||||
"The SSL protocol is unknown for %d", ssl_protocol);
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (context == NULL) {
|
||||
thrift_ssl_socket_get_error(error, "No cipher overlay", THRIFT_SSL_SOCKET_ERROR_CIPHER_NOT_AVAILABLE);
|
||||
return NULL;
|
||||
}
|
||||
SSL_CTX_set_mode(context, SSL_MODE_AUTO_RETRY);
|
||||
|
||||
// Disable horribly insecure SSLv2 and SSLv3 protocols but allow a handshake
|
||||
// with older clients so they get a graceful denial.
|
||||
if (ssl_protocol == SSLTLS) {
|
||||
SSL_CTX_set_options(context, SSL_OP_NO_SSLv2);
|
||||
SSL_CTX_set_options(context, SSL_OP_NO_SSLv3); // THRIFT-3164
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
void thrift_ssl_socket_get_error(GError **error, const guchar *error_msg, guint thrift_error_no)
|
||||
{
|
||||
unsigned long error_code;
|
||||
while ((error_code = ERR_get_error()) != 0) {
|
||||
const char* reason = ERR_reason_error_string(error_code);
|
||||
if (reason == NULL) {
|
||||
g_set_error (error, THRIFT_TRANSPORT_ERROR,
|
||||
thrift_error_no,
|
||||
"SSL error %lX: %s", error_code, error_msg);
|
||||
}else{
|
||||
g_set_error (error, THRIFT_TRANSPORT_ERROR,
|
||||
thrift_error_no,
|
||||
"SSL error %lX %s: %s", error_code,reason, error_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
231
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_ssl_socket.h
generated
vendored
Normal file
231
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_ssl_socket.h
generated
vendored
Normal file
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_SSL_SOCKET_H
|
||||
#define _THRIFT_SSL_SOCKET_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_socket.h>
|
||||
#include <thrift/c_glib/transport/thrift_platform_socket.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_ssl_socket.h
|
||||
* \brief SSL Socket implementation of a Thrift transport. Subclasses the
|
||||
* ThriftSocket class. Based on plain openssl.
|
||||
* In the future we should take a look to https://issues.apache.org/jira/browse/THRIFT-1016
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_SSL_SOCKET (thrift_ssl_socket_get_type ())
|
||||
#define THRIFT_SSL_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_SSL_SOCKET, ThriftSSLSocket))
|
||||
#define THRIFT_IS_SSL_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_SSL_SOCKET))
|
||||
#define THRIFT_SSL_SOCKET_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_SSL_SOCKET, ThriftSSLSocketClass))
|
||||
#define THRIFT_IS_SSL_SOCKET_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_SSL_SOCKET))
|
||||
#define THRIFT_SSL_SOCKET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_SSL_SOCKET, ThriftSSLSocketClass))
|
||||
|
||||
|
||||
/* define error/exception types */
|
||||
typedef enum
|
||||
{
|
||||
THRIFT_SSL_SOCKET_ERROR_TRANSPORT=7,
|
||||
THRIFT_SSL_SOCKET_ERROR_CIPHER_NOT_AVAILABLE,
|
||||
THRIFT_SSL_SOCKET_ERROR_SSL
|
||||
} ThriftSSLSocketError;
|
||||
|
||||
|
||||
typedef struct _ThriftSSLSocket ThriftSSLSocket;
|
||||
|
||||
/*!
|
||||
* Thrift SSL Socket instance.
|
||||
*/
|
||||
struct _ThriftSSLSocket
|
||||
{
|
||||
ThriftSocket parent;
|
||||
|
||||
/* private */
|
||||
SSL *ssl;
|
||||
SSL_CTX* ctx;
|
||||
gboolean server;
|
||||
gboolean allow_selfsigned;
|
||||
};
|
||||
|
||||
typedef struct _ThriftSSLSocketClass ThriftSSLSocketClass;
|
||||
typedef gboolean (* AUTHORIZATION_MANAGER_CALLBACK) (ThriftTransport * transport, X509 *cert, struct sockaddr_storage *addr, GError **error);
|
||||
|
||||
/*!
|
||||
* Thrift Socket class.
|
||||
*/
|
||||
struct _ThriftSSLSocketClass
|
||||
{
|
||||
ThriftSocketClass parent;
|
||||
|
||||
gboolean (* handle_handshake) (ThriftTransport * transport, GError **error);
|
||||
gboolean (* create_ssl_context) (ThriftTransport * transport, GError **error);
|
||||
gboolean (* authorize_peer) (ThriftTransport * transport, X509 *cert, struct sockaddr_storage *addr, GError **error);
|
||||
|
||||
/* Padding to allow adding up to 12 new virtual functions without
|
||||
* breaking ABI. */
|
||||
gpointer padding[12];
|
||||
};
|
||||
|
||||
enum _ThriftSSLSocketProtocol {
|
||||
SSLTLS = 0, /* Supports SSLv2 and SSLv3 handshake but only negotiates at TLSv1_0 or later. */
|
||||
/*SSLv2 = 1, HORRIBLY INSECURE! */
|
||||
SSLv3 = 2, /* Supports SSLv3 only - also horribly insecure! */
|
||||
TLSv1_0 = 3, /* Supports TLSv1_0 or later. */
|
||||
TLSv1_1 = 4, /* Supports TLSv1_1 or later. */
|
||||
TLSv1_2 = 5, /* Supports TLSv1_2 or later. */
|
||||
LATEST = TLSv1_2
|
||||
};
|
||||
typedef enum _ThriftSSLSocketProtocol ThriftSSLSocketProtocol;
|
||||
|
||||
|
||||
/* Internal functions */
|
||||
SSL_CTX*
|
||||
thrift_ssl_socket_context_initialize(ThriftSSLSocketProtocol ssl_protocol, GError **error);
|
||||
|
||||
|
||||
/* used by THRIFT_TYPE_SSL_SOCKET */
|
||||
GType thrift_ssl_socket_get_type (void);
|
||||
|
||||
/* Public API */
|
||||
|
||||
/**
|
||||
* @brief Returns a error message for a defined error code.
|
||||
*
|
||||
* It uses gobject error functionality to get the error code of the last error
|
||||
* produced by this API.
|
||||
*
|
||||
* @param error Pointer to the error message.
|
||||
* @param error_msg Adds this message to the error that will be added to the
|
||||
* code.
|
||||
* @param thrift_error_no number of the error triggered.
|
||||
*
|
||||
* @see https://developer.gnome.org/glib/stable/glib-Error-Reporting.html#g-set-error
|
||||
*/
|
||||
void thrift_ssl_socket_get_error(GError **error, const guchar *error_msg, guint thrift_error_no);
|
||||
|
||||
/**
|
||||
* @brief Set a pinning manager instead of the default one.
|
||||
*
|
||||
* The pinning manager will be used during the SSL handshake to check certificate
|
||||
* and pinning parameters.
|
||||
*
|
||||
* @param ssl_socket SSL Socket to operate on.
|
||||
* @param callback function that will take the control while validating pinning
|
||||
*
|
||||
*/
|
||||
void thrift_ssl_socket_set_manager(ThriftSSLSocket *ssl_socket, AUTHORIZATION_MANAGER_CALLBACK callback);
|
||||
|
||||
/* This is the SSL API */
|
||||
/**
|
||||
* Convenience function to create a new SSL context with the protocol specified
|
||||
* and assign this new context to the created ThriftSSLSocket with specified host:port.
|
||||
* @param ssl_protocol
|
||||
* @param hostname
|
||||
* @param port
|
||||
* @param error
|
||||
* @return
|
||||
*/
|
||||
ThriftSSLSocket*
|
||||
thrift_ssl_socket_new_with_host(ThriftSSLSocketProtocol ssl_protocol, gchar *hostname, guint port, GError **error);
|
||||
|
||||
/**
|
||||
* Convenience function to create a new SSL context with the protocol specified
|
||||
* and assign this new context to the created ThriftSSLSocket.
|
||||
* @param ssl_protocol
|
||||
* @param error
|
||||
* @return
|
||||
*/
|
||||
ThriftSSLSocket*
|
||||
thrift_ssl_socket_new(ThriftSSLSocketProtocol ssl_protocol, GError **error);
|
||||
|
||||
/**
|
||||
* Load a certificate chain from a PEM file.
|
||||
* @param ssl_socket The ssl socket
|
||||
* @param file_name The file name of the PEM certificate chain
|
||||
* @return
|
||||
*/
|
||||
gboolean
|
||||
thrift_ssl_load_cert_from_file(ThriftSSLSocket *ssl_socket, const char *file_name);
|
||||
|
||||
/**
|
||||
* Load a certificate chain from memory
|
||||
* @param ssl_socket the ssl socket
|
||||
* @param chain_certs the buffer to load PEM from
|
||||
* @return
|
||||
*/
|
||||
gboolean
|
||||
thrift_ssl_load_cert_from_buffer(ThriftSSLSocket *ssl_socket, const char chain_certs[]);
|
||||
|
||||
/**
|
||||
* Check if the ssl socket is open and ready to send and receive
|
||||
* @param transport
|
||||
* @return true if open
|
||||
*/
|
||||
gboolean
|
||||
thrift_ssl_socket_is_open (ThriftTransport *transport);
|
||||
|
||||
|
||||
/**
|
||||
* Open connection if required and set the socket to be ready to send and receive
|
||||
* @param transport
|
||||
* @param error
|
||||
* @return true if operation was correct
|
||||
*/
|
||||
gboolean
|
||||
thrift_ssl_socket_open (ThriftTransport *transport, GError **error);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialization function
|
||||
*
|
||||
* It will initialize OpenSSL function. This initialization will be done app
|
||||
* wide. So if you want to initialize it by yourself you should not call it.
|
||||
* But it means you must handle OpenSSL initialization and handle locking.
|
||||
*
|
||||
* It should be called before anything else.
|
||||
*
|
||||
*
|
||||
*/
|
||||
void
|
||||
thrift_ssl_socket_initialize_openssl(void);
|
||||
/**
|
||||
* @brief Finalization function
|
||||
*
|
||||
* It clears all resources initialized in initialize function.
|
||||
*
|
||||
* It should be called after anything else.
|
||||
*
|
||||
*
|
||||
*/
|
||||
void
|
||||
thrift_ssl_socket_finalize_openssl(void);
|
||||
|
||||
G_END_DECLS
|
||||
#endif
|
||||
162
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_transport.c
generated
vendored
Normal file
162
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_transport.c
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
|
||||
/* define the GError domain string */
|
||||
#define THRIFT_TRANSPORT_ERROR_DOMAIN "thrift-transport-error-quark"
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE(ThriftTransport, thrift_transport, G_TYPE_OBJECT)
|
||||
|
||||
gboolean
|
||||
thrift_transport_is_open (ThriftTransport *transport)
|
||||
{
|
||||
return THRIFT_TRANSPORT_GET_CLASS (transport)->is_open (transport);
|
||||
}
|
||||
|
||||
gboolean
|
||||
thrift_transport_peek (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
return THRIFT_TRANSPORT_GET_CLASS (transport)->peek (transport, error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
thrift_transport_open (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
return THRIFT_TRANSPORT_GET_CLASS (transport)->open (transport, error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
thrift_transport_close (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
return THRIFT_TRANSPORT_GET_CLASS (transport)->close (transport, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_transport_read (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error)
|
||||
{
|
||||
return THRIFT_TRANSPORT_GET_CLASS (transport)->read (transport, buf,
|
||||
len, error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
thrift_transport_read_end (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
return THRIFT_TRANSPORT_GET_CLASS (transport)->read_end (transport,
|
||||
error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
thrift_transport_write (ThriftTransport *transport, const gpointer buf,
|
||||
const guint32 len, GError **error)
|
||||
{
|
||||
return THRIFT_TRANSPORT_GET_CLASS (transport)->write (transport, buf,
|
||||
len, error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
thrift_transport_write_end (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
return THRIFT_TRANSPORT_GET_CLASS (transport)->write_end (transport,
|
||||
error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
thrift_transport_flush (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
return THRIFT_TRANSPORT_GET_CLASS (transport)->flush (transport, error);
|
||||
}
|
||||
|
||||
gint32
|
||||
thrift_transport_read_all (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error)
|
||||
{
|
||||
return THRIFT_TRANSPORT_GET_CLASS (transport)->read_all (transport, buf,
|
||||
len, error);
|
||||
}
|
||||
|
||||
/* by default, peek returns true if and only if the transport is open */
|
||||
static gboolean
|
||||
thrift_transport_real_peek (ThriftTransport *transport, GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
|
||||
return THRIFT_TRANSPORT_GET_CLASS (transport)->is_open (transport);
|
||||
}
|
||||
|
||||
static gint32
|
||||
thrift_transport_real_read_all (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error)
|
||||
{
|
||||
ThriftTransportClass *ttc;
|
||||
guint32 have;
|
||||
gint32 ret;
|
||||
gint8 *bytes;
|
||||
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
|
||||
ttc = THRIFT_TRANSPORT_GET_CLASS (transport);
|
||||
have = 0;
|
||||
ret = 0;
|
||||
bytes = (gint8*) buf;
|
||||
|
||||
while (have < len) {
|
||||
if ((ret = ttc->read (transport, (gpointer) (bytes + have), len - have,
|
||||
error)) < 0) {
|
||||
return ret;
|
||||
}
|
||||
have += ret;
|
||||
}
|
||||
|
||||
return have;
|
||||
}
|
||||
|
||||
/* define the GError domain for Thrift transports */
|
||||
GQuark
|
||||
thrift_transport_error_quark (void)
|
||||
{
|
||||
return g_quark_from_static_string (THRIFT_TRANSPORT_ERROR_DOMAIN);
|
||||
}
|
||||
|
||||
/* class initializer for ThriftTransport */
|
||||
static void
|
||||
thrift_transport_class_init (ThriftTransportClass *cls)
|
||||
{
|
||||
/* set these as virtual methods to be implemented by a subclass */
|
||||
cls->is_open = thrift_transport_is_open;
|
||||
cls->open = thrift_transport_open;
|
||||
cls->close = thrift_transport_close;
|
||||
cls->read = thrift_transport_read;
|
||||
cls->read_end = thrift_transport_read_end;
|
||||
cls->write = thrift_transport_write;
|
||||
cls->write_end = thrift_transport_write_end;
|
||||
cls->flush = thrift_transport_flush;
|
||||
|
||||
/* provide a default implementation for the peek and read_all methods */
|
||||
cls->peek = thrift_transport_real_peek;
|
||||
cls->read_all = thrift_transport_real_read_all;
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_transport_init (ThriftTransport *transport)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (transport);
|
||||
}
|
||||
176
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_transport.h
generated
vendored
Normal file
176
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_transport.h
generated
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_TRANSPORT_H
|
||||
#define _THRIFT_TRANSPORT_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_transport.h
|
||||
* \brief Abstract class for Thrift transports.
|
||||
*
|
||||
* An abstract class is used instead of an interface because:
|
||||
* - interfaces can't seem to be used as properties. ThriftProtocol has
|
||||
* a ThriftTransport as an object property.
|
||||
* - if a method needs to be added that all subclasses can use, a class
|
||||
* is necessary.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_TRANSPORT (thrift_transport_get_type ())
|
||||
#define THRIFT_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_TRANSPORT, ThriftTransport))
|
||||
#define THRIFT_IS_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_TRANSPORT))
|
||||
#define THRIFT_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_TRANSPORT, ThriftTransportClass))
|
||||
#define THRIFT_IS_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_TRANSPORT))
|
||||
#define THRIFT_TRANSPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_TRANSPORT, ThriftTransportClass))
|
||||
|
||||
typedef struct _ThriftTransport ThriftTransport;
|
||||
|
||||
/*!
|
||||
* Thrift Protocol object
|
||||
*/
|
||||
struct _ThriftTransport
|
||||
{
|
||||
GObject parent;
|
||||
};
|
||||
|
||||
typedef struct _ThriftTransportClass ThriftTransportClass;
|
||||
|
||||
/*!
|
||||
* Thrift Transport class
|
||||
*/
|
||||
struct _ThriftTransportClass
|
||||
{
|
||||
GObjectClass parent;
|
||||
|
||||
/* vtable */
|
||||
gboolean (*is_open) (ThriftTransport *transport);
|
||||
gboolean (*peek) (ThriftTransport *transport, GError **error);
|
||||
gboolean (*open) (ThriftTransport *transport, GError **error);
|
||||
gboolean (*close) (ThriftTransport *transport, GError **error);
|
||||
gint32 (*read) (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error);
|
||||
gboolean (*read_end) (ThriftTransport *transport, GError **error);
|
||||
gboolean (*write) (ThriftTransport *transport, const gpointer buf,
|
||||
const guint32 len, GError **error);
|
||||
gboolean (*write_end) (ThriftTransport *transport, GError **error);
|
||||
gboolean (*flush) (ThriftTransport *transport, GError **error);
|
||||
gint32 (*read_all) (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error);
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_TRANSPORT */
|
||||
GType thrift_transport_get_type (void);
|
||||
|
||||
/* virtual public methods */
|
||||
|
||||
/*!
|
||||
* Checks if this transport is opened.
|
||||
* \public \memberof ThriftTransportInterface
|
||||
*/
|
||||
gboolean thrift_transport_is_open (ThriftTransport *transport);
|
||||
|
||||
/*!
|
||||
* Open the transport for reading and writing.
|
||||
* \public \memberof ThriftTransportInterface
|
||||
*/
|
||||
gboolean thrift_transport_open (ThriftTransport *transport, GError **error);
|
||||
|
||||
/*!
|
||||
* Tests whether there is more data to read or if the remote side is still
|
||||
* open. By default this is true whenever the transport is open, but
|
||||
* implementations should add logic to test for this condition where possible
|
||||
* (i.e. on a socket).
|
||||
*
|
||||
* This is used by a server to check if it should listen for another request.
|
||||
* \public \memberof ThriftTransportInterface
|
||||
*/
|
||||
gboolean thrift_transport_peek (ThriftTransport *transport, GError **error);
|
||||
|
||||
/*!
|
||||
* Close the transport.
|
||||
* \public \memberof ThriftTransportInterface
|
||||
*/
|
||||
gboolean thrift_transport_close (ThriftTransport *transport, GError **error);
|
||||
|
||||
/*!
|
||||
* Read some data into the buffer buf.
|
||||
* \public \memberof ThriftTransportInterface
|
||||
*/
|
||||
gint32 thrift_transport_read (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error);
|
||||
|
||||
/*!
|
||||
* Called when read is completed.
|
||||
* \public \memberof ThriftTransportInterface
|
||||
*/
|
||||
gboolean thrift_transport_read_end (ThriftTransport *transport, GError **error);
|
||||
|
||||
/*!
|
||||
* Writes data from a buffer to the transport.
|
||||
* \public \memberof ThriftTransportInterface
|
||||
*/
|
||||
gboolean thrift_transport_write (ThriftTransport *transport, const gpointer buf,
|
||||
const guint32 len, GError **error);
|
||||
|
||||
/*!
|
||||
* Called when write is completed.
|
||||
* \public \memberof ThriftTransportInterface
|
||||
*/
|
||||
gboolean thrift_transport_write_end (ThriftTransport *transport,
|
||||
GError **error);
|
||||
|
||||
/*!
|
||||
* Flushes any pending data to be written. Typically used with buffered
|
||||
* transport mechanisms.
|
||||
* \public \memberof ThriftTransportInterface
|
||||
*/
|
||||
gboolean thrift_transport_flush (ThriftTransport *transport, GError **error);
|
||||
|
||||
/*!
|
||||
* Read len bytes of data into the buffer buf.
|
||||
* \public \memberof ThriftTransportInterface
|
||||
*/
|
||||
gint32 thrift_transport_read_all (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error);
|
||||
|
||||
/* define error/exception types */
|
||||
typedef enum
|
||||
{
|
||||
THRIFT_TRANSPORT_ERROR_UNKNOWN,
|
||||
THRIFT_TRANSPORT_ERROR_HOST,
|
||||
THRIFT_TRANSPORT_ERROR_SOCKET,
|
||||
THRIFT_TRANSPORT_ERROR_CONNECT,
|
||||
THRIFT_TRANSPORT_ERROR_SEND,
|
||||
THRIFT_TRANSPORT_ERROR_RECEIVE,
|
||||
THRIFT_TRANSPORT_ERROR_CLOSE
|
||||
} ThriftTransportError;
|
||||
|
||||
/* define an error domain for GError to use */
|
||||
GQuark thrift_transport_error_quark (void);
|
||||
#define THRIFT_TRANSPORT_ERROR (thrift_transport_error_quark ())
|
||||
|
||||
/* define macro for invalid socket */
|
||||
#define THRIFT_INVALID_SOCKET (-1)
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_TRANSPORT_H */
|
||||
44
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_transport_factory.c
generated
vendored
Normal file
44
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_transport_factory.c
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/transport/thrift_transport_factory.h>
|
||||
|
||||
G_DEFINE_TYPE(ThriftTransportFactory, thrift_transport_factory, G_TYPE_OBJECT)
|
||||
|
||||
/* builds a transport from the base transport. */
|
||||
ThriftTransport *
|
||||
thrift_transport_factory_get_transport (ThriftTransportFactory *factory,
|
||||
ThriftTransport *transport)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (factory);
|
||||
return transport;
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_transport_factory_class_init (ThriftTransportFactoryClass *cls)
|
||||
{
|
||||
cls->get_transport = thrift_transport_factory_get_transport;
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_transport_factory_init (ThriftTransportFactory *factory)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (factory);
|
||||
}
|
||||
71
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_transport_factory.h
generated
vendored
Normal file
71
vendor/github.com/apache/thrift/lib/c_glib/src/thrift/c_glib/transport/thrift_transport_factory.h
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _THRIFT_TRANSPORT_FACTORY_H
|
||||
#define _THRIFT_TRANSPORT_FACTORY_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "thrift_transport.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*! \file thrift_transport_factory.h
|
||||
* \brief Base class for Thrift Transport Factories. Used by Thrift Servers
|
||||
* to obtain a client transport from an existing transport. The default
|
||||
* implementation simply clones the provided transport.
|
||||
*/
|
||||
|
||||
/* type macros */
|
||||
#define THRIFT_TYPE_TRANSPORT_FACTORY (thrift_transport_factory_get_type ())
|
||||
#define THRIFT_TRANSPORT_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_TRANSPORT_FACTORY, ThriftTransportFactory))
|
||||
#define THRIFT_IS_TRANSPORT_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_TRANSPORT_FACTORY))
|
||||
#define THRIFT_TRANSPORT_FACTORY_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_TRANSPORT_FACTORY, ThriftTransportFactoryClass))
|
||||
#define THRIFT_IS_TRANSPORT_FACTORY_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_TRANSPORT_FACTORY))
|
||||
#define THRIFT_TRANSPORT_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_TRANSPORT_FACTORY, ThriftTransportFactoryClass))
|
||||
|
||||
typedef struct _ThriftTransportFactory ThriftTransportFactory;
|
||||
|
||||
/* Thrift Transport Factory instance */
|
||||
struct _ThriftTransportFactory
|
||||
{
|
||||
GObject parent;
|
||||
};
|
||||
|
||||
typedef struct _ThriftTransportFactoryClass ThriftTransportFactoryClass;
|
||||
|
||||
/* Thrift Transport Factory class */
|
||||
struct _ThriftTransportFactoryClass
|
||||
{
|
||||
GObjectClass parent;
|
||||
|
||||
/* vtable */
|
||||
ThriftTransport *(*get_transport) (ThriftTransportFactory *factory,
|
||||
ThriftTransport *transport);
|
||||
};
|
||||
|
||||
/* used by THRIFT_TYPE_TRANSPORT_FACTORY */
|
||||
GType thrift_transport_factory_get_type (void);
|
||||
|
||||
/* virtual public methods */
|
||||
ThriftTransport *thrift_transport_factory_get_transport (ThriftTransportFactory *factory, ThriftTransport *transport);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _THRIFT_TRANSPORT_FACTORY_H */
|
||||
200
vendor/github.com/apache/thrift/lib/c_glib/test/CMakeLists.txt
generated
vendored
Normal file
200
vendor/github.com/apache/thrift/lib/c_glib/test/CMakeLists.txt
generated
vendored
Normal file
@@ -0,0 +1,200 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
|
||||
set(TEST_PREFIX "c_glib")
|
||||
|
||||
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
|
||||
|
||||
#Make sure gen-cpp and gen-c_glib files can be included
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
# Create the thrift C test library
|
||||
set(testgenc_SOURCES
|
||||
gen-c_glib/t_test_debug_proto_test_types.c
|
||||
gen-c_glib/t_test_enum_test_types.c
|
||||
gen-c_glib/t_test_enum_test_service.c
|
||||
gen-c_glib/t_test_empty_service.c
|
||||
gen-c_glib/t_test_inherited.c
|
||||
gen-c_glib/t_test_optional_required_test_types.c
|
||||
gen-c_glib/t_test_reverse_order_service.c
|
||||
gen-c_glib/t_test_second_service.c
|
||||
gen-c_glib/t_test_service_for_exception_with_a_map.c
|
||||
gen-c_glib/t_test_srv.c
|
||||
gen-c_glib/t_test_thrift_test.c
|
||||
gen-c_glib/t_test_thrift_test_types.c
|
||||
gen-c_glib/t_test_debug_proto_test_types.h
|
||||
gen-c_glib/t_test_enum_test_types.h
|
||||
gen-c_glib/t_test_enum_test_service.h
|
||||
gen-c_glib/t_test_empty_service.h
|
||||
gen-c_glib/t_test_inherited.h
|
||||
gen-c_glib/t_test_optional_required_test_types.h
|
||||
gen-c_glib/t_test_reverse_order_service.h
|
||||
gen-c_glib/t_test_second_service.h
|
||||
gen-c_glib/t_test_service_for_exception_with_a_map.h
|
||||
gen-c_glib/t_test_srv.h
|
||||
gen-c_glib/t_test_thrift_test.h
|
||||
gen-c_glib/t_test_thrift_test_types.h
|
||||
)
|
||||
|
||||
add_library(testgenc STATIC ${testgenc_SOURCES})
|
||||
LINK_AGAINST_THRIFT_LIBRARY(testgenc thrift_c_glib)
|
||||
|
||||
|
||||
add_executable(testserialization testserialization.c)
|
||||
target_link_libraries(testserialization testgenc)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(testserialization thrift_c_glib)
|
||||
add_test(NAME testserialization COMMAND testserialization)
|
||||
|
||||
add_executable(testapplicationexception testapplicationexception.c)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(testapplicationexception thrift_c_glib)
|
||||
add_test(NAME testapplicationexception COMMAND testapplicationexception)
|
||||
|
||||
add_executable(testtransportsocket testtransportsocket.c)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(testtransportsocket thrift_c_glib)
|
||||
add_test(NAME testtransportsocket COMMAND testtransportsocket)
|
||||
|
||||
add_executable(testbinaryprotocol testbinaryprotocol.c)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(testbinaryprotocol thrift_c_glib)
|
||||
add_test(NAME testbinaryprotocol COMMAND testbinaryprotocol)
|
||||
|
||||
add_executable(testcompactprotocol testcompactprotocol.c)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(testcompactprotocol thrift_c_glib)
|
||||
add_test(NAME testcompactprotocol COMMAND testcompactprotocol)
|
||||
|
||||
add_executable(testbufferedtransport testbufferedtransport.c)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(testbufferedtransport thrift_c_glib)
|
||||
add_test(NAME testbufferedtransport COMMAND testbufferedtransport)
|
||||
|
||||
add_executable(testframedtransport testframedtransport.c)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(testframedtransport thrift_c_glib)
|
||||
add_test(NAME testframedtransport COMMAND testframedtransport)
|
||||
|
||||
add_executable(testfdtransport testfdtransport.c)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(testfdtransport thrift_c_glib)
|
||||
add_test(NAME testfdtransport COMMAND testfdtransport)
|
||||
|
||||
add_executable(testmemorybuffer testmemorybuffer.c)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(testmemorybuffer thrift_c_glib)
|
||||
add_test(NAME testmemorybuffer COMMAND testmemorybuffer)
|
||||
|
||||
add_executable(testsimpleserver testsimpleserver.c)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(testsimpleserver thrift_c_glib)
|
||||
add_test(NAME testsimpleserver COMMAND testsimpleserver)
|
||||
|
||||
add_executable(testdebugproto testdebugproto.c)
|
||||
target_link_libraries(testdebugproto testgenc)
|
||||
add_test(NAME testdebugproto COMMAND testdebugproto)
|
||||
|
||||
add_executable(testoptionalrequired testoptionalrequired.c)
|
||||
target_link_libraries(testoptionalrequired testgenc)
|
||||
add_test(NAME testoptionalrequired COMMAND testoptionalrequired)
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}/test/c_glib/src" "${CMAKE_CURRENT_BINARY_DIR}/gen-c_glib")
|
||||
|
||||
add_executable(testthrifttest testthrifttest.c
|
||||
${PROJECT_SOURCE_DIR}/test/c_glib/src/thrift_test_handler.c
|
||||
${PROJECT_SOURCE_DIR}/test/c_glib/src/thrift_test_handler.h
|
||||
gen-c_glib/t_test_thrift_test_types.h)
|
||||
target_link_libraries(testthrifttest testgenc)
|
||||
add_test(NAME testthrifttest COMMAND testthrifttest)
|
||||
|
||||
|
||||
if(BUILD_CPP)
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}/lib/cpp/src")
|
||||
|
||||
# Create the thrift C++ test library
|
||||
set(testgenc_cpp_SOURCES
|
||||
gen-cpp/ThriftTest.cpp
|
||||
gen-cpp/ThriftTest_constants.cpp
|
||||
gen-cpp/ThriftTest_types.cpp
|
||||
gen-cpp/ThriftTest.h
|
||||
gen-cpp/ThriftTest_constants.h
|
||||
gen-cpp/ThriftTest_types.h
|
||||
)
|
||||
|
||||
add_library(testgenc_cpp STATIC ${testgenc_cpp_SOURCES})
|
||||
LINK_AGAINST_THRIFT_LIBRARY(testgenc_cpp thrift)
|
||||
|
||||
#HACK: testthrifttestclient.cpp includes ThriftTest.h without gen-*/ prefixes
|
||||
# so we include it here
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}/gen-cpp" "${CMAKE_CURRENT_BINARY_DIR}/gen-c_glib")
|
||||
|
||||
add_executable(testthrifttestclient testthrifttestclient.cpp)
|
||||
target_link_libraries(testthrifttestclient testgenc testgenc_cpp ${ZLIB_LIBRARIES})
|
||||
add_test(NAME testthrifttestclient COMMAND testthrifttestclient)
|
||||
|
||||
endif(BUILD_CPP)
|
||||
|
||||
#
|
||||
# Common thrift code generation rules
|
||||
#
|
||||
|
||||
add_custom_command(OUTPUT
|
||||
gen-c_glib/t_test_debug_proto_test_types.c
|
||||
gen-c_glib/t_test_debug_proto_test_types.h
|
||||
gen-c_glib/t_test_empty_service.c
|
||||
gen-c_glib/t_test_empty_service.h
|
||||
gen-c_glib/t_test_inherited.c
|
||||
gen-c_glib/t_test_inherited.h
|
||||
gen-c_glib/t_test_reverse_order_service.c
|
||||
gen-c_glib/t_test_reverse_order_service.h
|
||||
gen-c_glib/t_test_service_for_exception_with_a_map.c
|
||||
gen-c_glib/t_test_service_for_exception_with_a_map.h
|
||||
gen-c_glib/t_test_srv.c
|
||||
gen-c_glib/t_test_srv.h
|
||||
COMMAND ${THRIFT_COMPILER} --gen c_glib ${PROJECT_SOURCE_DIR}/test/DebugProtoTest.thrift
|
||||
)
|
||||
|
||||
add_custom_command(OUTPUT
|
||||
gen-c_glib/t_test_enum_test_types.c
|
||||
gen-c_glib/t_test_enum_test_types.h
|
||||
gen-c_glib/t_test_enum_test_service.c
|
||||
gen-c_glib/t_test_enum_test_service.h
|
||||
COMMAND ${THRIFT_COMPILER} --gen c_glib ${PROJECT_SOURCE_DIR}/test/EnumTest.thrift
|
||||
)
|
||||
|
||||
add_custom_command(OUTPUT
|
||||
gen-c_glib/t_test_optional_required_test_types.c
|
||||
gen-c_glib/t_test_optional_required_test_types.h
|
||||
COMMAND ${THRIFT_COMPILER} --gen c_glib ${PROJECT_SOURCE_DIR}/test/OptionalRequiredTest.thrift
|
||||
)
|
||||
|
||||
add_custom_command(OUTPUT
|
||||
gen-c_glib/t_test_second_service.c
|
||||
gen-c_glib/t_test_thrift_test.c
|
||||
gen-c_glib/t_test_thrift_test_types.c
|
||||
gen-c_glib/t_test_second_service.h
|
||||
gen-c_glib/t_test_thrift_test.h
|
||||
gen-c_glib/t_test_thrift_test_types.h
|
||||
COMMAND ${THRIFT_COMPILER} --gen c_glib ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
|
||||
)
|
||||
|
||||
add_custom_command(OUTPUT
|
||||
gen-cpp/ThriftTest.cpp
|
||||
gen-cpp/ThriftTest_constants.cpp
|
||||
gen-cpp/ThriftTest_types.cpp
|
||||
gen-cpp/ThriftTest.h
|
||||
gen-cpp/ThriftTest_constants.h
|
||||
gen-cpp/ThriftTest_types.h
|
||||
COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
|
||||
)
|
||||
|
||||
# TODO: Add memory checks using ctest_memcheck or similar
|
||||
35
vendor/github.com/apache/thrift/lib/c_glib/test/ContainerTest.thrift
generated
vendored
Normal file
35
vendor/github.com/apache/thrift/lib/c_glib/test/ContainerTest.thrift
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
namespace c_glib TTest
|
||||
|
||||
typedef list<string> StringList
|
||||
typedef list<StringList> ListStringList
|
||||
|
||||
struct ContainersWithDefaultValues {
|
||||
1: list<string> StringList = [ "Apache", "Thrift" ];
|
||||
}
|
||||
|
||||
service ContainerService {
|
||||
void receiveStringList(1: list<string> stringList);
|
||||
list<string> returnStringList();
|
||||
|
||||
list<list<string>> returnListStringList();
|
||||
ListStringList returnTypedefdListStringList();
|
||||
}
|
||||
326
vendor/github.com/apache/thrift/lib/c_glib/test/Makefile.am
generated
vendored
Executable file
326
vendor/github.com/apache/thrift/lib/c_glib/test/Makefile.am
generated
vendored
Executable file
@@ -0,0 +1,326 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
AUTOMAKE_OPTIONS = subdir-objects serial-tests
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
BUILT_SOURCES = \
|
||||
gen-c_glib/t_test_container_test_types.c \
|
||||
gen-c_glib/t_test_container_test_types.h \
|
||||
gen-c_glib/t_test_debug_proto_test_types.h \
|
||||
gen-c_glib/t_test_empty_service.h \
|
||||
gen-c_glib/t_test_inherited.h \
|
||||
gen-c_glib/t_test_optional_required_test_types.h \
|
||||
gen-c_glib/t_test_reverse_order_service.h \
|
||||
gen-c_glib/t_test_second_service.h \
|
||||
gen-c_glib/t_test_service_for_exception_with_a_map.h \
|
||||
gen-c_glib/t_test_container_service.c \
|
||||
gen-c_glib/t_test_container_service.h \
|
||||
gen-c_glib/t_test_srv.h \
|
||||
gen-c_glib/t_test_thrift_test.h \
|
||||
gen-c_glib/t_test_thrift_test_types.h
|
||||
|
||||
AM_CPPFLAGS = -I../src -I./gen-c_glib
|
||||
AM_CFLAGS = -g -Wall -Wextra -pedantic $(GLIB_CFLAGS) $(GOBJECT_CFLAGS) $(OPENSSL_INCLUDES) \
|
||||
@GCOV_CFLAGS@
|
||||
AM_CXXFLAGS = $(AM_CFLAGS)
|
||||
AM_LDFLAGS = $(GLIB_LIBS) $(GOBJECT_LIBS) $(OPENSSL_LIBS) @GCOV_LDFLAGS@
|
||||
|
||||
check_PROGRAMS = \
|
||||
testserialization \
|
||||
testapplicationexception \
|
||||
testcontainertest \
|
||||
testtransportsocket \
|
||||
testtransportsslsocket \
|
||||
testbinaryprotocol \
|
||||
testcompactprotocol \
|
||||
testbufferedtransport \
|
||||
testframedtransport \
|
||||
testfdtransport \
|
||||
testmemorybuffer \
|
||||
teststruct \
|
||||
testsimpleserver \
|
||||
testdebugproto \
|
||||
testoptionalrequired \
|
||||
testthrifttest
|
||||
|
||||
if WITH_CPP
|
||||
BUILT_SOURCES += gen-cpp/ThriftTest_types.cpp
|
||||
check_PROGRAMS += testthrifttestclient
|
||||
endif
|
||||
|
||||
testserialization_SOURCES = testserialization.c
|
||||
testserialization_LDADD = \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/protocol/libthrift_c_glib_la-thrift_protocol.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport.o \
|
||||
libtestgenc.la
|
||||
|
||||
testapplicationexception_SOURCES = testapplicationexception.c
|
||||
testapplicationexception_LDADD = \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/libthrift_c_glib_la-thrift_application_exception.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/protocol/libthrift_c_glib_la-thrift_protocol.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/libthrift_c_glib_la-thrift_struct.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport.o
|
||||
|
||||
testcontainertest_SOURCES = testcontainertest.c
|
||||
testcontainertest_LDADD = \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/libthrift_c_glib_la-thrift_struct.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/protocol/libthrift_c_glib_la-thrift_protocol.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport_factory.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/processor/libthrift_c_glib_la-thrift_processor.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/protocol/libthrift_c_glib_la-thrift_protocol_factory.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/protocol/libthrift_c_glib_la-thrift_binary_protocol.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/protocol/libthrift_c_glib_la-thrift_binary_protocol_factory.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_socket.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_server_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_server_socket.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/server/libthrift_c_glib_la-thrift_server.o \
|
||||
libtestgenc.la
|
||||
|
||||
testtransportsocket_SOURCES = testtransportsocket.c
|
||||
testtransportsocket_LDADD = \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_buffered_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_server_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_server_socket.o
|
||||
|
||||
|
||||
testtransportsslsocket_SOURCES = testtransportsslsocket.c
|
||||
testtransportsslsocket_LDADD = \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_socket.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_buffered_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_server_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_server_socket.o
|
||||
|
||||
|
||||
testbinaryprotocol_SOURCES = testbinaryprotocol.c
|
||||
testbinaryprotocol_LDADD = \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/protocol/libthrift_c_glib_la-thrift_protocol.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_framed_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_socket.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_server_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_server_socket.o
|
||||
|
||||
testcompactprotocol_SOURCES = testcompactprotocol.c
|
||||
testcompactprotocol_LDADD = \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/protocol/libthrift_c_glib_la-thrift_protocol.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_framed_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_socket.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_server_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_server_socket.o
|
||||
|
||||
testbufferedtransport_SOURCES = testbufferedtransport.c
|
||||
testbufferedtransport_LDADD = \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_socket.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_server_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_server_socket.o
|
||||
|
||||
testframedtransport_SOURCES = testframedtransport.c
|
||||
testframedtransport_LDADD = \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_socket.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_server_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_server_socket.o
|
||||
|
||||
testfdtransport_SOURCES = testfdtransport.c
|
||||
testfdtransport_LDADD = \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_fd_transport.o
|
||||
|
||||
testmemorybuffer_SOURCES = testmemorybuffer.c
|
||||
testmemorybuffer_LDADD = \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport.o
|
||||
|
||||
teststruct_SOURCES = teststruct.c
|
||||
teststruct_LDADD = \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/protocol/libthrift_c_glib_la-thrift_protocol.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport.o
|
||||
|
||||
testsimpleserver_SOURCES = testsimpleserver.c
|
||||
testsimpleserver_LDADD = \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/protocol/libthrift_c_glib_la-thrift_protocol.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport_factory.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/processor/libthrift_c_glib_la-thrift_processor.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/protocol/libthrift_c_glib_la-thrift_protocol_factory.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/protocol/libthrift_c_glib_la-thrift_binary_protocol.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/protocol/libthrift_c_glib_la-thrift_binary_protocol_factory.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_socket.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_server_transport.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_server_socket.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/server/libthrift_c_glib_la-thrift_server.o
|
||||
|
||||
testdebugproto_SOURCES = testdebugproto.c
|
||||
testdebugproto_LDADD = libtestgenc.la
|
||||
|
||||
testoptionalrequired_SOURCES = testoptionalrequired.c
|
||||
testoptionalrequired_LDADD = \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/protocol/libthrift_c_glib_la-thrift_protocol.o \
|
||||
$(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport.o \
|
||||
libtestgenc.la
|
||||
|
||||
testthrifttest_SOURCES = testthrifttest.c
|
||||
testthrifttest_LDADD = libtestgenc.la \
|
||||
$(top_builddir)/test/c_glib/src/thrift_test_handler.o
|
||||
testthrifttest_CFLAGS = -I$(top_srcdir)/test/c_glib/src -I./gen-c_glib $(GLIB_CFLAGS)
|
||||
|
||||
testthrifttestclient_SOURCES = testthrifttestclient.cpp
|
||||
testthrifttestclient_CPPFLAGS = -I../../cpp/src $(BOOST_CPPFLAGS) -I./gen-cpp -I../src -I./gen-c_glib $(GLIB_CFLAGS)
|
||||
testthrifttestclient_LDADD = ../../cpp/.libs/libthrift.la ../libthrift_c_glib.la libtestgenc.la libtestgencpp.la
|
||||
testthrifttestclient_LDFLAGS = -L../.libs -L../../cpp/.libs $(GLIB_LIBS) $(GOBJECT_LIBS)
|
||||
|
||||
check_LTLIBRARIES = libtestgenc.la
|
||||
|
||||
if WITH_CPP
|
||||
check_LTLIBRARIES += libtestgencpp.la
|
||||
endif
|
||||
|
||||
nodist_libtestgenc_la_SOURCES = \
|
||||
gen-c_glib/t_test_container_test_types.c \
|
||||
gen-c_glib/t_test_debug_proto_test_types.c \
|
||||
gen-c_glib/t_test_enum_test_types.c \
|
||||
gen-c_glib/t_test_enum_test_service.c \
|
||||
gen-c_glib/t_test_empty_service.c \
|
||||
gen-c_glib/t_test_inherited.c \
|
||||
gen-c_glib/t_test_optional_required_test_types.c \
|
||||
gen-c_glib/t_test_reverse_order_service.c \
|
||||
gen-c_glib/t_test_second_service.c \
|
||||
gen-c_glib/t_test_service_for_exception_with_a_map.c \
|
||||
gen-c_glib/t_test_srv.c \
|
||||
gen-c_glib/t_test_container_service.c \
|
||||
gen-c_glib/t_test_thrift_test.c \
|
||||
gen-c_glib/t_test_thrift_test_types.c \
|
||||
gen-c_glib/t_test_container_test_types.h \
|
||||
gen-c_glib/t_test_debug_proto_test_types.h \
|
||||
gen-c_glib/t_test_enum_test_types.h \
|
||||
gen-c_glib/t_test_enum_test_service.h \
|
||||
gen-c_glib/t_test_empty_service.h \
|
||||
gen-c_glib/t_test_inherited.h \
|
||||
gen-c_glib/t_test_optional_required_test_types.h \
|
||||
gen-c_glib/t_test_reverse_order_service.h \
|
||||
gen-c_glib/t_test_second_service.h \
|
||||
gen-c_glib/t_test_service_for_exception_with_a_map.h \
|
||||
gen-c_glib/t_test_srv.h \
|
||||
gen-c_glib/t_test_container_service.h \
|
||||
gen-c_glib/t_test_thrift_test.h \
|
||||
gen-c_glib/t_test_thrift_test_types.h
|
||||
libtestgenc_la_LIBADD = $(top_builddir)/lib/c_glib/libthrift_c_glib.la
|
||||
libtestgenc_la_CPPFLAGS = $(AM_CPPFLAGS) -Wno-unused-function
|
||||
|
||||
nodist_libtestgencpp_la_SOURCES = \
|
||||
gen-cpp/ThriftTest.cpp \
|
||||
gen-cpp/ThriftTest_constants.cpp \
|
||||
gen-cpp/ThriftTest_types.cpp \
|
||||
gen-cpp/ThriftTest.h \
|
||||
gen-cpp/ThriftTest_constants.h \
|
||||
gen-cpp/ThriftTest_types.h
|
||||
libtestgencpp_la_CPPFLAGS = -I../../cpp/src $(BOOST_CPPFLAGS) -I./gen-cpp
|
||||
|
||||
THRIFT = $(top_builddir)/compiler/cpp/thrift
|
||||
|
||||
gen-c_glib/t_test_container_test_types.c gen-c_glib/t_test_container_test_types.h gen-c_glib/t_test_container_service.c gen-c_glib/t_test_container_service.h: ContainerTest.thrift $(THRIFT)
|
||||
$(THRIFT) --gen c_glib $<
|
||||
|
||||
gen-c_glib/t_test_debug_proto_test_types.c gen-c_glib/t_test_debug_proto_test_types.h gen-c_glib/t_test_empty_service.c gen-c_glib/t_test_empty_service.h gen-c_glib/t_test_inherited.c gen-c_glib/t_test_inherited.h gen-c_glib/t_test_reverse_order_service.c gen-c_glib/t_test_reverse_order_service.h gen-c_glib/t_test_service_for_exception_with_a_map.c gen-c_glib/t_test_service_for_exception_with_a_map.h gen-c_glib/t_test_srv.c gen-c_glib/t_test_srv.h: ../../../test/DebugProtoTest.thrift $(THRIFT)
|
||||
$(THRIFT) --gen c_glib $<
|
||||
|
||||
gen-c_glib/t_test_enum_test_types.c gen-c_glib/t_test_enum_test_types.h gen-c_glib/t_test_enum_test_service.c gen-c_glib/t_test_enum_test_service.h : ../../../test/EnumTest.thrift $(THRIFT)
|
||||
$(THRIFT) --gen c_glib $<
|
||||
|
||||
gen-c_glib/t_test_optional_required_test_types.c gen-c_glib/t_test_optional_required_test_types.h: ../../../test/OptionalRequiredTest.thrift $(THRIFT)
|
||||
$(THRIFT) --gen c_glib $<
|
||||
|
||||
gen-c_glib/t_test_second_service.c gen-c_glib/t_test_thrift_test.c gen-c_glib/t_test_thrift_test_types.c gen-c_glib/t_test_second_service.h gen-c_glib/t_test_thrift_test.h gen-c_glib/t_test_thrift_test_types.h: ../../../test/ThriftTest.thrift $(THRIFT)
|
||||
$(THRIFT) --gen c_glib $<
|
||||
|
||||
gen-cpp/ThriftTest.cpp gen-cpp/ThriftTest_constants.cpp gen-cpp/ThriftTest_types.cpp: ../../../test/ThriftTest.thrift $(THRIFT)
|
||||
$(THRIFT) --gen cpp $<
|
||||
|
||||
TESTS = \
|
||||
$(check_PROGRAMS) \
|
||||
$(check_SCRIPTS)
|
||||
|
||||
# globally added to all instances of valgrind calls
|
||||
# VALGRIND_OPTS = --suppressions=glib.suppress
|
||||
VALGRIND_OPTS =
|
||||
|
||||
# globally added to all memcheck calls
|
||||
VALGRIND_MEM_OPTS = --tool=memcheck \
|
||||
--num-callers=10 \
|
||||
${myextravalgrindmemopts}
|
||||
|
||||
# globally added to all leakcheck calls
|
||||
VALGRIND_LEAK_OPTS = --tool=memcheck \
|
||||
--num-callers=10 \
|
||||
--leak-check=full \
|
||||
--leak-resolution=high \
|
||||
${myextravalgrindleakopts}
|
||||
|
||||
memcheck: $(check_PROGRAMS)
|
||||
@for x in $(check_PROGRAMS); \
|
||||
do \
|
||||
$(MAKE) memcheck-$$x; \
|
||||
done
|
||||
|
||||
leakcheck: $(check_PROGRAMS)
|
||||
@for x in $(check_PROGRAMS); \
|
||||
do \
|
||||
$(MAKE) leakcheck-$$x; \
|
||||
done
|
||||
|
||||
memcheck-%: %
|
||||
@echo "*****************************************"; \
|
||||
echo "MEMCHECK: $<"; \
|
||||
echo "ARGS: ${VALGRIND_OPTS} ${VALGRIND_MEM_OPTS} ${$<_VALGRIND_MEM_OPTS}"; \
|
||||
$(LIBTOOL) --mode=execute \
|
||||
valgrind \
|
||||
${VALGRIND_OPTS} \
|
||||
${VALGRIND_MEM_OPTS} \
|
||||
${$<_VALGRIND_MEM_OPTS} ./$<
|
||||
|
||||
leakcheck-%: %
|
||||
@echo "*****************************************"; \
|
||||
echo "LEAKCHECK: $<"; \
|
||||
echo "ARGS: ${VALGRIND_OPTS} ${VALGRIND_LEAK_OPTS} ${$<_VALGRIND_LEAK_OPTS}"; \
|
||||
G_SLICE=always-malloc $(LIBTOOL) --mode=execute \
|
||||
valgrind \
|
||||
${VALGRIND_OPTS} \
|
||||
${VALGRIND_LEAK_OPTS} \
|
||||
${$<_VALGRIND_LEAK_OPTS} ./$<
|
||||
|
||||
clean-local:
|
||||
$(RM) gen-c_glib/* gen-cpp/*
|
||||
|
||||
CLEANFILES = \
|
||||
*.bb \
|
||||
*.bbg \
|
||||
*.da \
|
||||
*.gcno \
|
||||
*.gcda \
|
||||
*.gcov
|
||||
|
||||
EXTRA_DIST = \
|
||||
CMakeLists.txt \
|
||||
ContainerTest.thrift
|
||||
|
||||
64
vendor/github.com/apache/thrift/lib/c_glib/test/glib.suppress
generated
vendored
Normal file
64
vendor/github.com/apache/thrift/lib/c_glib/test/glib.suppress
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
{
|
||||
g_type_init_1
|
||||
Memcheck:Leak
|
||||
fun:malloc
|
||||
...
|
||||
fun:g_type_init_with_debug_flags
|
||||
}
|
||||
|
||||
{
|
||||
g_type_init_2
|
||||
Memcheck:Leak
|
||||
fun:calloc
|
||||
...
|
||||
fun:g_type_init_with_debug_flags
|
||||
}
|
||||
|
||||
{
|
||||
g_type_init_3
|
||||
Memcheck:Leak
|
||||
fun:realloc
|
||||
...
|
||||
fun:g_type_init_with_debug_flags
|
||||
}
|
||||
|
||||
{
|
||||
g_type_register_static_1
|
||||
Memcheck:Leak
|
||||
fun:realloc
|
||||
...
|
||||
fun:g_type_register_static
|
||||
}
|
||||
|
||||
{
|
||||
g_type_register_statuc_2
|
||||
Memcheck:Leak
|
||||
fun:malloc
|
||||
fun:realloc
|
||||
fun:g_realloc
|
||||
...
|
||||
fun:g_type_register_static
|
||||
}
|
||||
|
||||
{
|
||||
type_class_init_Wm1
|
||||
Memcheck:Leak
|
||||
fun:calloc
|
||||
fun:g_malloc0
|
||||
fun:type_class_init_Wm
|
||||
fun:g_type_class_ref
|
||||
...
|
||||
fun:g_object_newv
|
||||
}
|
||||
|
||||
{
|
||||
type_class_init_Wm2
|
||||
Memcheck:Leak
|
||||
fun:calloc
|
||||
fun:g_malloc0
|
||||
fun:type_class_init_Wm
|
||||
fun:g_type_class_ref
|
||||
...
|
||||
fun:type_class_init_Wm
|
||||
}
|
||||
|
||||
180
vendor/github.com/apache/thrift/lib/c_glib/test/testapplicationexception.c
generated
vendored
Normal file
180
vendor/github.com/apache/thrift/lib/c_glib/test/testapplicationexception.c
generated
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <thrift/c_glib/thrift_application_exception.h>
|
||||
|
||||
static void
|
||||
test_create_and_destroy (void)
|
||||
{
|
||||
GObject *object = NULL;
|
||||
|
||||
/* A ThriftApplicationException can be created... */
|
||||
object = g_object_new (THRIFT_TYPE_APPLICATION_EXCEPTION, NULL);
|
||||
|
||||
g_assert (object != NULL);
|
||||
g_assert (THRIFT_IS_APPLICATION_EXCEPTION (object));
|
||||
|
||||
/* ...and destroyed */
|
||||
g_object_unref (object);
|
||||
}
|
||||
|
||||
static void
|
||||
test_initialize (void)
|
||||
{
|
||||
ThriftApplicationException *xception = NULL;
|
||||
gint32 type = THRIFT_APPLICATION_EXCEPTION_ERROR_INTERNAL_ERROR;
|
||||
gchar *message = "Exception message";
|
||||
gint32 retrieved_type = 0;
|
||||
gchar *retrieved_message = NULL;
|
||||
|
||||
/* A ThriftApplicationException has "type" and "message" properties that can
|
||||
be initialized at object creation */
|
||||
xception =
|
||||
g_object_new (THRIFT_TYPE_APPLICATION_EXCEPTION,
|
||||
"type", type,
|
||||
"message", message,
|
||||
NULL);
|
||||
|
||||
g_assert (xception != NULL);
|
||||
|
||||
/* A ThriftApplicationException's properties can be retrieved */
|
||||
g_object_get (xception,
|
||||
"type", &retrieved_type,
|
||||
"message", &retrieved_message,
|
||||
NULL);
|
||||
|
||||
g_assert (retrieved_type == type);
|
||||
g_assert (retrieved_message != NULL);
|
||||
g_assert_cmpstr (retrieved_message, ==, message);
|
||||
|
||||
g_free (retrieved_message);
|
||||
g_object_unref (xception);
|
||||
}
|
||||
|
||||
static void
|
||||
test_properties_test (void)
|
||||
{
|
||||
ThriftApplicationException *xception = NULL;
|
||||
gint32 retrieved_type;
|
||||
|
||||
xception = g_object_new (THRIFT_TYPE_APPLICATION_EXCEPTION, NULL);
|
||||
|
||||
#define TEST_TYPE_VALUE(_type) \
|
||||
retrieved_type = -1; \
|
||||
g_object_set (xception, "type", _type, NULL); \
|
||||
g_object_get (xception, "type", &retrieved_type, NULL); \
|
||||
g_assert_cmpint (retrieved_type, ==, _type);
|
||||
|
||||
/* The "type" property can be set to any valid Thrift exception type */
|
||||
TEST_TYPE_VALUE (THRIFT_APPLICATION_EXCEPTION_ERROR_UNKNOWN);
|
||||
TEST_TYPE_VALUE (THRIFT_APPLICATION_EXCEPTION_ERROR_UNKNOWN_METHOD);
|
||||
TEST_TYPE_VALUE (THRIFT_APPLICATION_EXCEPTION_ERROR_INVALID_MESSAGE_TYPE);
|
||||
TEST_TYPE_VALUE (THRIFT_APPLICATION_EXCEPTION_ERROR_WRONG_METHOD_NAME);
|
||||
TEST_TYPE_VALUE (THRIFT_APPLICATION_EXCEPTION_ERROR_BAD_SEQUENCE_ID);
|
||||
TEST_TYPE_VALUE (THRIFT_APPLICATION_EXCEPTION_ERROR_MISSING_RESULT);
|
||||
TEST_TYPE_VALUE (THRIFT_APPLICATION_EXCEPTION_ERROR_INTERNAL_ERROR);
|
||||
TEST_TYPE_VALUE (THRIFT_APPLICATION_EXCEPTION_ERROR_PROTOCOL_ERROR);
|
||||
TEST_TYPE_VALUE (THRIFT_APPLICATION_EXCEPTION_ERROR_INVALID_TRANSFORM);
|
||||
TEST_TYPE_VALUE (THRIFT_APPLICATION_EXCEPTION_ERROR_INVALID_PROTOCOL);
|
||||
TEST_TYPE_VALUE (THRIFT_APPLICATION_EXCEPTION_ERROR_UNSUPPORTED_CLIENT_TYPE);
|
||||
|
||||
/* "g_test_expect_message" is required for the property range tests below but is
|
||||
not present in GLib before version 2.34 */
|
||||
#if (GLIB_CHECK_VERSION (2, 34, 0))
|
||||
g_object_set (xception,
|
||||
"type", THRIFT_APPLICATION_EXCEPTION_ERROR_UNKNOWN,
|
||||
NULL);
|
||||
|
||||
/* The "type" property cannot be set to a value too low (less than zero) */
|
||||
g_test_expect_message ("GLib-GObject",
|
||||
G_LOG_LEVEL_WARNING,
|
||||
"value*out of range*type*");
|
||||
g_object_set (xception, "type", -1, NULL);
|
||||
g_test_assert_expected_messages ();
|
||||
|
||||
g_object_get (xception, "type", &retrieved_type, NULL);
|
||||
g_assert_cmpint (retrieved_type, !=, -1);
|
||||
g_assert_cmpint (retrieved_type,
|
||||
==,
|
||||
THRIFT_APPLICATION_EXCEPTION_ERROR_UNKNOWN);
|
||||
|
||||
/* The "type" property cannot be set to a value too high (greater than the
|
||||
highest defined exception-type value) */
|
||||
g_test_expect_message ("GLib-GObject",
|
||||
G_LOG_LEVEL_WARNING,
|
||||
"value*out of range*type*");
|
||||
g_object_set (xception, "type", THRIFT_APPLICATION_EXCEPTION_ERROR_N, NULL);
|
||||
g_test_assert_expected_messages ();
|
||||
|
||||
g_object_get (xception, "type", &retrieved_type, NULL);
|
||||
g_assert_cmpint (retrieved_type, !=, THRIFT_APPLICATION_EXCEPTION_ERROR_N);
|
||||
g_assert_cmpint (retrieved_type,
|
||||
==,
|
||||
THRIFT_APPLICATION_EXCEPTION_ERROR_UNKNOWN);
|
||||
#endif
|
||||
|
||||
g_object_unref (xception);
|
||||
}
|
||||
|
||||
static void
|
||||
test_properties_message (void)
|
||||
{
|
||||
ThriftApplicationException *xception = NULL;
|
||||
gchar *message = "Exception message";
|
||||
gchar *retrieved_message;
|
||||
|
||||
xception = g_object_new (THRIFT_TYPE_APPLICATION_EXCEPTION, NULL);
|
||||
|
||||
/* The "message" property can be set to NULL */
|
||||
g_object_set (xception, "message", NULL, NULL);
|
||||
g_object_get (xception, "message", &retrieved_message, NULL);
|
||||
g_assert (retrieved_message == NULL);
|
||||
|
||||
/* The "message" property can be set to a valid string */
|
||||
g_object_set (xception, "message", message, NULL);
|
||||
g_object_get (xception, "message", &retrieved_message, NULL);
|
||||
g_assert_cmpint (strcmp (retrieved_message, message), ==, 0);
|
||||
|
||||
g_free (retrieved_message);
|
||||
g_object_unref (xception);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
#if (!GLIB_CHECK_VERSION (2, 36, 0))
|
||||
g_type_init ();
|
||||
#endif
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/testapplicationexception/CreateAndDestroy",
|
||||
test_create_and_destroy);
|
||||
g_test_add_func ("/testapplicationexception/Initialize",
|
||||
test_initialize);
|
||||
g_test_add_func ("/testapplicationexception/Properties/test",
|
||||
test_properties_test);
|
||||
g_test_add_func ("/testapplicationexception/Properties/message",
|
||||
test_properties_message);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
860
vendor/github.com/apache/thrift/lib/c_glib/test/testbinaryprotocol.c
generated
vendored
Executable file
860
vendor/github.com/apache/thrift/lib/c_glib/test/testbinaryprotocol.c
generated
vendored
Executable file
@@ -0,0 +1,860 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/* Disable string-function optimizations when glibc is used, as these produce
|
||||
compiler warnings about string length when a string function is used inside
|
||||
a call to assert () */
|
||||
#ifdef __GLIBC__
|
||||
#include <features.h>
|
||||
#define __NO_STRING_INLINES 1
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <thrift/c_glib/protocol/thrift_protocol.h>
|
||||
#include <thrift/c_glib/transport/thrift_socket.h>
|
||||
#include <thrift/c_glib/transport/thrift_server_socket.h>
|
||||
#include <thrift/c_glib/transport/thrift_framed_transport.h>
|
||||
|
||||
#define TEST_BOOL TRUE
|
||||
#define TEST_BYTE 123
|
||||
#define TEST_I16 12345
|
||||
#define TEST_I32 1234567890
|
||||
#define TEST_I64 G_GINT64_CONSTANT (123456789012345)
|
||||
#define TEST_DOUBLE 1234567890.123
|
||||
#define TEST_STRING "this is a test string 1234567890!@#$%^&*()"
|
||||
#define TEST_PORT 51199
|
||||
|
||||
static int transport_read_count = 0;
|
||||
static int transport_read_error = 0;
|
||||
static int transport_read_error_at = -1;
|
||||
gint32
|
||||
my_thrift_transport_read_all (ThriftTransport *transport, gpointer buf,
|
||||
guint32 len, GError **error)
|
||||
{
|
||||
if (transport_read_count != transport_read_error_at
|
||||
&& transport_read_error == 0)
|
||||
{
|
||||
transport_read_count++;
|
||||
return thrift_transport_read_all (transport, buf, len, error);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int transport_write_count = 0;
|
||||
static int transport_write_error = 0;
|
||||
static int transport_write_error_at = -1;
|
||||
gboolean
|
||||
my_thrift_transport_write (ThriftTransport *transport, const gpointer buf,
|
||||
const guint32 len, GError **error)
|
||||
{
|
||||
if (transport_write_count != transport_write_error_at
|
||||
&& transport_write_error == 0)
|
||||
{
|
||||
transport_write_count++;
|
||||
return thrift_transport_write (transport, buf, len, error);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#define thrift_transport_read_all my_thrift_transport_read_all
|
||||
#define thrift_transport_write my_thrift_transport_write
|
||||
#include "../src/thrift/c_glib/protocol/thrift_binary_protocol.c"
|
||||
#undef thrift_transport_read_all
|
||||
#undef thrift_transport_write
|
||||
|
||||
static void thrift_server_primitives (const int port);
|
||||
static void thrift_server_complex_types (const int port);
|
||||
static void thrift_server_many_frames (const int port);
|
||||
|
||||
static void
|
||||
test_create_and_destroy(void)
|
||||
{
|
||||
GObject *object = NULL;
|
||||
|
||||
/* create an object and then destroy it */
|
||||
object = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, NULL);
|
||||
assert (object != NULL);
|
||||
g_object_unref (object);
|
||||
}
|
||||
|
||||
static void
|
||||
test_initialize(void)
|
||||
{
|
||||
ThriftSocket *tsocket = NULL;
|
||||
ThriftBinaryProtocol *protocol = NULL;
|
||||
ThriftSocket *temp = NULL;
|
||||
|
||||
/* create a ThriftTransport */
|
||||
tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
|
||||
"port", 51188, NULL);
|
||||
assert (tsocket != NULL);
|
||||
/* create a ThriftBinaryProtocol using the Transport */
|
||||
protocol = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
|
||||
tsocket, NULL);
|
||||
assert (protocol != NULL);
|
||||
/* fetch the properties */
|
||||
g_object_get (G_OBJECT(protocol), "transport", &temp, NULL);
|
||||
g_object_unref (temp);
|
||||
|
||||
/* clean up memory */
|
||||
g_object_unref (protocol);
|
||||
g_object_unref (tsocket);
|
||||
}
|
||||
|
||||
static void
|
||||
test_read_and_write_primitives(void)
|
||||
{
|
||||
int status;
|
||||
pid_t pid;
|
||||
ThriftSocket *tsocket = NULL;
|
||||
ThriftTransport *transport = NULL;
|
||||
ThriftBinaryProtocol *tb = NULL;
|
||||
ThriftProtocol *protocol = NULL;
|
||||
gpointer binary = (gpointer *) TEST_STRING;
|
||||
guint32 len = strlen (TEST_STRING);
|
||||
int port = TEST_PORT;
|
||||
|
||||
/* fork a server from the client */
|
||||
pid = fork ();
|
||||
assert (pid >= 0);
|
||||
|
||||
if (pid == 0)
|
||||
{
|
||||
/* child listens */
|
||||
thrift_server_primitives (port);
|
||||
exit (0);
|
||||
} else {
|
||||
/* parent. wait a bit for the socket to be created. */
|
||||
sleep (1);
|
||||
|
||||
/* create a ThriftSocket */
|
||||
tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
|
||||
"port", port, NULL);
|
||||
transport = THRIFT_TRANSPORT (tsocket);
|
||||
thrift_transport_open (transport, NULL);
|
||||
assert (thrift_transport_is_open (transport));
|
||||
|
||||
/* create a ThriftBinaryTransport */
|
||||
tb = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
|
||||
tsocket, NULL);
|
||||
protocol = THRIFT_PROTOCOL (tb);
|
||||
assert (protocol != NULL);
|
||||
|
||||
/* write a bunch of primitives */
|
||||
assert (thrift_binary_protocol_write_bool (protocol, TEST_BOOL, NULL) > 0);
|
||||
assert (thrift_binary_protocol_write_byte (protocol, TEST_BYTE, NULL) > 0);
|
||||
assert (thrift_binary_protocol_write_i16 (protocol, TEST_I16, NULL) > 0);
|
||||
assert (thrift_binary_protocol_write_i32 (protocol, TEST_I32, NULL) > 0);
|
||||
assert (thrift_binary_protocol_write_i64 (protocol, TEST_I64, NULL) > 0);
|
||||
assert (thrift_binary_protocol_write_double (protocol,
|
||||
TEST_DOUBLE, NULL) > 0);
|
||||
assert (thrift_binary_protocol_write_string (protocol,
|
||||
TEST_STRING, NULL) > 0);
|
||||
assert (thrift_binary_protocol_write_string (protocol, "", NULL) > 0);
|
||||
assert (thrift_binary_protocol_write_binary (protocol, binary,
|
||||
len, NULL) > 0);
|
||||
assert (thrift_binary_protocol_write_binary (protocol, NULL, 0, NULL) > 0);
|
||||
assert (thrift_binary_protocol_write_binary (protocol, binary,
|
||||
len, NULL) > 0);
|
||||
|
||||
/* test write errors */
|
||||
transport_write_error = 1;
|
||||
assert (thrift_binary_protocol_write_byte (protocol, TEST_BYTE,
|
||||
NULL) == -1);
|
||||
assert (thrift_binary_protocol_write_i16 (protocol, TEST_I16, NULL) == -1);
|
||||
assert (thrift_binary_protocol_write_i32 (protocol, TEST_I32, NULL) == -1);
|
||||
assert (thrift_binary_protocol_write_i64 (protocol, TEST_I64, NULL) == -1);
|
||||
assert (thrift_binary_protocol_write_double (protocol, TEST_DOUBLE,
|
||||
NULL) == -1);
|
||||
assert (thrift_binary_protocol_write_binary (protocol, binary, len,
|
||||
NULL) == -1);
|
||||
transport_write_error = 0;
|
||||
|
||||
/* test binary partial failure */
|
||||
transport_write_count = 0;
|
||||
transport_write_error_at = 1;
|
||||
assert (thrift_binary_protocol_write_binary (protocol, binary,
|
||||
len, NULL) == -1);
|
||||
transport_write_error_at = -1;
|
||||
|
||||
/* clean up */
|
||||
thrift_transport_close (transport, NULL);
|
||||
g_object_unref (tsocket);
|
||||
g_object_unref (protocol);
|
||||
assert (wait (&status) == pid);
|
||||
assert (status == 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_read_and_write_complex_types (void)
|
||||
{
|
||||
int status;
|
||||
pid_t pid;
|
||||
ThriftSocket *tsocket = NULL;
|
||||
ThriftTransport *transport = NULL;
|
||||
ThriftBinaryProtocol *tb = NULL;
|
||||
ThriftProtocol *protocol = NULL;
|
||||
int port = TEST_PORT;
|
||||
|
||||
/* fork a server from the client */
|
||||
pid = fork ();
|
||||
assert (pid >= 0);
|
||||
|
||||
if (pid == 0)
|
||||
{
|
||||
/* child listens */
|
||||
thrift_server_complex_types (port);
|
||||
exit (0);
|
||||
} else {
|
||||
/* parent. wait a bit for the socket to be created. */
|
||||
sleep (1);
|
||||
|
||||
/* create a ThriftSocket */
|
||||
tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
|
||||
"port", port, NULL);
|
||||
transport = THRIFT_TRANSPORT (tsocket);
|
||||
thrift_transport_open (transport, NULL);
|
||||
assert (thrift_transport_is_open (transport));
|
||||
|
||||
/* create a ThriftBinaryTransport */
|
||||
tb = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
|
||||
tsocket, NULL);
|
||||
protocol = THRIFT_PROTOCOL (tb);
|
||||
assert (protocol != NULL);
|
||||
|
||||
/* test structures */
|
||||
assert (thrift_binary_protocol_write_struct_begin (protocol,
|
||||
NULL, NULL) == 0);
|
||||
assert (thrift_binary_protocol_write_struct_end (protocol, NULL) == 0);
|
||||
|
||||
assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID,
|
||||
1, NULL) > 0);
|
||||
assert (thrift_binary_protocol_write_field_end (protocol, NULL) == 0);
|
||||
|
||||
/* test write error */
|
||||
transport_write_error = 1;
|
||||
assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID,
|
||||
1, NULL) == -1);
|
||||
transport_write_error = 0;
|
||||
|
||||
/* test 2nd write error */
|
||||
transport_write_count = 0;
|
||||
transport_write_error_at = 1;
|
||||
assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID,
|
||||
1, NULL) == -1);
|
||||
transport_write_error_at = -1;
|
||||
|
||||
/* test 2nd read failure on a field */
|
||||
thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
|
||||
|
||||
/* test write_field_stop */
|
||||
assert (thrift_binary_protocol_write_field_stop (protocol, NULL) > 0);
|
||||
|
||||
/* write a map */
|
||||
assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
|
||||
1, NULL) > 0);
|
||||
assert (thrift_binary_protocol_write_map_end (protocol, NULL) == 0);
|
||||
|
||||
/* test 2nd read failure on a map */
|
||||
thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
|
||||
|
||||
/* test 3rd read failure on a map */
|
||||
thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
|
||||
thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
|
||||
|
||||
/* test 1st write failure on a map */
|
||||
transport_write_error = 1;
|
||||
assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
|
||||
1, NULL) == -1);
|
||||
transport_write_error = 0;
|
||||
|
||||
/* test 2nd write failure on a map */
|
||||
transport_write_count = 0;
|
||||
transport_write_error_at = 1;
|
||||
assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
|
||||
1, NULL) == -1);
|
||||
transport_write_error_at = -1;
|
||||
|
||||
/* test 3rd write failure on a map */
|
||||
transport_write_count = 0;
|
||||
transport_write_error_at = 2;
|
||||
assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
|
||||
1, NULL) == -1);
|
||||
transport_write_error_at = -1;
|
||||
|
||||
/* test negative map size */
|
||||
thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
|
||||
thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
|
||||
thrift_binary_protocol_write_i32 (protocol, -10, NULL);
|
||||
|
||||
/* test list operations */
|
||||
assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
|
||||
1, NULL) > 0);
|
||||
assert (thrift_binary_protocol_write_list_end (protocol, NULL) == 0);
|
||||
|
||||
/* test 2nd read failure on a list */
|
||||
thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
|
||||
|
||||
/* test negative list size */
|
||||
thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
|
||||
thrift_binary_protocol_write_i32 (protocol, -10, NULL);
|
||||
|
||||
/* test first write error on a list */
|
||||
transport_write_error = 1;
|
||||
assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
|
||||
1, NULL) == -1);
|
||||
transport_write_error = 0;
|
||||
|
||||
/* test 2nd write error on a list */
|
||||
transport_write_count = 0;
|
||||
transport_write_error_at = 1;
|
||||
assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
|
||||
1, NULL) == -1);
|
||||
transport_write_error_at = -1;
|
||||
|
||||
/* test set operation s*/
|
||||
assert (thrift_binary_protocol_write_set_begin (protocol, T_VOID,
|
||||
1, NULL) > 0);
|
||||
assert (thrift_binary_protocol_write_set_end (protocol, NULL) == 0);
|
||||
|
||||
/* invalid version */
|
||||
assert (thrift_binary_protocol_write_i32 (protocol, -1, NULL) > 0);
|
||||
|
||||
/* sz > 0 for a message */
|
||||
assert (thrift_binary_protocol_write_i32 (protocol, 1, NULL) > 0);
|
||||
|
||||
/* send a valid message */
|
||||
thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);
|
||||
thrift_binary_protocol_write_string (protocol, "test", NULL);
|
||||
thrift_binary_protocol_write_i32 (protocol, 1, NULL);
|
||||
|
||||
/* broken 2nd read */
|
||||
thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);
|
||||
|
||||
/* send a broken 3rd read */
|
||||
thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);
|
||||
thrift_binary_protocol_write_string (protocol, "test", NULL);
|
||||
|
||||
/* send a valid message */
|
||||
assert (thrift_binary_protocol_write_message_begin (protocol, "test",
|
||||
T_CALL, 1, NULL) > 0);
|
||||
|
||||
assert (thrift_binary_protocol_write_message_end (protocol, NULL) == 0);
|
||||
|
||||
/* send broken writes */
|
||||
transport_write_error = 1;
|
||||
assert (thrift_binary_protocol_write_message_begin (protocol, "test",
|
||||
T_CALL, 1, NULL) == -1);
|
||||
transport_write_error = 0;
|
||||
|
||||
transport_write_count = 0;
|
||||
transport_write_error_at = 2;
|
||||
assert (thrift_binary_protocol_write_message_begin (protocol, "test",
|
||||
T_CALL, 1, NULL) == -1);
|
||||
transport_write_error_at = -1;
|
||||
|
||||
transport_write_count = 0;
|
||||
transport_write_error_at = 3;
|
||||
assert (thrift_binary_protocol_write_message_begin (protocol, "test",
|
||||
T_CALL, 1, NULL) == -1);
|
||||
transport_write_error_at = -1;
|
||||
|
||||
/* clean up */
|
||||
thrift_transport_close (transport, NULL);
|
||||
g_object_unref (tsocket);
|
||||
g_object_unref (protocol);
|
||||
assert (wait (&status) == pid);
|
||||
assert (status == 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_read_and_write_many_frames (void)
|
||||
{
|
||||
int status;
|
||||
pid_t pid;
|
||||
ThriftSocket *tsocket = NULL;
|
||||
ThriftTransport *transport = NULL;
|
||||
ThriftFramedTransport *ft = NULL;
|
||||
ThriftBinaryProtocol *tb = NULL;
|
||||
ThriftProtocol *protocol = NULL;
|
||||
gpointer binary = (gpointer *) TEST_STRING;
|
||||
const guint32 len = strlen (TEST_STRING);
|
||||
int port = TEST_PORT;
|
||||
|
||||
/* fork a server from the client */
|
||||
pid = fork ();
|
||||
assert (pid >= 0);
|
||||
|
||||
if (pid == 0)
|
||||
{
|
||||
/* child listens */
|
||||
thrift_server_many_frames (port);
|
||||
exit (0);
|
||||
} else {
|
||||
/* parent. wait a bit for the socket to be created. */
|
||||
sleep (1);
|
||||
|
||||
/* create a ThriftSocket */
|
||||
tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
|
||||
"port", port, NULL);
|
||||
assert (tsocket != NULL);
|
||||
transport = THRIFT_TRANSPORT (tsocket);
|
||||
|
||||
/* wrap in a framed transport */
|
||||
ft = g_object_new (THRIFT_TYPE_FRAMED_TRANSPORT, "transport", transport,
|
||||
"w_buf_size", 1, NULL);
|
||||
assert (ft != NULL);
|
||||
transport = THRIFT_TRANSPORT (ft);
|
||||
|
||||
thrift_transport_open (transport, NULL);
|
||||
assert (thrift_transport_is_open (transport));
|
||||
|
||||
/* create a binary protocol */
|
||||
tb = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
|
||||
transport, NULL);
|
||||
protocol = THRIFT_PROTOCOL (tb);
|
||||
assert (protocol != NULL);
|
||||
|
||||
/* write a bunch of primitives */
|
||||
assert (thrift_binary_protocol_write_bool (protocol, TEST_BOOL, NULL) > 0);
|
||||
thrift_transport_flush (transport, NULL);
|
||||
assert (thrift_binary_protocol_write_byte (protocol, TEST_BYTE, NULL) > 0);
|
||||
thrift_transport_flush (transport, NULL);
|
||||
assert (thrift_binary_protocol_write_i16 (protocol, TEST_I16, NULL) > 0);
|
||||
thrift_transport_flush (transport, NULL);
|
||||
assert (thrift_binary_protocol_write_i32 (protocol, TEST_I32, NULL) > 0);
|
||||
thrift_transport_flush (transport, NULL);
|
||||
assert (thrift_binary_protocol_write_i64 (protocol, TEST_I64, NULL) > 0);
|
||||
thrift_transport_flush (transport, NULL);
|
||||
assert (thrift_binary_protocol_write_double (protocol,
|
||||
TEST_DOUBLE, NULL) > 0);
|
||||
thrift_transport_flush (transport, NULL);
|
||||
assert (thrift_binary_protocol_write_string (protocol,
|
||||
TEST_STRING, NULL) > 0);
|
||||
thrift_transport_flush (transport, NULL);
|
||||
assert (thrift_binary_protocol_write_string (protocol, "", NULL) > 0);
|
||||
thrift_transport_flush (transport, NULL);
|
||||
assert (thrift_binary_protocol_write_binary (protocol, binary,
|
||||
len, NULL) > 0);
|
||||
thrift_transport_flush (transport, NULL);
|
||||
assert (thrift_binary_protocol_write_binary (protocol, NULL, 0, NULL) > 0);
|
||||
thrift_transport_flush (transport, NULL);
|
||||
assert (thrift_binary_protocol_write_binary (protocol, binary,
|
||||
len, NULL) > 0);
|
||||
thrift_transport_flush (transport, NULL);
|
||||
|
||||
/* clean up */
|
||||
thrift_transport_write_end (transport, NULL);
|
||||
thrift_transport_close (transport, NULL);
|
||||
g_object_unref (ft);
|
||||
g_object_unref (tsocket);
|
||||
g_object_unref (tb);
|
||||
assert (wait (&status) == pid);
|
||||
assert (status == 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
thrift_server_primitives (const int port)
|
||||
{
|
||||
ThriftServerTransport *transport = NULL;
|
||||
ThriftTransport *client = NULL;
|
||||
ThriftBinaryProtocol *tbp = NULL;
|
||||
ThriftProtocol *protocol = NULL;
|
||||
gboolean value_boolean = FALSE;
|
||||
gint8 value_byte = 0;
|
||||
gint16 value_16 = 0;
|
||||
gint32 value_32 = 0;
|
||||
gint64 value_64 = 0;
|
||||
gdouble value_double = 0;
|
||||
gchar *string = NULL;
|
||||
gchar *empty_string = NULL;
|
||||
gpointer binary = NULL;
|
||||
guint32 len = 0;
|
||||
void *comparator = (void *) TEST_STRING;
|
||||
|
||||
ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
|
||||
"port", port, NULL);
|
||||
transport = THRIFT_SERVER_TRANSPORT (tsocket);
|
||||
thrift_server_transport_listen (transport, NULL);
|
||||
client = thrift_server_transport_accept (transport, NULL);
|
||||
assert (client != NULL);
|
||||
|
||||
tbp = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
|
||||
client, NULL);
|
||||
protocol = THRIFT_PROTOCOL (tbp);
|
||||
|
||||
assert (thrift_binary_protocol_read_bool (protocol,
|
||||
&value_boolean, NULL) > 0);
|
||||
assert (thrift_binary_protocol_read_byte (protocol, &value_byte, NULL) > 0);
|
||||
assert (thrift_binary_protocol_read_i16 (protocol, &value_16, NULL) > 0);
|
||||
assert (thrift_binary_protocol_read_i32 (protocol, &value_32, NULL) > 0);
|
||||
assert (thrift_binary_protocol_read_i64 (protocol, &value_64, NULL) > 0);
|
||||
assert (thrift_binary_protocol_read_double (protocol,
|
||||
&value_double, NULL) > 0);
|
||||
assert (thrift_binary_protocol_read_string (protocol, &string, NULL) > 0);
|
||||
assert (thrift_binary_protocol_read_string (protocol, &empty_string,
|
||||
NULL) > 0);
|
||||
assert (thrift_binary_protocol_read_binary (protocol, &binary,
|
||||
&len, NULL) > 0);
|
||||
|
||||
assert (value_boolean == TEST_BOOL);
|
||||
assert (value_byte == TEST_BYTE);
|
||||
assert (value_16 == TEST_I16);
|
||||
assert (value_32 == TEST_I32);
|
||||
assert (value_64 == TEST_I64);
|
||||
assert (value_double == TEST_DOUBLE);
|
||||
assert (strcmp (TEST_STRING, string) == 0);
|
||||
assert (strcmp ("", empty_string) == 0);
|
||||
assert (memcmp (comparator, binary, len) == 0);
|
||||
|
||||
g_free (string);
|
||||
g_free (empty_string);
|
||||
g_free (binary);
|
||||
|
||||
assert (thrift_binary_protocol_read_binary (protocol, &binary,
|
||||
&len, NULL) > 0);
|
||||
assert (binary == NULL);
|
||||
assert (len == 0);
|
||||
g_free (binary);
|
||||
|
||||
transport_read_count = 0;
|
||||
transport_read_error_at = 0;
|
||||
assert (thrift_binary_protocol_read_binary (protocol, &binary,
|
||||
&len, NULL) == -1);
|
||||
transport_read_error_at = -1;
|
||||
|
||||
transport_read_count = 0;
|
||||
transport_read_error_at = 1;
|
||||
assert (thrift_binary_protocol_read_binary (protocol, &binary,
|
||||
&len, NULL) == -1);
|
||||
transport_read_error_at = -1;
|
||||
|
||||
transport_read_error = 1;
|
||||
assert (thrift_binary_protocol_read_bool (protocol,
|
||||
&value_boolean, NULL) == -1);
|
||||
assert (thrift_binary_protocol_read_byte (protocol,
|
||||
&value_byte, NULL) == -1);
|
||||
assert (thrift_binary_protocol_read_i16 (protocol,
|
||||
&value_16, NULL) == -1);
|
||||
assert (thrift_binary_protocol_read_i32 (protocol, &value_32, NULL) == -1);
|
||||
assert (thrift_binary_protocol_read_i64 (protocol, &value_64, NULL) == -1);
|
||||
assert (thrift_binary_protocol_read_double (protocol,
|
||||
&value_double, NULL) == -1);
|
||||
transport_read_error = 0;
|
||||
|
||||
/* test partial write failure */
|
||||
thrift_protocol_read_i32 (protocol, &value_32, NULL);
|
||||
|
||||
thrift_transport_read_end (client, NULL);
|
||||
thrift_transport_close (client, NULL);
|
||||
|
||||
g_object_unref (tbp);
|
||||
g_object_unref (client);
|
||||
g_object_unref (tsocket);
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_server_complex_types (const int port)
|
||||
{
|
||||
ThriftServerTransport *transport = NULL;
|
||||
ThriftTransport *client = NULL;
|
||||
ThriftBinaryProtocol *tbp = NULL;
|
||||
ThriftProtocol *protocol = NULL;
|
||||
gchar *struct_name = NULL;
|
||||
gchar *field_name = NULL;
|
||||
gchar *message_name = NULL;
|
||||
ThriftType element_type, key_type, value_type, field_type;
|
||||
ThriftMessageType message_type;
|
||||
gint8 value = 0;
|
||||
gint16 field_id = 0;
|
||||
guint32 size = 0;
|
||||
gint32 seqid = 0;
|
||||
gint32 version = 0;
|
||||
|
||||
ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
|
||||
"port", port, NULL);
|
||||
transport = THRIFT_SERVER_TRANSPORT (tsocket);
|
||||
thrift_server_transport_listen (transport, NULL);
|
||||
client = thrift_server_transport_accept (transport, NULL);
|
||||
assert (client != NULL);
|
||||
|
||||
tbp = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
|
||||
client, NULL);
|
||||
protocol = THRIFT_PROTOCOL (tbp);
|
||||
|
||||
thrift_binary_protocol_read_struct_begin (protocol, &struct_name, NULL);
|
||||
thrift_binary_protocol_read_struct_end (protocol, NULL);
|
||||
|
||||
thrift_binary_protocol_read_field_begin (protocol, &field_name, &field_type,
|
||||
&field_id, NULL);
|
||||
thrift_binary_protocol_read_field_end (protocol, NULL);
|
||||
|
||||
/* test first read error on a field */
|
||||
transport_read_error = 1;
|
||||
assert (thrift_binary_protocol_read_field_begin (protocol,
|
||||
&field_name, &field_type,
|
||||
&field_id, NULL) == -1);
|
||||
transport_read_error = 0;
|
||||
|
||||
/* test 2nd write failure */
|
||||
thrift_binary_protocol_read_byte (protocol, &value, NULL);
|
||||
|
||||
/* test 2nd read failure on a field */
|
||||
transport_read_count = 0;
|
||||
transport_read_error_at = 1;
|
||||
assert (thrift_binary_protocol_read_field_begin (protocol,
|
||||
&field_name, &field_type,
|
||||
&field_id, NULL) == -1);
|
||||
transport_read_error_at = -1;
|
||||
|
||||
/* test field stop */
|
||||
thrift_binary_protocol_read_field_begin (protocol, &field_name, &field_type,
|
||||
&field_id, NULL);
|
||||
|
||||
thrift_binary_protocol_read_map_begin (protocol, &key_type, &value_type,
|
||||
&size, NULL);
|
||||
thrift_binary_protocol_read_map_end (protocol, NULL);
|
||||
|
||||
/* test read failure on a map */
|
||||
transport_read_count = 0;
|
||||
transport_read_error_at = 0;
|
||||
assert (thrift_binary_protocol_read_map_begin (protocol,
|
||||
&key_type, &value_type,
|
||||
&size, NULL) == -1);
|
||||
transport_read_error_at = -1;
|
||||
|
||||
/* test 2nd read failure on a map */
|
||||
transport_read_count = 0;
|
||||
transport_read_error_at = 1;
|
||||
assert (thrift_binary_protocol_read_map_begin (protocol,
|
||||
&key_type, &value_type,
|
||||
&size, NULL) == -1);
|
||||
transport_read_error_at = -1;
|
||||
|
||||
/* test 3rd read failure on a map */
|
||||
transport_read_count = 0;
|
||||
transport_read_error_at = 2;
|
||||
assert (thrift_binary_protocol_read_map_begin (protocol,
|
||||
&key_type, &value_type,
|
||||
&size, NULL) == -1);
|
||||
transport_read_error_at = -1;
|
||||
|
||||
/* test 2nd write failure */
|
||||
thrift_binary_protocol_read_byte (protocol, &value, NULL);
|
||||
|
||||
/* test 3rd write failure */
|
||||
thrift_binary_protocol_read_byte (protocol, &value, NULL);
|
||||
thrift_binary_protocol_read_byte (protocol, &value, NULL);
|
||||
|
||||
/* test negative map size */
|
||||
assert (thrift_binary_protocol_read_map_begin (protocol,
|
||||
&key_type, &value_type,
|
||||
&size, NULL) == -1);
|
||||
|
||||
/* test list operations */
|
||||
thrift_binary_protocol_read_list_begin (protocol, &element_type, &size, NULL);
|
||||
thrift_binary_protocol_read_list_end (protocol, NULL);
|
||||
|
||||
/* test read failure */
|
||||
transport_read_error = 1;
|
||||
assert (thrift_binary_protocol_read_list_begin (protocol, &element_type,
|
||||
&size, NULL) == -1);
|
||||
transport_read_error = 0;
|
||||
|
||||
/* test 2nd read failure */
|
||||
transport_read_count = 0;
|
||||
transport_read_error_at = 1;
|
||||
thrift_binary_protocol_read_list_begin (protocol, &element_type, &size, NULL);
|
||||
transport_read_error_at = -1;
|
||||
|
||||
/* test negative list size failure */
|
||||
thrift_binary_protocol_read_list_begin (protocol, &element_type, &size, NULL);
|
||||
|
||||
/* test 2nd write failure */
|
||||
thrift_binary_protocol_read_byte (protocol, &value, NULL);
|
||||
|
||||
/* test set operations */
|
||||
thrift_binary_protocol_read_set_begin (protocol, &element_type, &size, NULL);
|
||||
thrift_binary_protocol_read_set_end (protocol, NULL);
|
||||
|
||||
/* broken read */
|
||||
transport_read_error = 1;
|
||||
assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
|
||||
&message_type, &seqid,
|
||||
NULL) == -1);
|
||||
transport_read_error = 0;
|
||||
|
||||
/* invalid protocol version */
|
||||
assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
|
||||
&message_type, &seqid,
|
||||
NULL) == -1);
|
||||
|
||||
/* sz > 0 */
|
||||
assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
|
||||
&message_type, &seqid,
|
||||
NULL) > 0);
|
||||
|
||||
/* read a valid message */
|
||||
assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
|
||||
&message_type, &seqid,
|
||||
NULL) > 0);
|
||||
g_free (message_name);
|
||||
|
||||
/* broken 2nd read on a message */
|
||||
transport_read_count = 0;
|
||||
transport_read_error_at = 1;
|
||||
assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
|
||||
&message_type, &seqid,
|
||||
NULL) == -1);
|
||||
transport_read_error_at = -1;
|
||||
|
||||
/* broken 3rd read on a message */
|
||||
transport_read_count = 0;
|
||||
transport_read_error_at = 3; /* read_string does two reads */
|
||||
assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
|
||||
&message_type, &seqid,
|
||||
NULL) == -1);
|
||||
g_free (message_name);
|
||||
transport_read_error_at = -1;
|
||||
|
||||
/* read a valid message */
|
||||
assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
|
||||
&message_type, &seqid,
|
||||
NULL) > 0);
|
||||
g_free (message_name);
|
||||
|
||||
assert (thrift_binary_protocol_read_message_end (protocol, NULL) == 0);
|
||||
|
||||
/* handle 2nd write failure on a message */
|
||||
thrift_binary_protocol_read_i32 (protocol, &version, NULL);
|
||||
|
||||
/* handle 2nd write failure on a message */
|
||||
thrift_binary_protocol_read_i32 (protocol, &version, NULL);
|
||||
thrift_binary_protocol_read_string (protocol, &message_name, NULL);
|
||||
|
||||
g_object_unref (client);
|
||||
/* TODO: investigate g_object_unref (tbp); */
|
||||
g_object_unref (tsocket);
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_server_many_frames (const int port)
|
||||
{
|
||||
ThriftServerTransport *transport = NULL;
|
||||
ThriftTransport *client = NULL;
|
||||
ThriftBinaryProtocol *tbp = NULL;
|
||||
ThriftProtocol *protocol = NULL;
|
||||
ThriftServerSocket *tsocket = NULL;
|
||||
gboolean value_boolean = FALSE;
|
||||
gint8 value_byte = 0;
|
||||
gint16 value_16 = 0;
|
||||
gint32 value_32 = 0;
|
||||
gint64 value_64 = 0;
|
||||
gdouble value_double = 0;
|
||||
gchar *string = NULL;
|
||||
gchar *empty_string = NULL;
|
||||
gpointer binary = NULL;
|
||||
guint32 len = 0;
|
||||
void *comparator = (void *) TEST_STRING;
|
||||
|
||||
tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET, "port", port, NULL);
|
||||
transport = THRIFT_SERVER_TRANSPORT (tsocket);
|
||||
thrift_server_transport_listen (transport, NULL);
|
||||
|
||||
/* wrap the client in a framed transport */
|
||||
client = g_object_new (THRIFT_TYPE_FRAMED_TRANSPORT, "transport",
|
||||
thrift_server_transport_accept (transport, NULL),
|
||||
"r_buf_size", 1, NULL);
|
||||
assert (client != NULL);
|
||||
|
||||
tbp = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
|
||||
client, NULL);
|
||||
protocol = THRIFT_PROTOCOL (tbp);
|
||||
|
||||
assert (thrift_binary_protocol_read_bool (protocol,
|
||||
&value_boolean, NULL) > 0);
|
||||
assert (thrift_binary_protocol_read_byte (protocol, &value_byte, NULL) > 0);
|
||||
assert (thrift_binary_protocol_read_i16 (protocol, &value_16, NULL) > 0);
|
||||
assert (thrift_binary_protocol_read_i32 (protocol, &value_32, NULL) > 0);
|
||||
assert (thrift_binary_protocol_read_i64 (protocol, &value_64, NULL) > 0);
|
||||
assert (thrift_binary_protocol_read_double (protocol,
|
||||
&value_double, NULL) > 0);
|
||||
assert (thrift_binary_protocol_read_string (protocol, &string, NULL) > 0);
|
||||
assert (thrift_binary_protocol_read_string (protocol, &empty_string,
|
||||
NULL) > 0);
|
||||
assert (thrift_binary_protocol_read_binary (protocol, &binary,
|
||||
&len, NULL) > 0);
|
||||
|
||||
assert (value_boolean == TEST_BOOL);
|
||||
assert (value_byte == TEST_BYTE);
|
||||
assert (value_16 == TEST_I16);
|
||||
assert (value_32 == TEST_I32);
|
||||
assert (value_64 == TEST_I64);
|
||||
assert (value_double == TEST_DOUBLE);
|
||||
assert (strcmp (TEST_STRING, string) == 0);
|
||||
assert (strcmp ("", empty_string) == 0);
|
||||
assert (memcmp (comparator, binary, len) == 0);
|
||||
|
||||
g_free (string);
|
||||
g_free (empty_string);
|
||||
g_free (binary);
|
||||
|
||||
assert (thrift_binary_protocol_read_binary (protocol, &binary,
|
||||
&len, NULL) > 0);
|
||||
assert (binary == NULL);
|
||||
assert (len == 0);
|
||||
g_free (binary);
|
||||
|
||||
thrift_transport_read_end (client, NULL);
|
||||
thrift_transport_close (client, NULL);
|
||||
|
||||
g_object_unref (tbp);
|
||||
g_object_unref (client);
|
||||
g_object_unref (tsocket);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
#if (!GLIB_CHECK_VERSION (2, 36, 0))
|
||||
g_type_init();
|
||||
#endif
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/testbinaryprotocol/CreateAndDestroy", test_create_and_destroy);
|
||||
g_test_add_func ("/testbinaryprotocol/Initialize", test_initialize);
|
||||
g_test_add_func ("/testbinaryprotocol/ReadAndWritePrimitives", test_read_and_write_primitives);
|
||||
g_test_add_func ("/testbinaryprotocol/ReadAndWriteComplexTypes", test_read_and_write_complex_types);
|
||||
g_test_add_func ("/testbinaryprotocol/ReadAndWriteManyFrames",
|
||||
test_read_and_write_many_frames);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
287
vendor/github.com/apache/thrift/lib/c_glib/test/testbufferedtransport.c
generated
vendored
Executable file
287
vendor/github.com/apache/thrift/lib/c_glib/test/testbufferedtransport.c
generated
vendored
Executable file
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <netdb.h>
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <thrift/c_glib/transport/thrift_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_socket.h>
|
||||
#include <thrift/c_glib/transport/thrift_server_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_server_socket.h>
|
||||
|
||||
#define TEST_DATA { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' }
|
||||
|
||||
#include "../src/thrift/c_glib/transport/thrift_buffered_transport.c"
|
||||
|
||||
static void thrift_server (const int port);
|
||||
|
||||
/* test object creation and destruction */
|
||||
static void
|
||||
test_create_and_destroy(void)
|
||||
{
|
||||
ThriftTransport *transport = NULL;
|
||||
guint r_buf_size = 0;
|
||||
guint w_buf_size = 0;
|
||||
|
||||
GObject *object = NULL;
|
||||
object = g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT, NULL);
|
||||
assert (object != NULL);
|
||||
g_object_get (G_OBJECT (object), "transport", &transport,
|
||||
"r_buf_size", &r_buf_size,
|
||||
"w_buf_size", &w_buf_size, NULL);
|
||||
g_object_unref (object);
|
||||
}
|
||||
|
||||
static void
|
||||
test_open_and_close(void)
|
||||
{
|
||||
ThriftSocket *tsocket = NULL;
|
||||
ThriftTransport *transport = NULL;
|
||||
GError *err = NULL;
|
||||
|
||||
/* create a ThriftSocket */
|
||||
tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
|
||||
"port", 51188, NULL);
|
||||
|
||||
/* create a BufferedTransport wrapper of the Socket */
|
||||
transport = g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT,
|
||||
"transport", THRIFT_TRANSPORT (tsocket), NULL);
|
||||
|
||||
/* this shouldn't work */
|
||||
assert (thrift_buffered_transport_open (transport, NULL) == FALSE);
|
||||
assert (thrift_buffered_transport_is_open (transport) == TRUE);
|
||||
assert (thrift_buffered_transport_close (transport, NULL) == TRUE);
|
||||
g_object_unref (transport);
|
||||
g_object_unref (tsocket);
|
||||
|
||||
/* try and underlying socket failure */
|
||||
tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost.broken",
|
||||
NULL);
|
||||
|
||||
/* create a BufferedTransport wrapper of the Socket */
|
||||
transport = g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT,
|
||||
"transport", THRIFT_TRANSPORT (tsocket), NULL);
|
||||
|
||||
assert (thrift_buffered_transport_open (transport, &err) == FALSE);
|
||||
g_object_unref (transport);
|
||||
g_object_unref (tsocket);
|
||||
g_error_free (err);
|
||||
err = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
test_read_and_write(void)
|
||||
{
|
||||
int status;
|
||||
pid_t pid;
|
||||
ThriftSocket *tsocket = NULL;
|
||||
ThriftTransport *transport = NULL;
|
||||
int port = 51199;
|
||||
guchar buf[10] = TEST_DATA; /* a buffer */
|
||||
|
||||
pid = fork ();
|
||||
assert ( pid >= 0 );
|
||||
|
||||
if ( pid == 0 )
|
||||
{
|
||||
/* child listens */
|
||||
thrift_server (port);
|
||||
exit (0);
|
||||
} else {
|
||||
/* parent connects, wait a bit for the socket to be created */
|
||||
sleep (1);
|
||||
|
||||
tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
|
||||
"port", port, NULL);
|
||||
transport = g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT,
|
||||
"transport", THRIFT_TRANSPORT (tsocket),
|
||||
"w_buf_size", 4, NULL);
|
||||
|
||||
assert (thrift_buffered_transport_open (transport, NULL) == TRUE);
|
||||
assert (thrift_buffered_transport_is_open (transport));
|
||||
|
||||
/* write 10 bytes */
|
||||
thrift_buffered_transport_write (transport, buf, 10, NULL);
|
||||
|
||||
/* write 1 byte at a time */
|
||||
thrift_buffered_transport_write (transport, buf, 1, NULL);
|
||||
thrift_buffered_transport_write (transport, buf, 1, NULL);
|
||||
thrift_buffered_transport_write (transport, buf, 1, NULL);
|
||||
|
||||
/* overflow the buffer */
|
||||
thrift_buffered_transport_write (transport, buf, 2, NULL);
|
||||
thrift_buffered_transport_write (transport, buf, 1, NULL);
|
||||
thrift_buffered_transport_flush (transport, NULL);
|
||||
|
||||
/* write 1 byte and flush */
|
||||
thrift_buffered_transport_write (transport, buf, 1, NULL);
|
||||
thrift_buffered_transport_flush (transport, NULL);
|
||||
|
||||
/* write and overflow buffer with 2 system calls */
|
||||
thrift_buffered_transport_write (transport, buf, 1, NULL);
|
||||
thrift_buffered_transport_write (transport, buf, 3, NULL);
|
||||
|
||||
/* write 10 bytes */
|
||||
thrift_buffered_transport_write (transport, buf, 10, NULL);
|
||||
|
||||
thrift_buffered_transport_write_end (transport, NULL);
|
||||
thrift_buffered_transport_flush (transport, NULL);
|
||||
thrift_buffered_transport_close (transport, NULL);
|
||||
|
||||
g_object_unref (transport);
|
||||
g_object_unref (tsocket);
|
||||
|
||||
assert ( wait (&status) == pid );
|
||||
assert ( status == 0 );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
thrift_server (const int port)
|
||||
{
|
||||
int bytes = 0;
|
||||
ThriftServerTransport *transport = NULL;
|
||||
ThriftTransport *client = NULL;
|
||||
guchar buf[10]; /* a buffer */
|
||||
guchar match[10] = TEST_DATA;
|
||||
|
||||
ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
|
||||
"port", port, NULL);
|
||||
|
||||
transport = THRIFT_SERVER_TRANSPORT (tsocket);
|
||||
thrift_server_transport_listen (transport, NULL);
|
||||
|
||||
/* wrap the client in a BufferedTransport */
|
||||
client = g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT, "transport",
|
||||
thrift_server_transport_accept (transport, NULL),
|
||||
"r_buf_size", 5, NULL);
|
||||
assert (client != NULL);
|
||||
|
||||
/* read 10 bytes */
|
||||
bytes = thrift_buffered_transport_read (client, buf, 10, NULL);
|
||||
assert (bytes == 10); /* make sure we've read 10 bytes */
|
||||
assert ( memcmp (buf, match, 10) == 0 ); /* make sure what we got matches */
|
||||
|
||||
/* read 1 byte */
|
||||
bytes = thrift_buffered_transport_read (client, buf, 1, NULL);
|
||||
|
||||
bytes = thrift_buffered_transport_read (client, buf, 6, NULL);
|
||||
bytes = thrift_buffered_transport_read (client, buf, 2, NULL);
|
||||
bytes = thrift_buffered_transport_read (client, buf, 1, NULL);
|
||||
|
||||
thrift_buffered_transport_read_end (client, NULL);
|
||||
thrift_buffered_transport_close (client, NULL);
|
||||
g_object_unref (client);
|
||||
g_object_unref (tsocket);
|
||||
}
|
||||
|
||||
static void
|
||||
test_write_fail(void)
|
||||
{
|
||||
int status;
|
||||
pid_t pid;
|
||||
ThriftSocket *tsocket = NULL;
|
||||
ThriftTransport *transport = NULL;
|
||||
int port = 51198;
|
||||
guchar buf[10] = TEST_DATA; /* a buffer */
|
||||
|
||||
/* SIGPIPE when send to disconnected socket */
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
pid = fork ();
|
||||
assert ( pid >= 0 );
|
||||
|
||||
if ( pid == 0 )
|
||||
{
|
||||
/* child listens */
|
||||
ThriftServerTransport *transport = NULL;
|
||||
ThriftTransport *client = NULL;
|
||||
|
||||
ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
|
||||
"port", port, NULL);
|
||||
|
||||
transport = THRIFT_SERVER_TRANSPORT (tsocket);
|
||||
thrift_server_transport_listen (transport, NULL);
|
||||
|
||||
/* wrap the client in a BufferedTransport */
|
||||
client = g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT, "transport",
|
||||
thrift_server_transport_accept (transport, NULL),
|
||||
"r_buf_size", 5, NULL);
|
||||
assert (client != NULL);
|
||||
|
||||
/* just close socket */
|
||||
thrift_buffered_transport_close (client, NULL);
|
||||
g_object_unref (client);
|
||||
g_object_unref (tsocket);
|
||||
exit (0);
|
||||
} else {
|
||||
/* parent connects, wait a bit for the socket to be created */
|
||||
sleep (1);
|
||||
|
||||
tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
|
||||
"port", port, NULL);
|
||||
transport = g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT,
|
||||
"transport", THRIFT_TRANSPORT (tsocket),
|
||||
"w_buf_size", 4, NULL);
|
||||
|
||||
|
||||
assert (thrift_buffered_transport_open (transport, NULL) == TRUE);
|
||||
assert (thrift_buffered_transport_is_open (transport));
|
||||
|
||||
/* recognize disconnection */
|
||||
sleep(1);
|
||||
assert (thrift_buffered_transport_write (transport, buf, 10, NULL) == TRUE);
|
||||
assert (thrift_buffered_transport_write (transport, buf, 10, NULL) == FALSE);
|
||||
|
||||
/* write and overflow buffer */
|
||||
assert (thrift_buffered_transport_write (transport, buf, 10, NULL) == FALSE);
|
||||
|
||||
/* write 1 and flush */
|
||||
assert (thrift_buffered_transport_write (transport, buf, 1, NULL) == TRUE);
|
||||
assert (thrift_buffered_transport_flush (transport, NULL) == FALSE);
|
||||
|
||||
thrift_buffered_transport_close (transport, NULL);
|
||||
|
||||
g_object_unref (transport);
|
||||
g_object_unref (tsocket);
|
||||
|
||||
assert ( wait (&status) == pid );
|
||||
assert ( status == 0 );
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
#if (!GLIB_CHECK_VERSION (2, 36, 0))
|
||||
g_type_init();
|
||||
#endif
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/testbufferedtransport/CreateAndDestroy", test_create_and_destroy);
|
||||
g_test_add_func ("/testbufferedtransport/OpenAndClose", test_open_and_close);
|
||||
g_test_add_func ("/testbufferedtransport/ReadAndWrite", test_read_and_write);
|
||||
g_test_add_func ("/testbufferedtransport/WriteFail", test_write_fail);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user