Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06fed7de52 | ||
|
|
da2428a9f9 | ||
|
|
83b6ae5229 | ||
|
|
4b7804cdfd | ||
|
|
d075b5212f | ||
|
|
636c8ce219 | ||
|
|
091d7fa3ec | ||
|
|
59356e5b52 | ||
|
|
882bf29e63 | ||
|
|
f3eef4dd6b | ||
|
|
898983c6e5 | ||
|
|
dae5d032fa | ||
|
|
ff76622796 | ||
|
|
a6fd11a243 | ||
|
|
cf983be44c | ||
|
|
1a72de0e85 | ||
|
|
bf70a1e80e | ||
|
|
512d797d4d | ||
|
|
4a46dd1dde | ||
|
|
7494cdc071 | ||
|
|
608184ef9e | ||
|
|
eb4d8a9b68 | ||
|
|
6b92ae383c | ||
|
|
5fee857c4a | ||
|
|
53b7139c30 | ||
|
|
83e864d667 | ||
|
|
b88297e6de | ||
|
|
4aa2f46011 | ||
|
|
1fb3c757e2 | ||
|
|
3f640b6c14 | ||
|
|
49eb57af00 | ||
|
|
6bd6a80e71 | ||
|
|
38b84f0fa5 | ||
|
|
1f46debd0c | ||
|
|
37998e76d1 | ||
|
|
80b5508533 | ||
|
|
a646cc8227 | ||
|
|
92692adf52 | ||
|
|
b2cfc2b99b | ||
|
|
86e08f6151 | ||
|
|
8d852eb2d1 | ||
|
|
8bef018911 | ||
|
|
5e13419c28 | ||
|
|
503a7ae18f | ||
|
|
dfb9638a38 | ||
|
|
8452b0675b | ||
|
|
930643706a | ||
|
|
a2eac1f721 | ||
|
|
6e994cd694 | ||
|
|
c82869c631 | ||
|
|
f5a94868c4 | ||
|
|
c5628d613b | ||
|
|
9509b1ffa8 | ||
|
|
c1dac8a21e | ||
|
|
950846df45 | ||
|
|
31d96e2dc6 | ||
|
|
031e96075e | ||
|
|
bf2caeac6c | ||
|
|
12e523b37e | ||
|
|
576c985d8f | ||
|
|
9365807f47 | ||
|
|
25ce10fa61 | ||
|
|
09c333501f | ||
|
|
c51b09ee3a | ||
|
|
4d82eace86 | ||
|
|
385b03a163 | ||
|
|
4b438afa69 | ||
|
|
66961b94da |
@@ -49,6 +49,8 @@ maven-metadata.xml
|
||||
/bin/
|
||||
broker/config/git.properties
|
||||
distribution/src/main/resources/git.properties
|
||||
license/target
|
||||
server/target
|
||||
broker/h2db
|
||||
broker/media
|
||||
common/target
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## 野火IM解决方案
|
||||
|
||||
野火IM是一套跨平台、全开源的即时通讯解决方案,主要包含以下内容。
|
||||
野火IM是一套跨平台、核心功能开源的即时通讯解决方案,主要包含以下内容。
|
||||
|
||||
| 仓库 | 说明 | 备注 |
|
||||
| ------------------------------------------------------------ | ------------------------------------------------------- | ---------------------------------------------- |
|
||||
@@ -20,11 +20,21 @@
|
||||
|
||||
开发一套IM系统真的很艰辛,请路过的朋友们给点个star,支持我们坚持下去🙏🙏🙏🙏🙏
|
||||
|
||||
|
||||
### 联系我们
|
||||
问题讨论请加群:822762829
|
||||
|
||||
微信公众号:
|
||||
> 商务合作请优先采用邮箱和我们联系。技术问题请到[野火IM论坛](http://bbs.wildfirechat.cn/)发帖交流
|
||||
|
||||
1. heavyrain.lee 邮箱: heavyrain.lee@wildfirechat.cn 微信:wildfirechat
|
||||
2. imndx 邮箱: imndx@wildfirechat.cn 微信:wfchat
|
||||
|
||||
### 问题交流
|
||||
1. 微信交流群(请先加我们好友,我们再邀请您进群)
|
||||
|
||||
 
|
||||
|
||||
2. 如果大家发现bug,请在GitHub提issue
|
||||
3. 其他问题,请到[野火IM论坛](http://bbs.wildfirechat.cn/)进行交流学习
|
||||
4. 微信公众号
|
||||
|
||||
<img src="http://static.wildfirechat.cn/wx_wfc_qrcode.jpg" width = 50% height = 50% />
|
||||
|
||||
@@ -65,7 +75,7 @@
|
||||
|
||||
| 捐赠者 | 商标 | 金额 | 简介 |
|
||||
| ----- | ---- | -------- | --- |
|
||||
| [SAMOS](http://samos.io) |  | 每月2000¥ | 一站式区块链解决方案服务商(http://samos.io) |
|
||||
| [SAMOS](http://samos.io) |  | 保密 | 一站式区块链解决方案服务商(http://samos.io) |
|
||||
|
||||
## 特别感谢
|
||||
1. [moquette](https://github.com/moquette-io/moquette) 本项目是基于此项目二次开发而来,处理MQTT相关业务。
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#*********************************************************************
|
||||
#服务器的接入IP。给客户端提供是${server.ip}和${http_port}。
|
||||
#客户端会从${http_port}端口获取到长链接端口。
|
||||
server.ip 192.168.1.100
|
||||
server.ip 0.0.0.0
|
||||
|
||||
##原生客户端长链接端口
|
||||
port 1883
|
||||
@@ -26,7 +26,7 @@ host 0.0.0.0
|
||||
##本地绑定端口
|
||||
local_port 80
|
||||
|
||||
##是否使用内置DB。0使用mysql;1使用h2db
|
||||
##是否使用内置DB。0使用mysql;1使用h2db;2使用mysql+mongodb。社区版只支持0和1,专业版支持2
|
||||
embed.db 0
|
||||
|
||||
##服务器管理接口密钥
|
||||
@@ -42,6 +42,12 @@ client.proto.secret_key 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x78,0x79,0x7A,0
|
||||
##用来生产im token的私钥,只在服务器使用,客户端不用。正式使用时为了安全一定要修改这个值,切记切记
|
||||
token.key testim
|
||||
|
||||
##首次登录,是否接收之前的历史消息。0 不接收;1接收。
|
||||
message.roaming 0
|
||||
|
||||
##是否开启拉取远程历史消息
|
||||
message.remote_history_message 0
|
||||
|
||||
#*********************************************************************
|
||||
# hazelcase configuration
|
||||
#*********************************************************************
|
||||
@@ -95,10 +101,20 @@ push.android.server.address http://localhost:8085/android/push
|
||||
push.ios.server.address http://localhost:8085/ios/push
|
||||
|
||||
|
||||
#*********************************************************************
|
||||
# MongoDB configuration
|
||||
#*********************************************************************
|
||||
#专业版支持,社区版请忽略
|
||||
#mongodb.client_uri mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
|
||||
#mongodb.client_uri mongodb://host1:27017,host2:27017,host3:27017/wfchat?replicaSet=myReplicaSet
|
||||
mongodb.client_uri mongodb://wfc:123456@localhost:27017/wfchat
|
||||
mongodb.database wfchat
|
||||
mongodb.data_expire_days 1096
|
||||
|
||||
#*********************************************************************
|
||||
# Sensitive configuration
|
||||
#*********************************************************************
|
||||
##文本敏感词过滤处理方法,0 发送失败;1 发送成功但消息被服务器直接丢弃;2 命中的敏感词被替换成***
|
||||
##文本敏感词过滤处理方法,0 发送失败;1 发送成功但消息被服务器直接丢弃;2 命中的敏感词被替换成***;3 记录并继续发送
|
||||
sensitive.filter.type 0
|
||||
|
||||
#*********************************************************************
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
|
||||
DROP TABLE IF EXISTS `t_settings`;
|
||||
CREATE TABLE `t_settings` (
|
||||
`id` int(11) NOT NULL PRIMARY KEY,
|
||||
`value` varchar(64) NOT NULL,
|
||||
`desc` varchar(128) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
insert into t_settings(`id`, `value`,`desc`) values (1, '3000', '最大群成员数量');
|
||||
@@ -0,0 +1 @@
|
||||
alter table `t_sensitiveword` add column `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
|
||||
DROP TABLE IF EXISTS `t_session`;
|
||||
CREATE TABLE `t_session` (
|
||||
`row_id` varchar(50) not null primary key,
|
||||
`del_flag` tinyint(1) default 0 null,
|
||||
`create_time` timestamp null,
|
||||
`update_time` timestamp null,
|
||||
`expire_time` timestamp null,
|
||||
`user_id` int null,
|
||||
constraint `t_session_pk_2` unique (`user_id`, `expire_time`)
|
||||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = utf8mb4
|
||||
COLLATE = utf8mb4_unicode_ci;
|
||||
@@ -0,0 +1,2 @@
|
||||
alter table t_user MODIFY column `_createTime` DATETIME NOT NULL DEFAULT NOW();
|
||||
alter table t_group MODIFY column `_createTime` DATETIME NOT NULL DEFAULT NOW();
|
||||
@@ -0,0 +1,4 @@
|
||||
alter table t_session MODIFY column `create_time` DATETIME NOT NULL DEFAULT NOW();
|
||||
alter table t_session MODIFY column `update_time` DATETIME NOT NULL DEFAULT NOW();
|
||||
alter table t_session MODIFY column `expire_time` DATETIME NOT NULL DEFAULT NOW();
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
update t_messages_0 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_1 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_2 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_3 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_4 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_5 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_6 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_7 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_8 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_9 set _dt = date_add(_dt, interval 8 hour);
|
||||
|
||||
update t_messages_10 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_11 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_12 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_13 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_14 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_15 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_16 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_17 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_18 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_19 set _dt = date_add(_dt, interval 8 hour);
|
||||
|
||||
update t_messages_20 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_21 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_22 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_23 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_24 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_25 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_26 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_27 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_28 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_29 set _dt = date_add(_dt, interval 8 hour);
|
||||
|
||||
|
||||
update t_messages_30 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_31 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_32 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_33 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_34 set _dt = date_add(_dt, interval 8 hour);
|
||||
update t_messages_35 set _dt = date_add(_dt, interval 8 hour);
|
||||
+4038
File diff suppressed because it is too large
Load Diff
+13
@@ -0,0 +1,13 @@
|
||||
|
||||
DROP TABLE IF EXISTS `t_settings`;
|
||||
CREATE TABLE `t_settings` (
|
||||
`id` int(11) NOT NULL PRIMARY KEY,
|
||||
`value` varchar(64) NOT NULL,
|
||||
`desc` varchar(128) NOT NULL default ""
|
||||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = utf8mb4
|
||||
COLLATE = utf8mb4_unicode_ci;
|
||||
|
||||
|
||||
insert into t_settings(`id`, `value`,`desc`) values (1, "3000", "最大群成员数量");
|
||||
@@ -0,0 +1 @@
|
||||
alter table `t_sensitiveword` add column `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT;
|
||||
+8
-26
@@ -5,7 +5,7 @@
|
||||
<relativePath>../</relativePath>
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>0.23</version>
|
||||
<version>0.26</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>moquette-broker</artifactId>
|
||||
@@ -110,34 +110,11 @@
|
||||
<artifactId>netty-transport-native-epoll</artifactId>
|
||||
<version>${netty.version}</version>
|
||||
<classifier>linux-x86_64</classifier>
|
||||
<!--
|
||||
<!--
|
||||
<classifier>${os.detected.name}-${os.detected.arch}</classifier>
|
||||
-->
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.dropwizard.metrics</groupId>
|
||||
<artifactId>metrics-core</artifactId>
|
||||
<version>3.2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dropwizard.metrics</groupId>
|
||||
<artifactId>metrics-jvm</artifactId>
|
||||
<version>3.2.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.librato.metrics</groupId>
|
||||
<artifactId>metrics-librato</artifactId>
|
||||
<version>5.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.bugsnag</groupId>
|
||||
<artifactId>bugsnag</artifactId>
|
||||
<version>[3.0,4.0)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
@@ -170,7 +147,7 @@
|
||||
<dependency>
|
||||
<groupId>com.mchange</groupId>
|
||||
<artifactId>c3p0</artifactId>
|
||||
<version>[0.9.5.3,)</version>
|
||||
<version>0.9.5.4</version>
|
||||
</dependency>
|
||||
|
||||
<!-- needs extra dependencies: objenesis & hamcrest -->
|
||||
@@ -256,6 +233,11 @@
|
||||
<version>5.2.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>mongo-java-driver</artifactId>
|
||||
<version>3.4.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ import io.netty.handler.codec.http.HttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
/**
|
||||
@@ -84,7 +86,7 @@ abstract public class Action {
|
||||
if (request instanceof FullHttpRequest) {
|
||||
FullHttpRequest fullHttpRequest = (FullHttpRequest) request;
|
||||
byte[] bytes = Utils.readBytesAndRewind(fullHttpRequest.content());
|
||||
String content = new String(bytes);
|
||||
String content = new String(bytes, StandardCharsets.UTF_8);//contribute by JiaRG from github
|
||||
Gson gson = new Gson();
|
||||
T t = gson.fromJson(content, cls);
|
||||
return t;
|
||||
|
||||
@@ -35,11 +35,14 @@ import java.util.concurrent.Executor;
|
||||
@HttpMethod("POST")
|
||||
public class RouteAction extends Action {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RouteAction.class);
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
|
||||
FullHttpRequest fullHttpRequest = (FullHttpRequest) request.getNettyRequest();
|
||||
boolean b = false;
|
||||
if ("web".equalsIgnoreCase(fullHttpRequest.headers().get("p"))) {
|
||||
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package com.xiaoleilu.loServer.action.admin;
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.*;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.google.gson.Gson;
|
||||
import com.xiaoleilu.loServer.RestResult;
|
||||
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||
import com.xiaoleilu.loServer.annotation.Route;
|
||||
import com.xiaoleilu.loServer.handler.Request;
|
||||
import com.xiaoleilu.loServer.handler.Response;
|
||||
import io.moquette.persistence.RPCCenter;
|
||||
import io.moquette.persistence.TargetEntry;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import win.liyufan.im.IMTopic;
|
||||
import win.liyufan.im.UUIDGenerator;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Route(APIPath.Create_Channel)
|
||||
@HttpMethod("POST")
|
||||
public class CreateChannelAction extends AdminAction {
|
||||
|
||||
@Override
|
||||
public boolean isTransactionAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputCreateChannel inputCreateChannel = getRequestBody(request.getNettyRequest(), InputCreateChannel.class);
|
||||
if (inputCreateChannel != null
|
||||
&& !StringUtil.isNullOrEmpty(inputCreateChannel.getName())) {
|
||||
|
||||
|
||||
if(StringUtil.isNullOrEmpty(inputCreateChannel.getTargetId())) {
|
||||
inputCreateChannel.setTargetId(messagesStore.getShortUUID());
|
||||
}
|
||||
|
||||
RPCCenter.getInstance().sendRequest(inputCreateChannel.getOwner(), null, IMTopic.CreateChannelTopic, inputCreateChannel.toProtoChannelInfo().toByteArray(), inputCreateChannel.getOwner(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
|
||||
@Override
|
||||
public void onSuccess(byte[] result) {
|
||||
ByteBuf byteBuf = Unpooled.buffer();
|
||||
byteBuf.writeBytes(result);
|
||||
ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte());
|
||||
if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
sendResponse(response, null, new OutputCreateChannel(inputCreateChannel.getTargetId()));
|
||||
} else {
|
||||
sendResponse(response, errorCode, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ErrorCode errorCode) {
|
||||
sendResponse(response, errorCode, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeout() {
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_TIMEOUT, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Executor getResponseExecutor() {
|
||||
return command -> {
|
||||
ctx.executor().execute(command);
|
||||
};
|
||||
}
|
||||
}, true);
|
||||
return false;
|
||||
} else {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package com.xiaoleilu.loServer.action.admin;
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.InputGetUserInfo;
|
||||
import cn.wildfirechat.pojos.InputOutputUserInfo;
|
||||
import cn.wildfirechat.pojos.SystemSettingPojo;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.google.gson.Gson;
|
||||
import com.xiaoleilu.loServer.RestResult;
|
||||
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||
import com.xiaoleilu.loServer.annotation.Route;
|
||||
import com.xiaoleilu.loServer.handler.Request;
|
||||
import com.xiaoleilu.loServer.handler.Response;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
@Route(APIPath.Get_System_Setting)
|
||||
@HttpMethod("POST")
|
||||
public class GetSystemSettingAction extends AdminAction {
|
||||
|
||||
@Override
|
||||
public boolean isTransactionAction() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
SystemSettingPojo inputUserId = getRequestBody(request.getNettyRequest(), SystemSettingPojo.class);
|
||||
if (inputUserId != null) {
|
||||
SystemSettingPojo output = messagesStore.getSystemSetting(inputUserId.id);
|
||||
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result;
|
||||
if (output == null) {
|
||||
result = RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_EXIST);
|
||||
} else {
|
||||
result = RestResult.ok(output);
|
||||
}
|
||||
|
||||
response.setContent(new Gson().toJson(result));
|
||||
} else {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class KickoffGroupMemberAction extends AdminAction {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputKickoffGroupMember inputKickoffGroupMember = getRequestBody(request.getNettyRequest(), InputKickoffGroupMember.class);
|
||||
if (inputKickoffGroupMember.isValide()) {
|
||||
RPCCenter.getInstance().sendRequest(inputKickoffGroupMember.getOperator(), null, IMTopic.AddGroupMemberTopic, inputKickoffGroupMember.toProtoGroupRequest().toByteArray(), inputKickoffGroupMember.getOperator(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
|
||||
RPCCenter.getInstance().sendRequest(inputKickoffGroupMember.getOperator(), null, IMTopic.KickoffGroupMemberTopic, inputKickoffGroupMember.toProtoGroupRequest().toByteArray(), inputKickoffGroupMember.getOperator(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
|
||||
@Override
|
||||
public void onSuccess(byte[] result) {
|
||||
ByteBuf byteBuf = Unpooled.buffer();
|
||||
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package com.xiaoleilu.loServer.action.admin;
|
||||
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.InputAddGroupMember;
|
||||
import cn.wildfirechat.pojos.InputModifyGroupInfo;
|
||||
import com.google.gson.Gson;
|
||||
import com.xiaoleilu.loServer.RestResult;
|
||||
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||
import com.xiaoleilu.loServer.annotation.Route;
|
||||
import com.xiaoleilu.loServer.handler.Request;
|
||||
import com.xiaoleilu.loServer.handler.Response;
|
||||
import io.moquette.persistence.RPCCenter;
|
||||
import io.moquette.persistence.TargetEntry;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import win.liyufan.im.IMTopic;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Route(APIPath.Group_Modify_Info)
|
||||
@HttpMethod("POST")
|
||||
public class ModifyGroupInfoAction extends AdminAction {
|
||||
|
||||
@Override
|
||||
public boolean isTransactionAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputModifyGroupInfo inputAddGroupMember = getRequestBody(request.getNettyRequest(), InputModifyGroupInfo.class);
|
||||
if (inputAddGroupMember.isValide()) {
|
||||
RPCCenter.getInstance().sendRequest(inputAddGroupMember.getOperator(), null, IMTopic.ModifyGroupInfoTopic, inputAddGroupMember.toProtoGroupRequest().toByteArray(), inputAddGroupMember.getOperator(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
|
||||
@Override
|
||||
public void onSuccess(byte[] result) {
|
||||
ByteBuf byteBuf = Unpooled.buffer();
|
||||
byteBuf.writeBytes(result);
|
||||
ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte());
|
||||
if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
sendResponse(response, null, null);
|
||||
} else {
|
||||
sendResponse(response, errorCode, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ErrorCode errorCode) {
|
||||
sendResponse(response, errorCode, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeout() {
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_TIMEOUT, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Executor getResponseExecutor() {
|
||||
return command -> {
|
||||
ctx.executor().execute(command);
|
||||
};
|
||||
}
|
||||
}, true);
|
||||
return false;
|
||||
} else {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package com.xiaoleilu.loServer.action.admin;
|
||||
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.BroadMessageData;
|
||||
import cn.wildfirechat.pojos.BroadMessageResult;
|
||||
import cn.wildfirechat.pojos.MultiMessageResult;
|
||||
import cn.wildfirechat.pojos.MulticastMessageData;
|
||||
import com.google.gson.Gson;
|
||||
import com.hazelcast.util.StringUtil;
|
||||
import com.xiaoleilu.loServer.RestResult;
|
||||
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||
import com.xiaoleilu.loServer.annotation.Route;
|
||||
import com.xiaoleilu.loServer.handler.Request;
|
||||
import com.xiaoleilu.loServer.handler.Response;
|
||||
import io.moquette.persistence.RPCCenter;
|
||||
import io.moquette.persistence.TargetEntry;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import win.liyufan.im.IMTopic;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Route(APIPath.Msg_Multicast)
|
||||
@HttpMethod("POST")
|
||||
public class MulticastMessageAction extends AdminAction {
|
||||
|
||||
@Override
|
||||
public boolean isTransactionAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
MulticastMessageData sendMessageData = getRequestBody(request.getNettyRequest(), MulticastMessageData.class);
|
||||
if (MulticastMessageData.isValide(sendMessageData)) {
|
||||
RPCCenter.getInstance().sendRequest(sendMessageData.getSender(), null, IMTopic.MultiCastMessageTopic, sendMessageData.toProtoMessage().toByteArray(), sendMessageData.getSender(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
|
||||
@Override
|
||||
public void onSuccess(byte[] result) {
|
||||
ByteBuf byteBuf = Unpooled.buffer();
|
||||
byteBuf.writeBytes(result);
|
||||
ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte());
|
||||
if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
long messageId = byteBuf.readLong();
|
||||
long timestamp = byteBuf.readLong();
|
||||
sendResponse(response, null, new MultiMessageResult(messageId, timestamp));
|
||||
} else {
|
||||
sendResponse(response, errorCode, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ErrorCode errorCode) {
|
||||
sendResponse(response, errorCode, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeout() {
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_TIMEOUT, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Executor getResponseExecutor() {
|
||||
return command -> {
|
||||
ctx.executor().execute(command);
|
||||
};
|
||||
}
|
||||
}, true);
|
||||
return false;
|
||||
} else {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package com.xiaoleilu.loServer.action.admin;
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.InputGetUserInfo;
|
||||
import cn.wildfirechat.pojos.InputOutputUserInfo;
|
||||
import cn.wildfirechat.pojos.SystemSettingPojo;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.google.gson.Gson;
|
||||
import com.xiaoleilu.loServer.RestResult;
|
||||
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||
import com.xiaoleilu.loServer.annotation.Route;
|
||||
import com.xiaoleilu.loServer.handler.Request;
|
||||
import com.xiaoleilu.loServer.handler.Response;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
@Route(APIPath.Put_System_Setting)
|
||||
@HttpMethod("POST")
|
||||
public class PutSystemSettingAction extends AdminAction {
|
||||
|
||||
@Override
|
||||
public boolean isTransactionAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
SystemSettingPojo inputUserId = getRequestBody(request.getNettyRequest(), SystemSettingPojo.class);
|
||||
if (inputUserId != null
|
||||
&& (!StringUtil.isNullOrEmpty(inputUserId.value) || !StringUtil.isNullOrEmpty(inputUserId.desc))) {
|
||||
|
||||
|
||||
boolean success = messagesStore.updateSystemSetting(inputUserId.id, inputUserId.value, inputUserId.desc);
|
||||
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result;
|
||||
if (!success) {
|
||||
result = RestResult.resultOf(ErrorCode.ERROR_CODE_SERVER_ERROR);
|
||||
} else {
|
||||
result = RestResult.ok();
|
||||
}
|
||||
|
||||
response.setContent(new Gson().toJson(result));
|
||||
} else {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Action处理单元
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
|
||||
@@ -45,7 +45,7 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
||||
try {
|
||||
//do filter
|
||||
boolean isPass = this.doFilter(request, response);
|
||||
|
||||
|
||||
if(isPass){
|
||||
//do action
|
||||
this.doAction(ctx, request, response);
|
||||
@@ -64,10 +64,10 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
||||
ctx.fireExceptionCaught(e);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
super.exceptionCaught(ctx, cause);
|
||||
@@ -75,7 +75,7 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
||||
Channel channel = ctx.channel();
|
||||
if(channel.isActive())ctx.close();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------- Private method start
|
||||
/**
|
||||
* 执行过滤
|
||||
@@ -91,7 +91,7 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//自定义Path过滤器
|
||||
filter = ServerSetting.getFilter(request.getPath());
|
||||
if(null != filter){
|
||||
@@ -99,7 +99,7 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -110,6 +110,10 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
||||
* @param response 响应对象
|
||||
*/
|
||||
private void doAction(ChannelHandlerContext ctx, Request request, Response response){
|
||||
if( "/route".equalsIgnoreCase(request.getPath()) && "OPTIONS".equalsIgnoreCase(request.getMethod())){
|
||||
handleOptions(ctx, request, response);
|
||||
return;
|
||||
}
|
||||
Action action;
|
||||
if (isValidePath(request.getPath())) {
|
||||
action = ServerSetting.getAction(request.getPath(), request.getMethod().toUpperCase());
|
||||
@@ -141,4 +145,11 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------------------- Private method start
|
||||
|
||||
|
||||
private void handleOptions(ChannelHandlerContext ctx, Request request, Response response){
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
response.setHeader("Access-Control-Allow-Headers", "*");
|
||||
response.send();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,13 +60,6 @@ public final class BrokerConstants {
|
||||
public static final String NETTY_SO_KEEPALIVE_PROPERTY_NAME = "netty.so_keepalive";
|
||||
public static final String NETTY_CHANNEL_TIMEOUT_SECONDS_PROPERTY_NAME = "netty.channel_timeout.seconds";
|
||||
public static final String NETTY_EPOLL_PROPERTY_NAME = "netty.epoll";
|
||||
public static final String METRICS_ENABLE_PROPERTY_NAME = "use_metrics";
|
||||
public static final String METRICS_LIBRATO_EMAIL_PROPERTY_NAME = "metrics.librato.email";
|
||||
public static final String METRICS_LIBRATO_TOKEN_PROPERTY_NAME = "metrics.librato.token";
|
||||
public static final String METRICS_LIBRATO_SOURCE_PROPERTY_NAME = "metrics.librato.source";
|
||||
|
||||
public static final String BUGSNAG_ENABLE_PROPERTY_NAME = "use_bugsnag";
|
||||
public static final String BUGSNAG_TOKEN_PROPERTY_NAME = "bugsnag.token";
|
||||
|
||||
public static final String STORAGE_CLASS_NAME = "storage_class";
|
||||
|
||||
@@ -103,7 +96,7 @@ public final class BrokerConstants {
|
||||
public static final String HTTP_SERVER_API_NO_CHECK_TIME = "http.admin.no_check_time";
|
||||
|
||||
public static final String CLIENT_PROTO_SECRET_KEY = "client.proto.secret_key";
|
||||
public static final String TOKEN_SECRET_KEY = "token.key ";
|
||||
public static final String TOKEN_SECRET_KEY = "token.key";
|
||||
|
||||
public static final String EMBED_DB_PROPERTY_NAME = "embed.db";
|
||||
|
||||
@@ -113,6 +106,12 @@ public final class BrokerConstants {
|
||||
|
||||
public static final String MESSAGE_Forward_Url = "message.forward.url";
|
||||
|
||||
public static final String MONGODB_Client_URI = "mongodb.client_uri";
|
||||
public static final String MONGODB_Database = "mongodb.database";
|
||||
public static final String MONGODB_Data_Expire_Days = "mongodb.data_expire_days";
|
||||
|
||||
public static final String MESSAGE_ROAMING = "message.roaming";
|
||||
public static final String MESSAGE_Remote_History_Message = "message.reomte_history_message";
|
||||
|
||||
|
||||
private BrokerConstants() {
|
||||
|
||||
@@ -14,10 +14,18 @@ import io.netty.buffer.ByteBuf;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import win.liyufan.im.IMTopic;
|
||||
|
||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
@Handler(IMTopic.DeleteFriendTopic)
|
||||
public class DeleteFriendHandler extends IMHandler<WFCMessage.IDBuf> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.IDBuf request, Qos1PublishHandler.IMCallback callback) {
|
||||
return m_messagesStore.deleteFriend(fromUser, request.getId());
|
||||
long[] head = new long[2];
|
||||
ErrorCode errorCode = m_messagesStore.deleteFriend(fromUser, request.getId(), head);
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
publisher.publishNotification(IMTopic.NotifyFriendTopic, fromUser, head[0]);
|
||||
publisher.publishNotification(IMTopic.NotifyFriendTopic, request.getId(), head[1]);
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package io.moquette.imhandler;
|
||||
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.hazelcast.util.StringUtil;
|
||||
import com.xiaoleilu.loServer.model.FriendData;
|
||||
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -25,7 +26,11 @@ public class FriendPullHandler extends IMHandler<WFCMessage.Version> {
|
||||
WFCMessage.GetFriendsResult.Builder builder = WFCMessage.GetFriendsResult.newBuilder();
|
||||
for (FriendData data : friendDatas
|
||||
) {
|
||||
builder.addEntry(WFCMessage.Friend.newBuilder().setState(data.getState()).setUid(data.getFriendUid()).setUpdateDt(data.getTimestamp()).setAlias(data.getAlias()).build());
|
||||
WFCMessage.Friend.Builder builder1 = WFCMessage.Friend.newBuilder().setState(data.getState()).setUid(data.getFriendUid()).setUpdateDt(data.getTimestamp());
|
||||
if (!StringUtil.isNullOrEmpty(data.getAlias())) {
|
||||
builder1.setAlias(data.getAlias());
|
||||
}
|
||||
builder.addEntry(builder1.build());
|
||||
}
|
||||
byte[] data = builder.build().toByteArray();
|
||||
ackPayload.ensureWritable(data.length).writeBytes(data);
|
||||
|
||||
@@ -32,6 +32,8 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -233,6 +235,14 @@ abstract public class IMHandler<T> {
|
||||
public void afterAction(String clientID, String fromUser, String topic, Qos1PublishHandler.IMCallback callback) {
|
||||
|
||||
}
|
||||
protected long publish(String username, String clientID, WFCMessage.Message message) {
|
||||
Set<String> notifyReceivers = new LinkedHashSet<>();
|
||||
|
||||
WFCMessage.Message.Builder messageBuilder = message.toBuilder();
|
||||
int pullType = m_messagesStore.getNotifyReceivers(username, messageBuilder, notifyReceivers);
|
||||
this.publisher.publish2Receivers(messageBuilder.build(), notifyReceivers, clientID, pullType);
|
||||
return notifyReceivers.size();
|
||||
}
|
||||
|
||||
protected long saveAndPublish(String username, String clientID, WFCMessage.Message message) {
|
||||
Set<String> notifyReceivers = new LinkedHashSet<>();
|
||||
@@ -250,4 +260,12 @@ abstract public class IMHandler<T> {
|
||||
mServer.getImBusinessScheduler().execute(() -> publisher.publish2Receivers(updatedMessage, notifyReceivers, clientID, ProtoConstants.PullType.Pull_Normal));
|
||||
return notifyReceivers.size();
|
||||
}
|
||||
|
||||
protected long saveAndMulticast(String username, String clientID, WFCMessage.Message message, Collection<String> targets) {
|
||||
Set<String> notifyReceivers = new HashSet<>();
|
||||
notifyReceivers.addAll(targets);
|
||||
WFCMessage.Message updatedMessage = m_messagesStore.storeMessage(username, clientID, message);
|
||||
mServer.getImBusinessScheduler().execute(() -> publisher.publish2Receivers(updatedMessage, notifyReceivers, clientID, ProtoConstants.PullType.Pull_Normal));
|
||||
return notifyReceivers.size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,20 +24,38 @@ public class KickoffGroupMember extends GroupHandler<WFCMessage.RemoveGroupMembe
|
||||
WFCMessage.GroupInfo groupInfo = m_messagesStore.getGroupInfo(request.getGroupId());
|
||||
if (groupInfo == null) {
|
||||
errorCode = ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
|
||||
} else if ((groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted)
|
||||
&& groupInfo.getOwner() != null && groupInfo.getOwner().equals(fromUser)) {
|
||||
|
||||
//send notify message first, then kickoff the member
|
||||
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
sendGroupNotification(fromUser, groupInfo.getTargetId(), request.getToLineList(), request.getNotifyContent());
|
||||
} else {
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, null, request.getRemovedMemberList()).getKickokfMemberGroupNotifyContent();
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), content);
|
||||
}
|
||||
errorCode = m_messagesStore.kickoffGroupMembers(fromUser, request.getGroupId(), request.getRemovedMemberList());
|
||||
} else {
|
||||
errorCode = ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
boolean isAllow = isAdmin;
|
||||
if (!isAllow) {
|
||||
if (groupInfo.getOwner() != null) {
|
||||
if (request.getRemovedMemberList().contains(groupInfo.getOwner())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
if (groupInfo.getOwner() != null && groupInfo.getOwner().equals(fromUser)) {
|
||||
isAllow = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isAllow) {
|
||||
WFCMessage.GroupMember gm = m_messagesStore.getGroupMember(request.getGroupId(), fromUser);
|
||||
if (gm != null && gm.getType() == ProtoConstants.GroupMemberType.GroupMemberType_Manager) {
|
||||
isAllow = true;
|
||||
}
|
||||
}
|
||||
if (!isAllow && (groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted)) {
|
||||
errorCode = ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
} else {
|
||||
//send notify message first, then kickoff the member
|
||||
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
sendGroupNotification(fromUser, groupInfo.getTargetId(), request.getToLineList(), request.getNotifyContent());
|
||||
} else {
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, null, request.getRemovedMemberList()).getKickokfMemberGroupNotifyContent();
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), content);
|
||||
}
|
||||
errorCode = m_messagesStore.kickoffGroupMembers(fromUser, isAdmin, request.getGroupId(), request.getRemovedMemberList());
|
||||
}
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import static win.liyufan.im.IMTopic.ModifyGroupInfoTopic;
|
||||
public class ModifyGroupInfoHandler extends GroupHandler<WFCMessage.ModifyGroupInfoRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.ModifyGroupInfoRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode= m_messagesStore.modifyGroupInfo(fromUser, request.getGroupId(), request.getType(), request.getValue());
|
||||
ErrorCode errorCode= m_messagesStore.modifyGroupInfo(fromUser, request.getGroupId(), request.getType(), request.getValue(), isAdmin);
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), request.getNotifyContent());
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package io.moquette.imhandler;
|
||||
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.hazelcast.util.StringUtil;
|
||||
import io.moquette.BrokerConstants;
|
||||
import io.moquette.server.Server;
|
||||
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import win.liyufan.im.IMTopic;
|
||||
import win.liyufan.im.MessageShardingUtil;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.wildfirechat.proto.ProtoConstants.ContentType.Text;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.ConversationType.ConversationType_Private;
|
||||
|
||||
@Handler(value = IMTopic.MultiCastMessageTopic)
|
||||
public class MultiCastMessageHandler extends IMHandler<WFCMessage.MultiCastMessage> {
|
||||
|
||||
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.MultiCastMessage multiCastMessage, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
|
||||
if (!isAdmin) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
|
||||
long timestamp = System.currentTimeMillis();
|
||||
long messageId = MessageShardingUtil.generateId();
|
||||
WFCMessage.Message message = WFCMessage.Message.newBuilder()
|
||||
.setContent(multiCastMessage.getContent())
|
||||
.setConversation(WFCMessage.Conversation.newBuilder().setTarget(fromUser).setType(ConversationType_Private).setLine(multiCastMessage.getLine()).build())
|
||||
.setFromUser(fromUser)
|
||||
.setMessageId(messageId)
|
||||
.setServerTimestamp(timestamp)
|
||||
.build();
|
||||
|
||||
saveAndMulticast(fromUser, clientID, message, multiCastMessage.getToList());
|
||||
|
||||
ackPayload = ackPayload.capacity(20);
|
||||
ackPayload.writeLong(messageId);
|
||||
ackPayload.writeLong(timestamp);
|
||||
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,19 +20,14 @@ import static win.liyufan.im.IMTopic.QuitGroupTopic;
|
||||
public class QuitGroupHandler extends GroupHandler<WFCMessage.QuitGroupRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.QuitGroupRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
|
||||
WFCMessage.GroupInfo groupInfo = m_messagesStore.getGroupInfo(request.getGroupId());
|
||||
if (groupInfo == null) {
|
||||
errorCode = m_messagesStore.quitGroup(fromUser, request.getGroupId());
|
||||
} else {
|
||||
//send notify message first, then quit group
|
||||
ErrorCode errorCode = m_messagesStore.quitGroup(fromUser, request.getGroupId());
|
||||
if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
sendGroupNotification(fromUser, groupInfo.getTargetId(), request.getToLineList(), request.getNotifyContent());
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), request.getNotifyContent());
|
||||
} else {
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, null, "").getQuitGroupNotifyContent();
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), content);
|
||||
}
|
||||
errorCode = m_messagesStore.quitGroup(fromUser, request.getGroupId());
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Set;
|
||||
public class RecallMessageHandler extends IMHandler<WFCMessage.INT64Buf> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.INT64Buf int64Buf, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = m_messagesStore.recallMessage(int64Buf.getId(), fromUser);
|
||||
ErrorCode errorCode = m_messagesStore.recallMessage(int64Buf.getId(), fromUser, isAdmin);
|
||||
|
||||
if(errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
return errorCode;
|
||||
@@ -33,6 +33,10 @@ public class RecallMessageHandler extends IMHandler<WFCMessage.INT64Buf> {
|
||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
}
|
||||
|
||||
publish(fromUser, clientID, message);
|
||||
|
||||
|
||||
//等待客户端实现根据撤回消息更新内容,之后可以删掉这段代码
|
||||
m_messagesStore.getNotifyReceivers(fromUser, message.toBuilder(), notifyReceivers);
|
||||
this.publisher.publishRecall2Receivers(int64Buf.getId(), fromUser, notifyReceivers, clientID);
|
||||
|
||||
|
||||
@@ -46,6 +46,10 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
|
||||
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
|
||||
if (message != null) {
|
||||
if (!isAdmin) { //admin do not check the right
|
||||
// 不能在端上直接发送撤回和群通知
|
||||
if (message.getContent().getType() == 80 || (message.getContent().getType() >= 100 && message.getContent().getType() < 200)) {
|
||||
return ErrorCode.INVALID_PARAMETER;
|
||||
}
|
||||
int userStatus = m_messagesStore.getUserStatus(fromUser);
|
||||
if (userStatus == 1 || userStatus == 2) {
|
||||
return ErrorCode.ERROR_CODE_FORBIDDEN_SEND_MSG;
|
||||
@@ -91,13 +95,15 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
|
||||
errorCode = ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
|
||||
} else if(mSensitiveType == 1) {
|
||||
ignoreMsg = true;
|
||||
} else {
|
||||
} else if(mSensitiveType == 2) {
|
||||
String text = message.getContent().getSearchableContent();
|
||||
for (String word : matched) {
|
||||
text = text.replace(word, "***");
|
||||
}
|
||||
|
||||
message = message.toBuilder().setContent(message.getContent().toBuilder().setSearchableContent(text).build()).build();
|
||||
} else if(mSensitiveType == 3) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
package io.moquette.persistence;
|
||||
|
||||
import cn.wildfirechat.pojos.SystemSettingPojo;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import cn.wildfirechat.server.ThreadPoolExecutorWrapper;
|
||||
@@ -76,6 +77,79 @@ public class DatabaseStore {
|
||||
return out;
|
||||
}
|
||||
|
||||
boolean updateSystemSetting(int id, String value, String desc) {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "insert into t_settings " +
|
||||
" (`id`, `value`, `desc`) values(?, ?, ?)" +
|
||||
" ON DUPLICATE KEY UPDATE " +
|
||||
"`value` = ?," +
|
||||
"`desc` = ?";
|
||||
|
||||
|
||||
statement = connection.prepareStatement(sql);
|
||||
int index = 1;
|
||||
statement.setLong(index++, id);
|
||||
statement.setString(index++, value);
|
||||
statement.setString(index++, desc);
|
||||
statement.setString(index++, value);
|
||||
statement.setString(index++, desc);
|
||||
|
||||
int count = statement.executeUpdate();
|
||||
LOG.info("Update rows {}", count);
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SystemSettingPojo getSystemSetting(int id) {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "select `value`, `desc` from t_settings where `id` = ?";
|
||||
|
||||
statement = connection.prepareStatement(sql);
|
||||
int index = 1;
|
||||
statement.setLong(index++, id);
|
||||
|
||||
rs = statement.executeQuery();
|
||||
while (rs.next()) {
|
||||
SystemSettingPojo out = new SystemSettingPojo();
|
||||
index = 1;
|
||||
|
||||
out.id = id;
|
||||
|
||||
String value = rs.getString(index++);
|
||||
value = (value == null ? "" : value);
|
||||
out.value = value;
|
||||
|
||||
value = rs.getString(index++);
|
||||
value = (value == null ? "" : value);
|
||||
out.desc = value;
|
||||
|
||||
return out;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement, rs);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
List<WFCMessage.User> searchUserFromDB(String keyword, boolean buzzy, int page) {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
@@ -210,23 +284,27 @@ public class DatabaseStore {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void reloadGroupMemberFromDB(HazelcastInstance hzInstance) {
|
||||
synchronized Collection<WFCMessage.GroupMember> reloadGroupMemberFromDB(HazelcastInstance hzInstance, String groupId) {
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(MemoryMessagesStore.GROUP_MEMBERS);
|
||||
if (groupMembers.get(groupId).size() > 0) {
|
||||
return groupMembers.get(groupId);
|
||||
}
|
||||
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "select `_gid`" +
|
||||
", `_mid`" +
|
||||
String sql = "select `_mid`" +
|
||||
", `_alias`" +
|
||||
", `_type`" +
|
||||
", `_dt` from t_group_member";
|
||||
", `_dt` from t_group_member where _gid = ?";
|
||||
statement = connection.prepareStatement(sql);
|
||||
|
||||
statement.setString(1, groupId);
|
||||
int index;
|
||||
|
||||
|
||||
rs = statement.executeQuery();
|
||||
while (rs.next()) {
|
||||
WFCMessage.GroupMember.Builder builder = WFCMessage.GroupMember.newBuilder();
|
||||
@@ -234,10 +312,6 @@ public class DatabaseStore {
|
||||
|
||||
String value = rs.getString(index++);
|
||||
value = (value == null ? "" : value);
|
||||
String groupId = value;
|
||||
|
||||
value = rs.getString(index++);
|
||||
value = (value == null ? "" : value);
|
||||
builder.setMemberId(value);
|
||||
|
||||
value = rs.getString(index++);
|
||||
@@ -254,6 +328,7 @@ public class DatabaseStore {
|
||||
WFCMessage.GroupMember member = builder.build();
|
||||
groupMembers.put(groupId, member);
|
||||
}
|
||||
return groupMembers.get(groupId);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
@@ -261,6 +336,7 @@ public class DatabaseStore {
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement, rs);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
void reloadFriendsFromDB(HazelcastInstance hzInstance) {
|
||||
@@ -592,6 +668,25 @@ public class DatabaseStore {
|
||||
return null;
|
||||
}
|
||||
|
||||
void deleteMessage(long messageId) {
|
||||
String sql = "delete from " + MessageShardingUtil.getMessageTable(messageId) + " where _mid = ?";
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
statement = connection.prepareStatement(sql);
|
||||
statement.setLong(1, messageId);
|
||||
|
||||
int count = statement.executeUpdate();
|
||||
LOG.info("Update rows {}", count);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
}
|
||||
|
||||
List<WFCMessage.Message> loadRemoteMessages(String user, WFCMessage.Conversation conversation, long beforeUid, int count) {
|
||||
List<WFCMessage.Message> messages = loadRemoteMessagesFromTable(user, conversation, beforeUid, count, MessageShardingUtil.getMessageTable(beforeUid));
|
||||
if (messages != null && messages.size() < count) {
|
||||
@@ -688,6 +783,43 @@ public class DatabaseStore {
|
||||
});
|
||||
}
|
||||
|
||||
void removeFavGroup(final String groupId, final List<String> memberIds) {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
|
||||
StringBuilder sb = new StringBuilder("update t_user_setting set _value = ?, _dt = ? where _uid in (");
|
||||
for (int i = 0; i < memberIds.size(); i++) {
|
||||
sb.append("?");
|
||||
if (i != memberIds.size() - 1) {
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
|
||||
sb.append(" and _scope = 6 and _key = ?");
|
||||
|
||||
statement = connection.prepareStatement(sb.toString());
|
||||
int index = 1;
|
||||
statement.setString(index++, "0");
|
||||
statement.setLong(index++, System.currentTimeMillis());
|
||||
for (int i = 0; i < memberIds.size(); i++) {
|
||||
statement.setString(index++, memberIds.get(i));
|
||||
}
|
||||
statement.setString(index++, groupId);
|
||||
|
||||
int count = statement.executeUpdate();
|
||||
LOG.info("Update rows {}", count);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
}
|
||||
|
||||
void persistUserSetting(final String userId, WFCMessage.UserSettingEntry entry) {
|
||||
mScheduler.execute(()->{
|
||||
Connection connection = null;
|
||||
@@ -779,6 +911,41 @@ public class DatabaseStore {
|
||||
}
|
||||
|
||||
|
||||
void removeGroupUserSettings(String groupId, List<String> users) {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
|
||||
StringBuilder sb = new StringBuilder("delete from t_user_setting where _scope in (1,3,5,7) and _uid in (");
|
||||
for (int i = 0; i < users.size(); i++) {
|
||||
sb.append("?");
|
||||
if (i != users.size() - 1) {
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
sb.append(") and _key like '1-_-");
|
||||
sb.append(groupId);
|
||||
sb.append("'");
|
||||
|
||||
|
||||
statement = connection.prepareStatement(sb.toString());
|
||||
int index = 1;
|
||||
for (String userId:users) {
|
||||
statement.setString(index++, userId);
|
||||
}
|
||||
|
||||
int count = statement.executeUpdate();
|
||||
LOG.info("Update rows {}", count);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
}
|
||||
|
||||
void persistGroupInfo(final WFCMessage.GroupInfo groupInfo) {
|
||||
mScheduler.execute(()->{
|
||||
Connection connection = null;
|
||||
@@ -986,7 +1153,7 @@ public class DatabaseStore {
|
||||
statement.setInt(index++, request.getPlatform());
|
||||
}
|
||||
if (session.getPushType() != request.getPushType()) {
|
||||
statement.setInt(index++, request.getPushType());
|
||||
statement.setInt(index++, request.getPushType() >= 32 ? 0 : request.getPushType());
|
||||
}
|
||||
if (!strEqual(session.getDeviceName(), request.getDeviceName())) {
|
||||
statement.setString(index++, request.getDeviceName());
|
||||
@@ -1098,7 +1265,6 @@ public class DatabaseStore {
|
||||
}
|
||||
|
||||
void persistGroupMember(final String groupId, final List<WFCMessage.GroupMember> memberList) {
|
||||
mScheduler.execute(()->{
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
@@ -1154,7 +1320,70 @@ public class DatabaseStore {
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
int removeGroupMember(String groupId, List<String> groupMembers) {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
PreparedStatement statement2 = null;
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
connection.setAutoCommit(false);
|
||||
|
||||
StringBuilder sqlBuilder = new StringBuilder("update t_group_member set `_type` = ?, `_dt` = ? where `_mid` in (");
|
||||
for (int i = 0; i < groupMembers.size(); i++) {
|
||||
sqlBuilder.append("?");
|
||||
if (i != groupMembers.size()-1) {
|
||||
sqlBuilder.append(",");
|
||||
}
|
||||
}
|
||||
sqlBuilder.append(")");
|
||||
|
||||
sqlBuilder.append(" and _gid = ?");
|
||||
|
||||
statement = connection.prepareStatement(sqlBuilder.toString());
|
||||
|
||||
int index = 1;
|
||||
long current = System.currentTimeMillis();
|
||||
statement.setInt(index++, ProtoConstants.GroupMemberType.GroupMemberType_Removed);
|
||||
statement.setLong(index++, current);
|
||||
|
||||
for (String memberId:groupMembers) {
|
||||
statement.setString(index++, memberId);
|
||||
}
|
||||
statement.setString(index++, groupId);
|
||||
|
||||
int count = statement.executeUpdate();
|
||||
LOG.info("Update rows {}", count);
|
||||
|
||||
String sql = "update t_group set `_member_count` = `_member_count` - ?, `_member_dt` = ? , `_dt` = ? where `_gid` = ?";
|
||||
|
||||
statement2 = connection.prepareStatement(sql);
|
||||
index = 1;
|
||||
statement2.setInt(index++, count);
|
||||
statement2.setLong(index++, current);
|
||||
statement2.setLong(index++, current);
|
||||
statement2.setString(index++, groupId);
|
||||
statement2.executeUpdate();
|
||||
connection.commit();
|
||||
connection.setAutoCommit(true);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.commit();
|
||||
connection.setAutoCommit(true);
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
DBUtil.closeDB(connection, statement2);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
WFCMessage.GroupInfo getPersistGroupInfo(String groupId) {
|
||||
@@ -1575,7 +1804,6 @@ public class DatabaseStore {
|
||||
|
||||
void updateUser(final WFCMessage.User user) {
|
||||
LOG.info("Database update user info {} {}", user.getUid(), user.getUpdateDt());
|
||||
mScheduler.execute(()->{
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
LOG.info("Database update user info {}", user.getDisplayName());
|
||||
@@ -1649,7 +1877,6 @@ public class DatabaseStore {
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void deleteUserStatus(String userId) {
|
||||
@@ -2007,7 +2234,6 @@ public class DatabaseStore {
|
||||
}
|
||||
|
||||
void persistFriendRequestUnreadStatus(String userId, long readDt, long updateDt) {
|
||||
mScheduler.execute(()->{
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
@@ -2034,11 +2260,9 @@ public class DatabaseStore {
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
});
|
||||
}
|
||||
//
|
||||
void persistOrUpdateFriendRequest(final WFCMessage.FriendRequest request) {
|
||||
mScheduler.execute(()->{
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
@@ -2075,11 +2299,9 @@ public class DatabaseStore {
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void persistOrUpdateFriendData(final FriendData request) {
|
||||
mScheduler.execute(()->{
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
@@ -2110,7 +2332,6 @@ public class DatabaseStore {
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
boolean removeGroupInfoFromDB(String groupId) {
|
||||
@@ -2158,7 +2379,6 @@ public class DatabaseStore {
|
||||
|
||||
void updateChannelInfo(final WFCMessage.ChannelInfo channelInfo) {
|
||||
LOG.info("Database update channel info {} {}", channelInfo.getTargetId(), channelInfo.getUpdateDt());
|
||||
mScheduler.execute(()->{
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
@@ -2221,7 +2441,6 @@ public class DatabaseStore {
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void removeChannelInfo(final String channelId) {
|
||||
@@ -2547,7 +2766,7 @@ public class DatabaseStore {
|
||||
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "select `_word` from t_sensitiveword";
|
||||
String sql = "select `_word` from t_sensitiveword order by `id` desc";
|
||||
|
||||
statement = connection.prepareStatement(sql);
|
||||
rs = statement.executeQuery();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.moquette.persistence;
|
||||
|
||||
import cn.wildfirechat.pojos.SystemSettingPojo;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.google.protobuf.ByteString;
|
||||
@@ -61,7 +62,6 @@ import static win.liyufan.im.MyInfoType.*;
|
||||
public class MemoryMessagesStore implements IMessagesStore {
|
||||
private static final String MESSAGES_MAP = "messages_map";
|
||||
private static final String GROUPS_MAP = "groups_map";
|
||||
private static final String GROUP_ID_COUNTER = "group_id_counter";
|
||||
static int dumy = 0;
|
||||
static final String GROUP_MEMBERS = "group_members";
|
||||
|
||||
@@ -83,6 +83,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
private static final String CHANNEL_LISTENERS = "channel_listeners";
|
||||
|
||||
private static boolean IS_MESSAGE_ROAMING = true;
|
||||
|
||||
private static boolean IS_MESSAGE_REMOTE_HISTORY_MESSAGE = true;
|
||||
|
||||
static final String USER_ROBOTS = "user_robots";
|
||||
static final String USER_THINGS = "user_things";
|
||||
|
||||
@@ -116,22 +120,20 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
MemoryMessagesStore(Server server, DatabaseStore databaseStore) {
|
||||
m_Server = server;
|
||||
this.databaseStore = databaseStore;
|
||||
IS_MESSAGE_ROAMING = "1".equals(m_Server.getConfig().getProperty(MESSAGE_ROAMING));
|
||||
IS_MESSAGE_REMOTE_HISTORY_MESSAGE = "1".equals(m_Server.getConfig().getProperty(MESSAGE_Remote_History_Message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initStore() {
|
||||
//TODO reload data from mysql
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(MemoryMessagesStore.GROUP_MEMBERS);
|
||||
if (groupMembers.size() == 0) {
|
||||
databaseStore.reloadGroupMemberFromDB(hzInstance);
|
||||
databaseStore.reloadFriendsFromDB(hzInstance);
|
||||
databaseStore.reloadFriendRequestsFromDB(hzInstance);
|
||||
}
|
||||
|
||||
updateSensitiveWord();
|
||||
}
|
||||
|
||||
private Collection<WFCMessage.GroupMember> loadGroupMemberFromDB(HazelcastInstance hzInstance, String groupId) {
|
||||
Collection<WFCMessage.GroupMember> members = databaseStore.reloadGroupMemberFromDB(hzInstance, groupId);
|
||||
return members;
|
||||
}
|
||||
|
||||
private void updateSensitiveWord() {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastUpdateSensitiveTime > 2 * 60 * 60 * 1000) {
|
||||
@@ -195,6 +197,9 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
} else {
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(message.getConversation().getTarget());
|
||||
if (members == null || members.size() == 0) {
|
||||
members = loadGroupMemberFromDB(hzInstance, message.getConversation().getTarget());
|
||||
}
|
||||
for (WFCMessage.GroupMember member : members) {
|
||||
if (member.getType() != GroupMemberType_Removed) {
|
||||
notifyReceivers.add(member.getMemberId());
|
||||
@@ -316,6 +321,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
});
|
||||
}
|
||||
|
||||
boolean noRoaming = false;
|
||||
if (pullType == ProtoConstants.PullType.Pull_Normal && fromMessageId == 0 && !IS_MESSAGE_ROAMING) {
|
||||
noRoaming = true;
|
||||
}
|
||||
while (true) {
|
||||
Map.Entry<Long, Long> entry = maps.higherEntry(current);
|
||||
if (entry == null) {
|
||||
@@ -335,6 +344,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
}
|
||||
|
||||
if (noRoaming && (System.currentTimeMillis() - bundle.getMessage().getServerTimestamp() > 5 * 60 * 1000)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
size += bundle.getMessage().getSerializedSize();
|
||||
if (size >= 1 * 1024 * 1024) { //3M
|
||||
break;
|
||||
@@ -360,7 +373,12 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
@Override
|
||||
public WFCMessage.PullMessageResult loadRemoteMessages(String user, WFCMessage.Conversation conversation, long beforeUid, int count) {
|
||||
WFCMessage.PullMessageResult.Builder builder = WFCMessage.PullMessageResult.newBuilder();
|
||||
List<WFCMessage.Message> messages = databaseStore.loadRemoteMessages(user, conversation, beforeUid, count);
|
||||
List<WFCMessage.Message> messages;
|
||||
if (IS_MESSAGE_REMOTE_HISTORY_MESSAGE) {
|
||||
messages = databaseStore.loadRemoteMessages(user, conversation, beforeUid, count);
|
||||
} else {
|
||||
messages = new ArrayList<>();
|
||||
}
|
||||
builder.setCurrent(0).setHead(0);
|
||||
if(messages != null) {
|
||||
builder.addAllMessage(messages);
|
||||
@@ -628,24 +646,35 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
if (groupInfo == null) {
|
||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
}
|
||||
if (groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted && (groupInfo.getOwner() == null || !groupInfo.getOwner().equals(operator))) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
|
||||
if (!isAdmin) {
|
||||
boolean isMember = false;
|
||||
for (WFCMessage.GroupMember member : memberList) {
|
||||
if (member.getType() == GroupMemberType_Removed) {
|
||||
boolean isManager = false;
|
||||
WFCMessage.GroupMember gm = getGroupMember(groupId, operator);
|
||||
if (gm != null) {
|
||||
if (gm.getType() == GroupMemberType_Removed && !(memberList.size() == 1 && operator.equals(memberList.get(0).getMemberId()))) {
|
||||
return ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
||||
} else if(member.getType() == GroupMemberType_Silent) {
|
||||
} else if (gm.getType() == GroupMemberType_Silent) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
isMember = true;
|
||||
break;
|
||||
isManager = (gm.getType() == GroupMemberType_Manager || gm.getType() == GroupMemberType_Owner);
|
||||
|
||||
if (gm.getType() != GroupMemberType_Removed) {
|
||||
isMember = true;
|
||||
}
|
||||
}
|
||||
if (!isMember) {
|
||||
|
||||
if (groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted && ((groupInfo.getOwner() == null || !groupInfo.getOwner().equals(operator)) && !isManager)) {
|
||||
if (groupInfo.getJoinType() == 2) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
} else if (groupInfo.getJoinType() == 1) {
|
||||
if (memberList.size() == 1 && operator.equals(memberList.get(0).getMemberId()))
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isMember && !(memberList.size() == 1 && operator.equals(memberList.get(0).getMemberId()))) {
|
||||
return ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
||||
}
|
||||
}
|
||||
@@ -661,7 +690,13 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
memberList = tmp;
|
||||
|
||||
for (WFCMessage.GroupMember member : groupMembers.get(groupId)) {
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
||||
if (members == null || members.size() == 0) {
|
||||
members = loadGroupMemberFromDB(hzInstance, groupId);
|
||||
}
|
||||
|
||||
for (WFCMessage.GroupMember member : members) {
|
||||
if (newInviteUsers.contains(member.getMemberId())) {
|
||||
groupMembers.remove(groupId, member);
|
||||
}
|
||||
@@ -685,44 +720,34 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode kickoffGroupMembers(String operator, String groupId, List<String> memberList) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
IMap<String, WFCMessage.GroupInfo> mIMap = hzInstance.getMap(GROUPS_MAP);
|
||||
public ErrorCode kickoffGroupMembers(String operator, boolean isAdmin, String groupId, List<String> memberList) {
|
||||
removeGroupMember(groupId, memberList);
|
||||
removeFavGroup(groupId, memberList);
|
||||
removeGroupUserSettings(groupId, memberList);
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
WFCMessage.GroupInfo groupInfo = mIMap.get(groupId);
|
||||
if (groupInfo == null) {
|
||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
}
|
||||
if ((groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal)
|
||||
&& (groupInfo.getOwner() == null || !groupInfo.getOwner().equals(operator))) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
void removeGroupMember(String groupId, List<String> memberIds) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
databaseStore.removeGroupMember(groupId, memberIds);
|
||||
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
groupMembers.remove(groupId);
|
||||
IMap<String, WFCMessage.GroupInfo> mIMap = hzInstance.getMap(GROUPS_MAP);
|
||||
mIMap.evict(groupId);
|
||||
|
||||
int removeCount = 0;
|
||||
long updateDt = System.currentTimeMillis();
|
||||
ArrayList<WFCMessage.GroupMember> list = new ArrayList<>();
|
||||
List<WFCMessage.GroupMember> allMembers = new ArrayList<>(groupMembers.get(groupId));
|
||||
for (WFCMessage.GroupMember member : allMembers) {
|
||||
if (memberList.contains(member.getMemberId())) {
|
||||
boolean removed = groupMembers.remove(groupId, member);
|
||||
if (removed) {
|
||||
removeCount++;
|
||||
member = member.toBuilder().setType(GroupMemberType_Removed).setUpdateDt(updateDt).build();
|
||||
groupMembers.put(groupId, member);
|
||||
list.add(member);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeFavGroup(String groupId, List<String> memberIds) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
MultiMap<String, WFCMessage.UserSettingEntry> userSettingMap = hzInstance.getMultiMap(USER_SETTING);
|
||||
|
||||
databaseStore.removeFavGroup(groupId, memberIds);
|
||||
|
||||
for (String member : memberIds) {
|
||||
userSettingMap.remove(member);
|
||||
}
|
||||
|
||||
if (removeCount > 0) {
|
||||
databaseStore.persistGroupMember(groupId, list);
|
||||
databaseStore.updateGroupMemberCountDt(groupId, groupInfo.getMemberCount()-removeCount, updateDt);
|
||||
mIMap.put(groupId, groupInfo.toBuilder().setMemberUpdateDt(updateDt).setUpdateDt(updateDt).setMemberCount(groupInfo.getMemberCount() - removeCount).build());
|
||||
}
|
||||
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -733,8 +758,11 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
WFCMessage.GroupInfo groupInfo = mIMap.get(groupId);
|
||||
if (groupInfo == null) {
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
for (WFCMessage.GroupMember member : groupMembers.get(groupId)
|
||||
) {
|
||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
||||
if (members == null || members.size() == 0) {
|
||||
members = loadGroupMemberFromDB(hzInstance, groupId);
|
||||
}
|
||||
for (WFCMessage.GroupMember member :members) {
|
||||
if (member.getMemberId().equals(operator)) {
|
||||
groupMembers.remove(groupId, member);
|
||||
break;
|
||||
@@ -746,33 +774,24 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
if (groupInfo.getType() != ProtoConstants.GroupType.GroupType_Free && groupInfo.getOwner() != null && groupInfo.getOwner().equals(operator)) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
|
||||
long updateDt = System.currentTimeMillis();
|
||||
boolean removed = false;
|
||||
for (WFCMessage.GroupMember member : groupMembers.get(groupId)
|
||||
) {
|
||||
if (member.getMemberId().equals(operator)) {
|
||||
removed = groupMembers.remove(groupId, member);
|
||||
if (removed) {
|
||||
ArrayList<WFCMessage.GroupMember> list = new ArrayList<>();
|
||||
list.add(member);
|
||||
databaseStore.persistGroupMember(groupId, list);
|
||||
|
||||
databaseStore.updateGroupMemberCountDt(groupId, groupInfo.getMemberCount()-1, updateDt);
|
||||
member = member.toBuilder().setType(GroupMemberType_Removed).setUpdateDt(updateDt).build();
|
||||
groupMembers.put(groupId, member);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (removed) {
|
||||
mIMap.put(groupId, groupInfo.toBuilder().setMemberUpdateDt(updateDt).setUpdateDt(updateDt).setMemberCount(groupInfo.getMemberCount() - 1).build());
|
||||
}
|
||||
removeGroupMember(groupId, Arrays.asList(operator));
|
||||
removeFavGroup(groupId, Arrays.asList(operator));
|
||||
removeGroupUserSettings(groupId, Arrays.asList(operator));
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
private void removeGroupUserSettings(String groupId, List<String> users) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
MultiMap<String, WFCMessage.UserSettingEntry> userSettingMap = hzInstance.getMultiMap(USER_SETTING);
|
||||
|
||||
databaseStore.removeGroupUserSettings(groupId, users);
|
||||
for (String userId:users) {
|
||||
userSettingMap.remove(userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode dismissGroup(String operator, String groupId, boolean isAdmin) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
@@ -795,16 +814,30 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
|
||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
||||
if (members == null || members.size() == 0) {
|
||||
members = loadGroupMemberFromDB(hzInstance, groupId);
|
||||
}
|
||||
|
||||
groupMembers.remove(groupId);
|
||||
mIMap.remove(groupId);
|
||||
|
||||
databaseStore.removeGroupMemberFromDB(groupId);
|
||||
|
||||
ArrayList<String> ids = new ArrayList<>();
|
||||
if (members != null) {
|
||||
for (WFCMessage.GroupMember member : members) {
|
||||
ids.add(member.getMemberId());
|
||||
}
|
||||
}
|
||||
removeFavGroup(groupId, ids);
|
||||
removeGroupUserSettings(groupId, ids);
|
||||
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode modifyGroupInfo(String operator, String groupId, int modifyType, String value) {
|
||||
public ErrorCode modifyGroupInfo(String operator, String groupId, int modifyType, String value, boolean isAdmin) {
|
||||
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
IMap<String, WFCMessage.GroupInfo> mIMap = hzInstance.getMap(GROUPS_MAP);
|
||||
@@ -815,22 +848,36 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
}
|
||||
|
||||
if ((oldInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted)
|
||||
&& (oldInfo.getOwner() == null || !oldInfo.getOwner().equals(operator))) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
|
||||
if (oldInfo.getType() == ProtoConstants.GroupType.GroupType_Normal) {
|
||||
if (oldInfo.getOwner() == null) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
if (!oldInfo.getOwner().equals(operator)) {
|
||||
if (modifyType == Modify_Group_Extra) {
|
||||
if (!isAdmin) {
|
||||
if (oldInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted) {
|
||||
boolean isAllow = false;
|
||||
if ((oldInfo.getOwner() != null && oldInfo.getOwner().equals(operator))) {
|
||||
isAllow = true;
|
||||
} else {
|
||||
WFCMessage.GroupMember gm = getGroupMember(groupId, operator);
|
||||
if (gm != null && gm.getType() == GroupMemberType_Manager) {
|
||||
isAllow = true;
|
||||
}
|
||||
}
|
||||
if (!isAllow) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
if (oldInfo.getType() == ProtoConstants.GroupType.GroupType_Normal) {
|
||||
if (oldInfo.getOwner() == null) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
if (!oldInfo.getOwner().equals(operator)) {
|
||||
if (modifyType == Modify_Group_Extra) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
WFCMessage.GroupInfo.Builder newInfoBuilder = oldInfo.toBuilder();
|
||||
|
||||
if (modifyType == Modify_Group_Name)
|
||||
@@ -874,8 +921,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
long updateDt = System.currentTimeMillis();
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
||||
for (WFCMessage.GroupMember member : members
|
||||
) {
|
||||
if (members == null || members.size() == 0) {
|
||||
members = loadGroupMemberFromDB(hzInstance, groupId);
|
||||
}
|
||||
for (WFCMessage.GroupMember member : members) {
|
||||
if (member.getMemberId().equals(operator)) {
|
||||
groupMembers.remove(groupId, member);
|
||||
member = member.toBuilder().setAlias(alias).setUpdateDt(updateDt).build();
|
||||
@@ -919,12 +968,6 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
IMap<String, WFCMessage.GroupInfo> mIMap = hzInstance.getMap(GROUPS_MAP);
|
||||
|
||||
WFCMessage.GroupInfo groupInfo = mIMap.get(groupId);
|
||||
if (groupInfo == null) {
|
||||
groupInfo = databaseStore.getPersistGroupInfo(groupId);
|
||||
if (groupInfo != null) {
|
||||
mIMap.put(groupId, groupInfo);
|
||||
}
|
||||
}
|
||||
return groupInfo;
|
||||
}
|
||||
|
||||
@@ -941,11 +984,41 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
Collection<WFCMessage.GroupMember> memberCollection = groupMembers.get(groupId);
|
||||
if (memberCollection == null || memberCollection.size() == 0) {
|
||||
memberCollection = loadGroupMemberFromDB(hzInstance, groupId);
|
||||
}
|
||||
for (WFCMessage.GroupMember member:memberCollection) {
|
||||
if (member.getUpdateDt() > maxDt) {
|
||||
members.add(member);
|
||||
}
|
||||
}
|
||||
|
||||
members.addAll(groupMembers.get(groupId));
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WFCMessage.GroupMember getGroupMember(String groupId, String memberId) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
|
||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
||||
if (members == null || members.size() == 0) {
|
||||
members = loadGroupMemberFromDB(hzInstance, groupId);
|
||||
}
|
||||
|
||||
if (members != null) {
|
||||
for (WFCMessage.GroupMember gm : members) {
|
||||
if (gm.getMemberId().equals(memberId)) {
|
||||
return gm;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ErrorCode transferGroup(String operator, String groupId, String newOwner, boolean isAdmin) {
|
||||
@@ -965,10 +1038,29 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
|
||||
//check the new owner is in member list? is that necessary?
|
||||
|
||||
groupInfo = groupInfo.toBuilder().setOwner(newOwner).build();
|
||||
long updateDt = System.currentTimeMillis();
|
||||
groupInfo = groupInfo.toBuilder().setOwner(newOwner).setUpdateDt(updateDt).build();
|
||||
|
||||
mIMap.set(groupId, groupInfo);
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
||||
if (members == null || members.size() == 0) {
|
||||
members = loadGroupMemberFromDB(hzInstance, groupId);
|
||||
}
|
||||
for (WFCMessage.GroupMember member : members) {
|
||||
if (newOwner.equals(member.getMemberId())) {
|
||||
groupMembers.remove(groupId, member);
|
||||
member = member.toBuilder().setType(GroupMemberType_Owner).setUpdateDt(updateDt).build();
|
||||
databaseStore.persistGroupMember(groupId, Arrays.asList(member));
|
||||
groupMembers.put(groupId, member);
|
||||
} else if(member.getType() == GroupMemberType_Owner) {
|
||||
groupMembers.remove(groupId, member);
|
||||
member = member.toBuilder().setType(GroupMemberType_Normal).setUpdateDt(updateDt).build();
|
||||
databaseStore.persistGroupMember(groupId, Arrays.asList(member));
|
||||
groupMembers.put(groupId, member);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
@@ -993,10 +1085,13 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
long updateDt = System.currentTimeMillis();
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
||||
if (members == null || members.size() == 0) {
|
||||
members = loadGroupMemberFromDB(hzInstance, groupId);
|
||||
}
|
||||
for (WFCMessage.GroupMember member : members) {
|
||||
if (userList.contains(member.getMemberId())) {
|
||||
groupMembers.remove(groupId, member);
|
||||
member = member.toBuilder().setType(ProtoConstants.GroupMemberType.GroupMemberType_Manager).setUpdateDt(updateDt).build();
|
||||
member = member.toBuilder().setType(type == 0 ? ProtoConstants.GroupMemberType.GroupMemberType_Normal : ProtoConstants.GroupMemberType.GroupMemberType_Manager).setUpdateDt(updateDt).build();
|
||||
databaseStore.persistGroupMember(groupId, Arrays.asList(member));
|
||||
groupMembers.put(groupId, member);
|
||||
// userList.remove(member.getMemberId());
|
||||
@@ -1013,7 +1108,9 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
|
||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
||||
|
||||
if (members == null || members.size() == 0) {
|
||||
members = loadGroupMemberFromDB(hzInstance, groupId);
|
||||
}
|
||||
for (WFCMessage.GroupMember member : members
|
||||
) {
|
||||
if (member.getMemberId().equals(memberId) && member.getType() != GroupMemberType_Removed)
|
||||
@@ -1031,11 +1128,16 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
WFCMessage.GroupInfo groupInfo = groups.get(groupId);
|
||||
boolean isMute = false;
|
||||
if (groupInfo != null) {
|
||||
if (groupInfo.getOwner().equals(memberId)) {
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
isMute = groupInfo.getMute()>0;
|
||||
}
|
||||
|
||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
||||
|
||||
if (members == null || members.size() == 0) {
|
||||
members = loadGroupMemberFromDB(hzInstance, groupId);
|
||||
}
|
||||
for (WFCMessage.GroupMember member : members
|
||||
) {
|
||||
if (member.getMemberId().equals(memberId)) {
|
||||
@@ -1047,9 +1149,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return ErrorCode.ERROR_CODE_GROUP_MUTED;
|
||||
}
|
||||
|
||||
if (member.getMemberId().equals(memberId) && member.getType() != GroupMemberType_Removed) {
|
||||
if (member.getMemberId().equals(memberId) && member.getType() == GroupMemberType_Removed) {
|
||||
return ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1058,7 +1161,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode recallMessage(long messageUid, String operatorId) {
|
||||
public ErrorCode recallMessage(long messageUid, String operatorId, boolean isAdmin) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
IMap<Long, MessageBundle> mIMap = hzInstance.getMap(MESSAGES_MAP);
|
||||
|
||||
@@ -1066,7 +1169,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
if (messageBundle != null) {
|
||||
WFCMessage.Message message = messageBundle.getMessage();
|
||||
boolean canRecall = false;
|
||||
if (message.getFromUser().equals(operatorId)) {
|
||||
if (isAdmin) {
|
||||
canRecall = true;
|
||||
}
|
||||
if (!isAdmin && message.getFromUser().equals(operatorId)) {
|
||||
canRecall = true;
|
||||
}
|
||||
|
||||
@@ -1083,6 +1189,9 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(message.getConversation().getTarget());
|
||||
if (members == null || members.size() == 0) {
|
||||
members = loadGroupMemberFromDB(hzInstance, message.getConversation().getTarget());
|
||||
}
|
||||
for (WFCMessage.GroupMember member : members) {
|
||||
if (member.getMemberId().equals(operatorId)) {
|
||||
if (member.getType() == GroupMemberType_Manager || member.getType() == ProtoConstants.GroupMemberType.GroupMemberType_Owner) {
|
||||
@@ -1106,6 +1215,8 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
message = message.toBuilder().setContent(message.getContent().toBuilder().setContent(operatorId).setType(80).clearSearchableContent().setData(ByteString.copyFrom(new StringBuffer().append(messageUid).toString().getBytes())).build()).build();
|
||||
messageBundle.setMessage(message);
|
||||
|
||||
databaseStore.deleteMessage(messageUid);
|
||||
|
||||
mIMap.put(messageUid, messageBundle, 7, TimeUnit.DAYS);
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
} else {
|
||||
@@ -1311,6 +1422,16 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return databaseStore.searchUserFromDB(keyword, buzzy, page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateSystemSetting(int id, String value, String desc) {
|
||||
return databaseStore.updateSystemSetting(id, value, desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemSettingPojo getSystemSetting(int id) {
|
||||
return databaseStore.getSystemSetting(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createChatroom(String chatroomId, WFCMessage.ChatroomInfo chatroomInfo) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
@@ -1429,8 +1550,8 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
Collection<FriendData> friendDatas = friendsMap.get(fromUser);
|
||||
|
||||
if (friendDatas == null) {
|
||||
return false;
|
||||
if (friendDatas == null || friendDatas.size() == 0) {
|
||||
friendDatas = loadFriend(friendsMap, fromUser);
|
||||
}
|
||||
|
||||
for (FriendData friendData : friendDatas) {
|
||||
@@ -1501,6 +1622,31 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
}
|
||||
|
||||
synchronized Collection<FriendData> loadFriend(MultiMap<String, FriendData> friendsMap, String userId) {
|
||||
Collection<FriendData> friends = databaseStore.getPersistFriends(userId);
|
||||
if (friends != null) {
|
||||
for (FriendData friend : friends) {
|
||||
friendsMap.put(userId, friend);
|
||||
}
|
||||
} else {
|
||||
friends = new ArrayList<>();
|
||||
}
|
||||
return friends;
|
||||
}
|
||||
|
||||
synchronized Collection<WFCMessage.FriendRequest> loadFriendRequest(MultiMap<String, WFCMessage.FriendRequest> requestMap, String userId) {
|
||||
Collection<WFCMessage.FriendRequest> requests = databaseStore.getPersistFriendRequests(userId);
|
||||
if (requests != null) {
|
||||
for (WFCMessage.FriendRequest r : requests
|
||||
) {
|
||||
requestMap.put(userId, r);
|
||||
}
|
||||
} else {
|
||||
requests = new ArrayList<>();
|
||||
}
|
||||
return requests;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FriendData> getFriendList(String userId, long version) {
|
||||
List<FriendData> out = new ArrayList<FriendData>();
|
||||
@@ -1509,14 +1655,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
|
||||
Collection<FriendData> friends = friendsMap.get(userId);
|
||||
if (friends == null || friends.size() == 0) {
|
||||
friends = databaseStore.getPersistFriends(userId);
|
||||
if (friends != null) {
|
||||
for (FriendData friend : friends) {
|
||||
friendsMap.put(userId, friend);
|
||||
}
|
||||
} else {
|
||||
friends = new ArrayList<>();
|
||||
}
|
||||
friends = loadFriend(friendsMap, userId);
|
||||
}
|
||||
|
||||
for (FriendData friend : friends) {
|
||||
@@ -1536,15 +1675,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
MultiMap<String, WFCMessage.FriendRequest> requestMap = hzInstance.getMultiMap(USER_FRIENDS_REQUEST);
|
||||
Collection<WFCMessage.FriendRequest> requests = requestMap.get(userId);
|
||||
if (requests == null || requests.size() == 0) {
|
||||
requests = databaseStore.getPersistFriendRequests(userId);
|
||||
if (requests != null) {
|
||||
for (WFCMessage.FriendRequest request : requests) {
|
||||
if (request.getUpdateDt() > version)
|
||||
requestMap.put(userId, request);
|
||||
}
|
||||
} else {
|
||||
requests = new ArrayList<>();
|
||||
}
|
||||
requests = loadFriendRequest(requestMap, userId);
|
||||
}
|
||||
|
||||
for (WFCMessage.FriendRequest request : requests) {
|
||||
@@ -1562,15 +1693,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
MultiMap<String, WFCMessage.FriendRequest> requestMap = hzInstance.getMultiMap(USER_FRIENDS_REQUEST);
|
||||
Collection<WFCMessage.FriendRequest> requests = requestMap.get(userId);
|
||||
if (requests == null || requests.size() == 0) {
|
||||
requests = databaseStore.getPersistFriendRequests(userId);
|
||||
if (requests != null) {
|
||||
for (WFCMessage.FriendRequest r : requests
|
||||
) {
|
||||
requestMap.put(userId, r);
|
||||
}
|
||||
} else {
|
||||
requests = new ArrayList<>();
|
||||
}
|
||||
requests = loadFriendRequest(requestMap, userId);
|
||||
}
|
||||
|
||||
WFCMessage.FriendRequest existRequest = null;
|
||||
@@ -1588,7 +1711,6 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
&& System.currentTimeMillis() - existRequest.getUpdateDt() < 30 * 24 * 60 * 60 * 1000) {
|
||||
return ErrorCode.ERROR_CODE_FRIEND_REQUEST_BLOCKED;
|
||||
}
|
||||
requestMap.remove(userId, existRequest);
|
||||
} else {
|
||||
return ErrorCode.ERROR_CODE_FRIEND_ALREADY_REQUEST;
|
||||
}
|
||||
@@ -1603,9 +1725,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
.setUpdateDt(System.currentTimeMillis())
|
||||
.build();
|
||||
|
||||
requestMap.put(userId, newRequest);
|
||||
requestMap.put(request.getTargetUid(), newRequest);
|
||||
databaseStore.persistOrUpdateFriendRequest(newRequest);
|
||||
requestMap.remove(userId);
|
||||
requestMap.remove(request.getTargetUid());
|
||||
|
||||
head[0] = newRequest.getUpdateDt();
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
@@ -1633,6 +1756,9 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
FriendData friendData1 = null;
|
||||
Collection<FriendData> friendDatas = friendsMap.get(userId);
|
||||
if (friendDatas == null || friendDatas.size() == 0) {
|
||||
friendDatas = loadFriend(friendsMap, userId);
|
||||
}
|
||||
for (FriendData fd : friendDatas) {
|
||||
if (fd.getFriendUid().equals(request.getTargetUid())) {
|
||||
friendData1 = fd;
|
||||
@@ -1642,18 +1768,19 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
if (friendData1 == null) {
|
||||
friendData1 = new FriendData(userId, request.getTargetUid(), "", request.getStatus(), System.currentTimeMillis());
|
||||
} else {
|
||||
friendsMap.remove(userId, friendData1);
|
||||
friendData1.setState(request.getStatus());
|
||||
friendData1.setTimestamp(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
friendsMap.put(userId, friendData1);
|
||||
databaseStore.persistOrUpdateFriendData(friendData1);
|
||||
|
||||
if (request.getStatus() != 2) {
|
||||
FriendData friendData2 = null;
|
||||
|
||||
friendDatas = friendsMap.get(request.getTargetUid());
|
||||
if (friendDatas == null || friendDatas.size() == 0) {
|
||||
friendDatas = loadFriend(friendsMap, request.getTargetUid());
|
||||
}
|
||||
for (FriendData fd : friendDatas) {
|
||||
if (fd.getFriendUid().equals(userId)) {
|
||||
friendData2 = fd;
|
||||
@@ -1668,8 +1795,6 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
friendData2.setTimestamp(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
||||
friendsMap.put(request.getTargetUid(), friendData2);
|
||||
databaseStore.persistOrUpdateFriendData(friendData2);
|
||||
|
||||
heads[0] = friendData2.getTimestamp();
|
||||
@@ -1677,19 +1802,15 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
heads[0] = 0;
|
||||
}
|
||||
heads[1] = friendData1.getTimestamp();
|
||||
friendsMap.remove(userId);
|
||||
friendsMap.remove(request.getTargetUid());
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
MultiMap<String, WFCMessage.FriendRequest> requestMap = hzInstance.getMultiMap(USER_FRIENDS_REQUEST);
|
||||
Collection<WFCMessage.FriendRequest> requests = requestMap.get(userId);
|
||||
if (requests == null || requests.size() == 0) {
|
||||
requests = databaseStore.getPersistFriendRequests(userId);
|
||||
if (requests != null) {
|
||||
for (WFCMessage.FriendRequest r : requests
|
||||
) {
|
||||
requestMap.put(userId, r);
|
||||
}
|
||||
}
|
||||
requests = loadFriendRequest(requestMap, userId);
|
||||
}
|
||||
|
||||
WFCMessage.FriendRequest existRequest = null;
|
||||
@@ -1704,22 +1825,21 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
if (System.currentTimeMillis() - existRequest.getUpdateDt() > 7 * 24 * 60 * 60 * 1000) {
|
||||
return ErrorCode.ERROR_CODE_FRIEND_REQUEST_OVERTIME;
|
||||
} else {
|
||||
requestMap.remove(userId, existRequest);
|
||||
existRequest = existRequest.toBuilder().setStatus(ProtoConstants.FriendRequestStatus.RequestStatus_Accepted).setUpdateDt(System.currentTimeMillis()).build();
|
||||
databaseStore.persistOrUpdateFriendRequest(existRequest);
|
||||
requestMap.put(userId, existRequest);
|
||||
|
||||
|
||||
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
|
||||
|
||||
FriendData friendData1 = new FriendData(userId, request.getTargetUid(), "", 0, System.currentTimeMillis());
|
||||
friendsMap.put(userId, friendData1);
|
||||
databaseStore.persistOrUpdateFriendData(friendData1);
|
||||
|
||||
FriendData friendData2 = new FriendData(request.getTargetUid(), userId, "", 0, friendData1.getTimestamp());
|
||||
friendsMap.put(request.getTargetUid(), friendData2);
|
||||
databaseStore.persistOrUpdateFriendData(friendData2);
|
||||
|
||||
requestMap.remove(userId);
|
||||
requestMap.remove(request.getTargetUid());
|
||||
friendsMap.remove(userId);
|
||||
friendsMap.remove(request.getTargetUid());
|
||||
|
||||
heads[0] = friendData2.getTimestamp();
|
||||
heads[1] = friendData1.getTimestamp();
|
||||
|
||||
@@ -1739,6 +1859,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
FriendData friendData = null;
|
||||
Collection<FriendData> friends = friendsMap.get(fromUser);
|
||||
if (friends == null || friends.size() == 0) {
|
||||
friends = loadFriend(friendsMap, fromUser);
|
||||
}
|
||||
|
||||
for (FriendData fd:friends) {
|
||||
if (fd.getFriendUid().equals(targetUserId)) {
|
||||
friendData = fd;
|
||||
@@ -1752,8 +1876,9 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
friendData.setState(state);
|
||||
friendData.setTimestamp(System.currentTimeMillis());
|
||||
|
||||
friendsMap.put(fromUser, friendData);
|
||||
|
||||
databaseStore.persistOrUpdateFriendData(friendData);
|
||||
friendsMap.remove(fromUser);
|
||||
|
||||
heads[0] = friendData.getTimestamp();
|
||||
|
||||
@@ -1767,6 +1892,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
FriendData friendData = null;
|
||||
Collection<FriendData> friends = friendsMap.get(fromUser);
|
||||
if (friends == null || friends.size() == 0) {
|
||||
friends = loadFriend(friendsMap, fromUser);
|
||||
}
|
||||
|
||||
for (FriendData fd:friends) {
|
||||
if (fd.getFriendUid().equals(targetUserId)) {
|
||||
friendData = fd;
|
||||
@@ -1777,16 +1906,16 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
if (friendData == null) {
|
||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
}
|
||||
friendsMap.remove(fromUser, friendData);
|
||||
|
||||
friendData.setAlias(alias);
|
||||
friendData.setTimestamp(System.currentTimeMillis());
|
||||
|
||||
friendsMap.put(fromUser, friendData);
|
||||
databaseStore.persistOrUpdateFriendData(friendData);
|
||||
|
||||
heads[0] = friendData.getTimestamp();
|
||||
|
||||
friendsMap.remove(fromUser);
|
||||
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1821,35 +1950,43 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode deleteFriend(String userId, String friendUid) {
|
||||
public ErrorCode deleteFriend(String userId, String friendUid, long[] head) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
|
||||
Collection<FriendData> user1Friends = friendsMap.get(userId);
|
||||
if (user1Friends == null || user1Friends.size() == 0) {
|
||||
user1Friends = loadFriend(friendsMap, userId);
|
||||
}
|
||||
for (FriendData data :
|
||||
user1Friends) {
|
||||
if (data.getFriendUid().equals(friendUid)) {
|
||||
friendsMap.remove(userId, data);
|
||||
long ts = System.currentTimeMillis();
|
||||
head[0] = ts;
|
||||
data.setState(1);
|
||||
data.setTimestamp(System.currentTimeMillis());
|
||||
friendsMap.put(userId, data);
|
||||
data.setTimestamp(ts);
|
||||
databaseStore.persistOrUpdateFriendData(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Collection<FriendData> user2Friends = friendsMap.get(friendUid);
|
||||
if (user2Friends == null || user2Friends.size() == 0) {
|
||||
user2Friends = loadFriend(friendsMap, friendUid);
|
||||
}
|
||||
for (FriendData data :
|
||||
user2Friends) {
|
||||
if (data.getFriendUid().equals(userId)) {
|
||||
friendsMap.remove(friendUid, data);
|
||||
data.setState(1);
|
||||
data.setTimestamp(System.currentTimeMillis());
|
||||
friendsMap.put(friendUid, data);
|
||||
long ts = System.currentTimeMillis();
|
||||
head[1] = ts;
|
||||
data.setTimestamp(ts);
|
||||
databaseStore.persistOrUpdateFriendData(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
friendsMap.remove(userId);
|
||||
friendsMap.remove(friendUid);
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -2171,7 +2308,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
public boolean addSensitiveWords(List<String> words) {
|
||||
for (String word :
|
||||
words) {
|
||||
databaseStore.persistSensitiveWord(word);
|
||||
databaseStore.persistSensitiveWord(word.toLowerCase());
|
||||
}
|
||||
lastUpdateSensitiveTime = 0;
|
||||
return true;
|
||||
@@ -2240,15 +2377,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
|
||||
Collection<FriendData> friends = friendsMap.get(userId);
|
||||
long max = 0;
|
||||
if (friends == null || friends.size() == 0) {
|
||||
friends = databaseStore.getPersistFriends(userId);
|
||||
for (FriendData friend :
|
||||
friends) {
|
||||
friendsMap.put(userId, friend);
|
||||
}
|
||||
friends = loadFriend(friendsMap, userId);
|
||||
}
|
||||
|
||||
long max = 0;
|
||||
if (friends != null && friends.size() > 0) {
|
||||
for (FriendData friend :
|
||||
friends) {
|
||||
@@ -2267,11 +2399,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
Collection<WFCMessage.FriendRequest> friendsReq = friendsReqMap.get(userId);
|
||||
long max = 0;
|
||||
if (friendsReq == null || friendsReq.size() == 0) {
|
||||
friendsReq = databaseStore.getPersistFriendRequests(userId);
|
||||
for (WFCMessage.FriendRequest req : friendsReq
|
||||
) {
|
||||
friendsReqMap.put(userId, req);
|
||||
}
|
||||
friendsReq = loadFriendRequest(friendsReqMap, userId);
|
||||
}
|
||||
|
||||
if (friendsReq != null && friendsReq.size() > 0) {
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2017 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package io.moquette.server.netty;
|
||||
|
||||
import com.bugsnag.Bugsnag;
|
||||
import io.moquette.server.config.IConfig;
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
|
||||
import static io.moquette.BrokerConstants.BUGSNAG_TOKEN_PROPERTY_NAME;
|
||||
|
||||
@Sharable
|
||||
public class BugSnagErrorsHandler extends ChannelInboundHandlerAdapter {
|
||||
|
||||
private Bugsnag bugsnag;
|
||||
|
||||
public void init(IConfig props) {
|
||||
final String token = props.getProperty(BUGSNAG_TOKEN_PROPERTY_NAME);
|
||||
this.bugsnag = new Bugsnag(token);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
bugsnag.notify(cause);
|
||||
ctx.fireExceptionCaught(cause);
|
||||
}
|
||||
}
|
||||
@@ -139,25 +139,11 @@ public class NettyAcceptor implements ServerAcceptor {
|
||||
|
||||
final NettyMQTTHandler mqttHandler = new NettyMQTTHandler(processor);
|
||||
|
||||
final boolean useFineMetrics = Boolean.parseBoolean(props.getProperty(METRICS_ENABLE_PROPERTY_NAME, "false"));
|
||||
if (useFineMetrics) {
|
||||
DropWizardMetricsHandler metricsHandler = new DropWizardMetricsHandler();
|
||||
metricsHandler.init(props);
|
||||
this.metrics = Optional.of(metricsHandler);
|
||||
} else {
|
||||
this.metrics = Optional.empty();
|
||||
}
|
||||
this.metrics = Optional.empty();
|
||||
|
||||
this.errorsCather = Optional.empty();
|
||||
|
||||
final boolean useBugSnag = Boolean.parseBoolean(props.getProperty(BUGSNAG_ENABLE_PROPERTY_NAME, "false"));
|
||||
if (useBugSnag) {
|
||||
BugSnagErrorsHandler bugSnagHandler = new BugSnagErrorsHandler();
|
||||
bugSnagHandler.init(props);
|
||||
this.errorsCather = Optional.of(bugSnagHandler);
|
||||
} else {
|
||||
this.errorsCather = Optional.empty();
|
||||
}
|
||||
initializePlainTCPTransport(mqttHandler, props);
|
||||
initializeWebSocketTransport(mqttHandler, props);
|
||||
String sslTcpPortProp = props.getProperty(BrokerConstants.SSL_PORT_PROPERTY_NAME);
|
||||
String wssPortProp = props.getProperty(BrokerConstants.WSS_PORT_PROPERTY_NAME);
|
||||
if (sslTcpPortProp != null || wssPortProp != null) {
|
||||
@@ -239,42 +225,6 @@ public class NettyAcceptor implements ServerAcceptor {
|
||||
});
|
||||
}
|
||||
|
||||
private void initializeWebSocketTransport(final NettyMQTTHandler handler, IConfig props) throws IOException {
|
||||
LOG.info("Configuring Websocket MQTT transport");
|
||||
String webSocketPortProp = props.getProperty(WEB_SOCKET_PORT_PROPERTY_NAME, DISABLED_PORT_BIND);
|
||||
if (DISABLED_PORT_BIND.equals(webSocketPortProp)) {
|
||||
// Do nothing no WebSocket configured
|
||||
LOG.info("Property {} has been setted to {}. Websocket MQTT will be disabled",
|
||||
BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, DISABLED_PORT_BIND);
|
||||
return;
|
||||
}
|
||||
int port = Integer.parseInt(webSocketPortProp);
|
||||
|
||||
final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler();
|
||||
|
||||
String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
|
||||
initFactory(host, port, "Websocket MQTT", new PipelineInitializer() {
|
||||
|
||||
@Override
|
||||
void init(ChannelPipeline pipeline) {
|
||||
pipeline.addLast(new HttpServerCodec());
|
||||
pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
|
||||
pipeline.addLast("webSocketHandler",
|
||||
new WebSocketServerProtocolHandler("/org/fusesource/mqtt", MQTT_SUBPROTOCOL_CSV_LIST));
|
||||
pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder());
|
||||
pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder());
|
||||
pipeline.addFirst("idleStateHandler", new IdleStateHandler(nettyChannelTimeoutSeconds, 0, 0));
|
||||
pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
|
||||
pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
|
||||
pipeline.addLast("decoder", new MqttDecoder());
|
||||
pipeline.addLast("encoder", MqttEncoder.INSTANCE);
|
||||
pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
|
||||
pipeline.addLast("messageLogger", new MQTTMessageLogger());
|
||||
pipeline.addLast("handler", handler);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initializeSSLTCPTransport(final NettyMQTTHandler handler, IConfig props, final SSLContext sslContext)
|
||||
throws IOException {
|
||||
LOG.info("Configuring SSL MQTT transport");
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.moquette.server.netty.metrics;
|
||||
|
||||
import io.moquette.server.netty.NettyUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
@@ -23,10 +24,15 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import io.netty.util.Attribute;
|
||||
import io.netty.util.AttributeKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static io.moquette.server.netty.NettyUtils.ATTR_USERNAME;
|
||||
|
||||
public class BytesMetricsHandler extends ChannelDuplexHandler {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(BytesMetricsHandler.class);
|
||||
private static final AttributeKey<BytesMetrics> ATTR_KEY_METRICS = AttributeKey.valueOf("BytesMetrics");
|
||||
private static final AttributeKey<String> ATTR_KEY_USERNAME = AttributeKey.valueOf(ATTR_USERNAME);
|
||||
|
||||
private BytesMetricsCollector m_collector;
|
||||
|
||||
@@ -59,6 +65,12 @@ public class BytesMetricsHandler extends ChannelDuplexHandler {
|
||||
@Override
|
||||
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
|
||||
BytesMetrics metrics = ctx.channel().attr(ATTR_KEY_METRICS).get();
|
||||
String userId = ctx.channel().attr(ATTR_KEY_USERNAME).get();
|
||||
if (userId == null) {
|
||||
userId = "";
|
||||
}
|
||||
|
||||
LOG.info("channel<{}> closing after read {} bytes and wrote {} bytes", userId, metrics.readBytes(), metrics.wroteBytes());
|
||||
m_collector.sumReadBytes(metrics.readBytes());
|
||||
m_collector.sumWroteBytes(metrics.wroteBytes());
|
||||
super.close(ctx, promise);
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2017 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package io.moquette.server.netty.metrics;
|
||||
|
||||
import com.codahale.metrics.Counter;
|
||||
import com.codahale.metrics.Meter;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.librato.metrics.reporter.Librato;
|
||||
import io.moquette.server.config.IConfig;
|
||||
import io.moquette.server.netty.NettyUtils;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.handler.codec.mqtt.MqttMessage;
|
||||
import io.netty.handler.codec.mqtt.MqttMessageType;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static io.moquette.BrokerConstants.*;
|
||||
import static io.netty.channel.ChannelHandler.Sharable;
|
||||
|
||||
/**
|
||||
* Pipeline handler use to track some MQTT metrics.
|
||||
*/
|
||||
@Sharable
|
||||
public final class DropWizardMetricsHandler extends ChannelInboundHandlerAdapter {
|
||||
private MetricRegistry metrics;
|
||||
private Meter publishesMetrics;
|
||||
private Meter subscribeMetrics;
|
||||
private Counter connectedClientsMetrics;
|
||||
|
||||
public void init(IConfig props) {
|
||||
this.metrics = new MetricRegistry();
|
||||
this.publishesMetrics = metrics.meter("publish.requests");
|
||||
this.subscribeMetrics = metrics.meter("subscribe.requests");
|
||||
this.connectedClientsMetrics = metrics.counter("connect.num_clients");
|
||||
// ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics)
|
||||
// .convertRatesTo(TimeUnit.SECONDS)
|
||||
// .convertDurationsTo(TimeUnit.MILLISECONDS)
|
||||
// .build();
|
||||
// reporter.start(1, TimeUnit.MINUTES);
|
||||
final String email = props.getProperty(METRICS_LIBRATO_EMAIL_PROPERTY_NAME);
|
||||
final String token = props.getProperty(METRICS_LIBRATO_TOKEN_PROPERTY_NAME);
|
||||
final String source = props.getProperty(METRICS_LIBRATO_SOURCE_PROPERTY_NAME);
|
||||
|
||||
Librato.reporter(this.metrics, email, token)
|
||||
.setSource(source)
|
||||
.start(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object message) {
|
||||
MqttMessage msg = (MqttMessage) message;
|
||||
MqttMessageType messageType = msg.fixedHeader().messageType();
|
||||
switch (messageType) {
|
||||
case PUBLISH:
|
||||
this.publishesMetrics.mark();
|
||||
break;
|
||||
case SUBSCRIBE:
|
||||
this.subscribeMetrics.mark();
|
||||
break;
|
||||
case CONNECT:
|
||||
this.connectedClientsMetrics.inc();
|
||||
break;
|
||||
case DISCONNECT:
|
||||
this.connectedClientsMetrics.dec();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ctx.fireChannelRead(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
String clientID = NettyUtils.clientID(ctx.channel());
|
||||
if (clientID != null && !clientID.isEmpty()) {
|
||||
this.connectedClientsMetrics.dec();
|
||||
}
|
||||
ctx.fireChannelInactive();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,10 +22,16 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import io.netty.util.Attribute;
|
||||
import io.netty.util.AttributeKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static io.moquette.server.netty.NettyUtils.ATTR_USERNAME;
|
||||
|
||||
public class MessageMetricsHandler extends ChannelDuplexHandler {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MessageMetricsHandler.class);
|
||||
private static final AttributeKey<MessageMetrics> ATTR_KEY_METRICS = AttributeKey.valueOf("MessageMetrics");
|
||||
private static final AttributeKey<String> ATTR_KEY_USERNAME = AttributeKey.valueOf(ATTR_USERNAME);
|
||||
|
||||
|
||||
private MessageMetricsCollector m_collector;
|
||||
|
||||
@@ -58,6 +64,12 @@ public class MessageMetricsHandler extends ChannelDuplexHandler {
|
||||
@Override
|
||||
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
|
||||
MessageMetrics metrics = ctx.channel().attr(ATTR_KEY_METRICS).get();
|
||||
String userId = ctx.channel().attr(ATTR_KEY_USERNAME).get();
|
||||
if (userId == null) {
|
||||
userId = "";
|
||||
}
|
||||
|
||||
LOG.info("channel<{}> closing after read {} messages and wrote {} messages", userId, metrics.messagesRead(), metrics.messagesWrote());
|
||||
m_collector.sumReadMessages(metrics.messagesRead());
|
||||
m_collector.sumWroteMessages(metrics.messagesWrote());
|
||||
super.close(ctx, promise);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.moquette.spi;
|
||||
|
||||
import cn.wildfirechat.pojos.SystemSettingPojo;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.xiaoleilu.loServer.model.FriendData;
|
||||
import cn.wildfirechat.pojos.InputOutputUserBlockStatus;
|
||||
@@ -104,20 +105,21 @@ public interface IMessagesStore {
|
||||
long insertUserMessages(String sender, int conversationType, String target, int line, int messageContentType, String userId, long messageId);
|
||||
WFCMessage.GroupInfo createGroup(String operator, WFCMessage.GroupInfo groupInfo, List<WFCMessage.GroupMember> memberList);
|
||||
ErrorCode addGroupMembers(String operator, boolean isAdmin, String groupId, List<WFCMessage.GroupMember> memberList);
|
||||
ErrorCode kickoffGroupMembers(String operator, String groupId, List<String> memberList);
|
||||
ErrorCode kickoffGroupMembers(String operator, boolean isAdmin, String groupId, List<String> memberList);
|
||||
ErrorCode quitGroup(String operator, String groupId);
|
||||
ErrorCode dismissGroup(String operator, String groupId, boolean isAdmin);
|
||||
ErrorCode modifyGroupInfo(String operator, String groupId, int modifyType, String value);
|
||||
ErrorCode modifyGroupInfo(String operator, String groupId, int modifyType, String value, boolean isAdmin);
|
||||
ErrorCode modifyGroupAlias(String operator, String groupId, String alias);
|
||||
List<WFCMessage.GroupInfo> getGroupInfos(List<WFCMessage.UserRequest> requests);
|
||||
WFCMessage.GroupInfo getGroupInfo(String groupId);
|
||||
ErrorCode getGroupMembers(String groupId, long maxDt, List<WFCMessage.GroupMember> members);
|
||||
WFCMessage.GroupMember getGroupMember(String groupId, String memberId);
|
||||
ErrorCode transferGroup(String operator, String groupId, String newOwner, boolean isAdmin);
|
||||
ErrorCode setGroupManager(String operator, String groupId, int type, List<String> userList, boolean isAdmin);
|
||||
boolean isMemberInGroup(String member, String groupId);
|
||||
ErrorCode canSendMessageInGroup(String member, String groupId);
|
||||
|
||||
ErrorCode recallMessage(long messageUid, String operatorId);
|
||||
ErrorCode recallMessage(long messageUid, String operatorId, boolean isAdmin);
|
||||
|
||||
WFCMessage.Robot getRobot(String robotId);
|
||||
void addRobot(WFCMessage.Robot robot);
|
||||
@@ -134,6 +136,8 @@ public interface IMessagesStore {
|
||||
WFCMessage.User getUserInfoByMobile(String mobile);
|
||||
List<WFCMessage.User> searchUser(String keyword, boolean buzzy, int page);
|
||||
|
||||
boolean updateSystemSetting(int id, String value, String desc);
|
||||
SystemSettingPojo getSystemSetting(int id);
|
||||
void createChatroom(String chatroomId, WFCMessage.ChatroomInfo chatroomInfo);
|
||||
void destoryChatroom(String chatroomId);
|
||||
WFCMessage.ChatroomInfo getChatroomInfo(String chatroomId);
|
||||
@@ -154,7 +158,7 @@ public interface IMessagesStore {
|
||||
|
||||
ErrorCode saveAddFriendRequest(String userId, WFCMessage.AddFriendRequest request, long[] head);
|
||||
ErrorCode handleFriendRequest(String userId, WFCMessage.HandleFriendRequest request, WFCMessage.Message.Builder msgBuilder, long[] heads, boolean isAdmin);
|
||||
ErrorCode deleteFriend(String userId, String friendUid);
|
||||
ErrorCode deleteFriend(String userId, String friendUid, long[] head);
|
||||
ErrorCode blackUserRequest(String fromUser, String targetUserId, int status, long[] head);
|
||||
ErrorCode SyncFriendRequestUnread(String userId, long unreadDt, long[] head);
|
||||
boolean isBlacked(String fromUser, String userId);
|
||||
|
||||
@@ -623,7 +623,8 @@ public class ProtocolProcessor {
|
||||
|
||||
public void onRpcMsg(String fromUser, String clientId, byte[] message, int messageId, String from, String request, boolean isAdmin) {
|
||||
if(request.equals(RPCCenter.KICKOFF_USER_REQUEST)) {
|
||||
mServer.getImBusinessScheduler().execute(()->handleTargetRemovedFromCurrentNode(new TargetEntry(TargetEntry.Type.TARGET_TYPE_USER, from)));
|
||||
String userId = new String(message);
|
||||
mServer.getImBusinessScheduler().execute(()->handleTargetRemovedFromCurrentNode(new TargetEntry(TargetEntry.Type.TARGET_TYPE_USER, userId)));
|
||||
return;
|
||||
}
|
||||
qos1PublishHandler.onRpcMsg(fromUser, clientId, message, messageId, from, request, isAdmin);
|
||||
|
||||
@@ -33,7 +33,7 @@ public class IDUtils {
|
||||
return ch - 'a' + 26;
|
||||
} else if(ch >= '0' && ch <= '9') {
|
||||
return ch - '0' + 52;
|
||||
} else if(ch == '_') {
|
||||
} else if(ch == '+') {
|
||||
return 62;
|
||||
}
|
||||
return 63;
|
||||
|
||||
@@ -10,6 +10,7 @@ package win.liyufan.im;
|
||||
|
||||
public interface IMTopic {
|
||||
String SendMessageTopic = "MS";
|
||||
String MultiCastMessageTopic = "MMC";
|
||||
String RecallMessageTopic = "MR";
|
||||
String PullMessageTopic = "MP";
|
||||
String NotifyMessageTopic = "MN";
|
||||
|
||||
@@ -54,10 +54,15 @@ public class MessageShardingUtil {
|
||||
return "t_messages";
|
||||
}
|
||||
|
||||
mid >>= (nodeIdWidth + rotateIdWidth);
|
||||
Date date = new Date(mid + T201801010000);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
if (mid != Long.MAX_VALUE) {
|
||||
mid >>= (nodeIdWidth + rotateIdWidth);
|
||||
Date date = new Date(mid + T201801010000);
|
||||
calendar.setTime(date);
|
||||
} else {
|
||||
Date date = new Date(System.currentTimeMillis());
|
||||
calendar.setTime(date);
|
||||
}
|
||||
int month = calendar.get(Calendar.MONTH);
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
year %= 3;
|
||||
|
||||
@@ -58,6 +58,7 @@ public class SensitiveFilter {
|
||||
return sensitiveWords;
|
||||
}
|
||||
|
||||
text = text.toLowerCase();
|
||||
for(int i=0;i<text.length();i++){
|
||||
int sensitiveWordLength = getSensitiveWordLength(text, i, matchType);
|
||||
if(sensitiveWordLength>0){
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
<!--MySQL数据库驱动程序-->
|
||||
<property name="driverClass">com.mysql.cj.jdbc.Driver</property>
|
||||
<!--MySQL数据库地址-->
|
||||
<property name="jdbcUrl">jdbc:mysql://localhost:3306/wfchat?useSSL=false&serverTimezone=GMT&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf8</property>
|
||||
<property name="jdbcUrl">jdbc:mysql://localhost:3306/wfchat?useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf8</property>
|
||||
<!--MySQL数据库用户名-->
|
||||
<property name="user">root</property>
|
||||
<!--MySQL数据库密码-->
|
||||
<property name="password">123456</property>
|
||||
<property name="password">lt123456</property>
|
||||
<!-- 初始化连接池中的连接数,取值应在minPoolSize与maxPoolSize之间,默认为3-->
|
||||
<property name="initialPoolSize">10</property>
|
||||
<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。默认值: 0 -->
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
<relativePath>../</relativePath>
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>0.23</version>
|
||||
<version>0.26</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>0.23</version>
|
||||
<version>0.26</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
public class InputCreateChannel {
|
||||
private String owner;
|
||||
private String name;
|
||||
private String targetId;
|
||||
private String callback;
|
||||
private String portrait;
|
||||
private int auto;
|
||||
private String secret;
|
||||
private String desc;
|
||||
private int status;
|
||||
private String extra;
|
||||
private long updateDt;
|
||||
|
||||
public WFCMessage.ChannelInfo toProtoChannelInfo() {
|
||||
WFCMessage.ChannelInfo.Builder builder = WFCMessage.ChannelInfo.newBuilder().setOwner(owner);
|
||||
if (!StringUtil.isNullOrEmpty(name))
|
||||
builder = builder.setName(name);
|
||||
if (!StringUtil.isNullOrEmpty(targetId))
|
||||
builder = builder.setTargetId(targetId);
|
||||
if (!StringUtil.isNullOrEmpty(callback))
|
||||
builder = builder.setCallback(callback);
|
||||
if (!StringUtil.isNullOrEmpty(portrait))
|
||||
builder = builder.setPortrait(portrait);
|
||||
builder = builder.setAutomatic(auto);
|
||||
if (!StringUtil.isNullOrEmpty(secret))
|
||||
builder = builder.setSecret(secret);
|
||||
if (!StringUtil.isNullOrEmpty(desc))
|
||||
builder = builder.setDesc(desc);
|
||||
builder = builder.setStatus(status);
|
||||
if (!StringUtil.isNullOrEmpty(extra))
|
||||
builder = builder.setExtra(extra);
|
||||
if (!StringUtil.isNullOrEmpty(name))
|
||||
builder = builder.setUpdateDt(updateDt);
|
||||
else
|
||||
builder = builder.setUpdateDt(System.currentTimeMillis());
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(String owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getTargetId() {
|
||||
return targetId;
|
||||
}
|
||||
|
||||
public void setTargetId(String targetId) {
|
||||
this.targetId = targetId;
|
||||
}
|
||||
|
||||
public String getCallback() {
|
||||
return callback;
|
||||
}
|
||||
|
||||
public void setCallback(String callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public String getPortrait() {
|
||||
return portrait;
|
||||
}
|
||||
|
||||
public void setPortrait(String portrait) {
|
||||
this.portrait = portrait;
|
||||
}
|
||||
|
||||
public int getAuto() {
|
||||
return auto;
|
||||
}
|
||||
|
||||
public void setAuto(int auto) {
|
||||
this.auto = auto;
|
||||
}
|
||||
|
||||
public String getSecret() {
|
||||
return secret;
|
||||
}
|
||||
|
||||
public void setSecret(String secret) {
|
||||
this.secret = secret;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getExtra() {
|
||||
return extra;
|
||||
}
|
||||
|
||||
public void setExtra(String extra) {
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
public long getUpdateDt() {
|
||||
return updateDt;
|
||||
}
|
||||
|
||||
public void setUpdateDt(long updateDt) {
|
||||
this.updateDt = updateDt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class InputModifyGroupInfo extends InputGroupBase {
|
||||
private String group_id;
|
||||
//ModifyGroupInfoType
|
||||
private int type;
|
||||
private String value;
|
||||
|
||||
public boolean isValide() {
|
||||
return !StringUtil.isNullOrEmpty(group_id);
|
||||
}
|
||||
public String getGroup_id() {
|
||||
return group_id;
|
||||
}
|
||||
|
||||
public void setGroup_id(String group_id) {
|
||||
this.group_id = group_id;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public WFCMessage.ModifyGroupInfoRequest toProtoGroupRequest() {
|
||||
return WFCMessage.ModifyGroupInfoRequest.newBuilder()
|
||||
.setGroupId(group_id)
|
||||
.setType(type)
|
||||
.setValue(value)
|
||||
.addAllToLine(to_lines == null || to_lines.isEmpty() ? Arrays.asList(0) : to_lines)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
public class MultiMessageResult {
|
||||
private long messageUid;
|
||||
private long timestamp;
|
||||
|
||||
public MultiMessageResult() {
|
||||
}
|
||||
|
||||
public MultiMessageResult(long messageUid, long timestamp) {
|
||||
this.messageUid = messageUid;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public long getMessageUid() {
|
||||
return messageUid;
|
||||
}
|
||||
|
||||
public void setMessageUid(long messageUid) {
|
||||
this.messageUid = messageUid;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MulticastMessageData {
|
||||
private String sender;
|
||||
private int line;
|
||||
private MessagePayload payload;
|
||||
private List<String> targets;
|
||||
|
||||
public String getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public void setSender(String sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public int getLine() {
|
||||
return line;
|
||||
}
|
||||
|
||||
public void setLine(int line) {
|
||||
this.line = line;
|
||||
}
|
||||
|
||||
public MessagePayload getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void setPayload(MessagePayload payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public static boolean isValide(MulticastMessageData sendMessageData) {
|
||||
if(sendMessageData == null ||
|
||||
StringUtil.isNullOrEmpty(sendMessageData.getSender()) ||
|
||||
sendMessageData.getPayload() == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public WFCMessage.MultiCastMessage toProtoMessage() {
|
||||
return WFCMessage.MultiCastMessage.newBuilder().setFromUser(sender)
|
||||
.setLine(line)
|
||||
.setContent(payload.toProtoMessageContent())
|
||||
.addAllTo(targets)
|
||||
.build();
|
||||
}
|
||||
|
||||
public List<String> getTargets() {
|
||||
return targets;
|
||||
}
|
||||
|
||||
public void setTargets(List<String> targets) {
|
||||
this.targets = targets;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
|
||||
public class OutputCreateChannel {
|
||||
private String targetId;
|
||||
|
||||
public OutputCreateChannel(String targetId) {
|
||||
this.targetId = targetId;
|
||||
}
|
||||
|
||||
public String getTargetId() {
|
||||
return targetId;
|
||||
}
|
||||
|
||||
public void setTargetId(String targetId) {
|
||||
this.targetId = targetId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
public class SystemSettingPojo {
|
||||
public int id;
|
||||
public String value;
|
||||
public String desc;
|
||||
}
|
||||
@@ -26,16 +26,23 @@ public interface APIPath {
|
||||
String Msg_Send = "/admin/message/send";
|
||||
String Msg_Recall = "/admin/message/recall";
|
||||
String Msg_Broadcast = "/admin/message/broadcast";
|
||||
String Msg_Multicast = "/admin/message/multicast";
|
||||
|
||||
String Create_Group = "/admin/group/create";
|
||||
String Group_Dismiss = "/admin/group/del";
|
||||
String Group_Transfer = "/admin/group/transfer";
|
||||
String Group_Get_Info = "/admin/group/get_info";
|
||||
String Group_Modify_Info = "/admin/group/modify";
|
||||
String Group_Member_List = "/admin/group/member/list";
|
||||
String Group_Member_Add = "/admin/group/member/add";
|
||||
String Group_Member_Kickoff = "/admin/group/member/del";
|
||||
|
||||
|
||||
String Create_Channel = "/admin/channel/create";
|
||||
String Get_System_Setting = "/admin/system/get_setting";
|
||||
String Put_System_Setting = "/admin/system/put_setting";
|
||||
|
||||
|
||||
String Channel_Message_Send = "/channel/message/send";
|
||||
|
||||
String Robot_User_Info = "/robot/user_info";
|
||||
|
||||
@@ -128,6 +128,9 @@ public class ProtoConstants {
|
||||
}
|
||||
|
||||
|
||||
public interface SystemSettingType {
|
||||
int Group_Max_Member_Count = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@
|
||||
<!--<relativePath>../pom.xml</relativePath>-->
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>0.23</version>
|
||||
<version>0.26</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>distribution</artifactId>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<!--MySQL数据库驱动程序-->
|
||||
<property name="driverClass">com.mysql.cj.jdbc.Driver</property>
|
||||
<!--MySQL数据库地址-->
|
||||
<property name="jdbcUrl">jdbc:mysql://localhost:3306/wfchat?useSSL=false&serverTimezone=GMT&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf8</property>
|
||||
<property name="jdbcUrl">jdbc:mysql://localhost:3306/wfchat?useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf8</property>
|
||||
<!--MySQL数据库用户名-->
|
||||
<property name="user">root</property>
|
||||
<!--MySQL数据库密码-->
|
||||
|
||||
@@ -26,7 +26,7 @@ host 0.0.0.0
|
||||
##本地绑定端口
|
||||
local_port 80
|
||||
|
||||
##是否使用内置DB。0使用mysql;1使用h2db
|
||||
##是否使用内置DB。0使用mysql;1使用h2db;2使用mysql+mongodb。社区版只支持0和1,专业版支持2
|
||||
embed.db 1
|
||||
|
||||
##服务器管理接口密钥
|
||||
@@ -42,6 +42,12 @@ client.proto.secret_key 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x78,0x79,0x7A,0
|
||||
##用来生产im token的私钥,只在服务器使用,客户端不用。正式使用时为了安全一定要修改这个值,切记切记
|
||||
token.key testim
|
||||
|
||||
##首次登录,是否接收之前的历史消息。0 不接收;1接收。
|
||||
message.roaming 0
|
||||
|
||||
##是否开启拉取远程历史消息
|
||||
message.remote_history_message 0
|
||||
|
||||
#*********************************************************************
|
||||
# hazelcase configuration
|
||||
#*********************************************************************
|
||||
@@ -96,6 +102,15 @@ push.android.server.address http://localhost:8085/android/push
|
||||
##苹果推送服务器地址
|
||||
push.ios.server.address http://localhost:8085/ios/push
|
||||
|
||||
#*********************************************************************
|
||||
# MongoDB configuration
|
||||
#*********************************************************************
|
||||
#专业版支持,社区版请忽略
|
||||
#mongodb.client_uri mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
|
||||
#mongodb.client_uri mongodb://host1:27017,host2:27017,host3:27017/wfchat?replicaSet=myReplicaSet
|
||||
mongodb.client_uri mongodb://wfc:123456@localhost:27017/wfchat
|
||||
mongodb.database wfchat
|
||||
mongodb.data_expire_days 1096
|
||||
|
||||
#*********************************************************************
|
||||
# Netty Configuration
|
||||
|
||||
@@ -17,9 +17,9 @@ goto end
|
||||
rem Set JavaHome if it exists
|
||||
if exist { "%JAVA_HOME%\bin\java" } (
|
||||
set "JAVA="%JAVA_HOME%\bin\java""
|
||||
) else {
|
||||
) else (
|
||||
set "JAVA="java""
|
||||
}
|
||||
)
|
||||
|
||||
echo Using JAVA_HOME: "%JAVA_HOME%"
|
||||
echo Using WILDFIRECHAT_HOME: "%WILDFIRECHAT_HOME%"
|
||||
|
||||
@@ -70,7 +70,7 @@ JAVA_OPTS="$JAVA_OPTS -XX:MaxGCPauseMillis=500"
|
||||
### GC logging options -- uncomment to enable
|
||||
|
||||
JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails"
|
||||
JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDateStamps"
|
||||
#JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDateStamps"
|
||||
JAVA_OPTS="$JAVA_OPTS -XX:+PrintHeapAtGC"
|
||||
JAVA_OPTS="$JAVA_OPTS -XX:+PrintTenuringDistribution"
|
||||
JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCApplicationStoppedTime"
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
<version>0.23</version>
|
||||
<version>0.26</version>
|
||||
<name>Wildfire Chat</name>
|
||||
<description>Wildfire Chat Server</description>
|
||||
<inceptionYear>2019</inceptionYear>
|
||||
@@ -30,7 +30,6 @@
|
||||
</licenses>
|
||||
|
||||
|
||||
|
||||
<modules>
|
||||
<module>broker</module>
|
||||
<module>wildfire_jmeter</module>
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
## Run follow command by sequence:
|
||||
To build protobuf from source, the following tools are needed:
|
||||
|
||||
|
||||
On Ubuntu, you can install them with:
|
||||
$ sudo apt-get install autoconf automake libtool curl make g++ unzip
|
||||
|
||||
On Mac, you can install them with:
|
||||
$ brew install autoconf automake libtool
|
||||
|
||||
|
||||
Then run the cmd.
|
||||
$ ./autogen.sh
|
||||
$ ./configure
|
||||
$ make
|
||||
$ make check
|
||||
$ sudo make install
|
||||
$ sudo ldconfig # refresh shared library cache.
|
||||
|
||||
|
||||
|
||||
## Javascript 生成方法
|
||||
1. 安装nodejs
|
||||
2. 安装protobufjs
|
||||
```
|
||||
sudo npm install protobufjs@5 -g
|
||||
```
|
||||
3. 生成JS
|
||||
```
|
||||
pbjs -t static-module -w commonjs -o protocol.js wfcmessage.proto
|
||||
```
|
||||
|
||||
> [参考1](http://dcode.io/protobuf.js/#pbjs-for-javascript)
|
||||
|
||||
> [参考2](https://blog.csdn.net/yyf1990cs/article/details/78942157)
|
||||
@@ -1,528 +0,0 @@
|
||||
2013-02-27 version 2.5.0:
|
||||
|
||||
General
|
||||
* New notion "import public" that allows a proto file to forward the content
|
||||
it imports to its importers. For example,
|
||||
// foo.proto
|
||||
import public "bar.proto";
|
||||
import "baz.proto";
|
||||
|
||||
// qux.proto
|
||||
import "foo.proto";
|
||||
// Stuff defined in bar.proto may be used in this file, but stuff from
|
||||
// baz.proto may NOT be used without importing it explicitly.
|
||||
This is useful for moving proto files. To move a proto file, just leave
|
||||
a single "import public" in the old proto file.
|
||||
* New enum option "allow_alias" that specifies whether different symbols can
|
||||
be assigned the same numeric value. Default value is "true". Setting it to
|
||||
false causes the compiler to reject enum definitions where multiple symbols
|
||||
have the same numeric value.
|
||||
|
||||
C++
|
||||
* New generated method set_allocated_foo(Type* foo) for message and string
|
||||
fields. This method allows you to set the field to a pre-allocated object
|
||||
and the containing message takes the ownership of that object.
|
||||
* Added SetAllocatedExtension() and ReleaseExtension() to extensions API.
|
||||
* Custom options are now formatted correctly when descriptors are printed in
|
||||
text format.
|
||||
* Various speed optimizations.
|
||||
|
||||
Java
|
||||
* Comments in proto files are now collected and put into generated code as
|
||||
comments for corresponding classes and data members.
|
||||
* Added Parser to parse directly into messages without a Builder. For
|
||||
example,
|
||||
Foo foo = Foo.getParser().ParseFrom(input);
|
||||
Using Parser is ~25% faster than using Builder to parse messages.
|
||||
* Added getters/setters to access the underlying ByteString of a string field
|
||||
directly.
|
||||
* ByteString now supports more operations: substring(), prepend(), and
|
||||
append(). The implementation of ByteString uses a binary tree structure
|
||||
to support these operations efficiently.
|
||||
* New method findInitializationErrors() that lists all missing required
|
||||
fields.
|
||||
* Various code size and speed optimizations.
|
||||
|
||||
Python
|
||||
* Added support for dynamic message creation. DescriptorDatabase,
|
||||
DescriptorPool, and MessageFactory work like their C++ couterparts to
|
||||
simplify Descriptor construction from *DescriptorProtos, and MessageFactory
|
||||
provides a message instance from a Descriptor.
|
||||
* Added pickle support for protobuf messages.
|
||||
* Unknown fields are now preserved after parsing.
|
||||
* Fixed bug where custom options were not correctly populated. Custom
|
||||
options can be accessed now.
|
||||
* Added EnumTypeWrapper that provides better accessibility to enum types.
|
||||
* Added ParseMessage(descriptor, bytes) to generate a new Message instance
|
||||
from a descriptor and a byte string.
|
||||
|
||||
2011-05-01 version 2.4.1:
|
||||
|
||||
C++
|
||||
* Fixed the frendship problem for old compilers to make the library now gcc 3
|
||||
compatible again.
|
||||
* Fixed vcprojects/extract_includes.bat to extract compiler/plugin.h.
|
||||
|
||||
Java
|
||||
* Removed usages of JDK 1.6 only features to make the library now JDK 1.5
|
||||
compatible again.
|
||||
* Fixed a bug about negative enum values.
|
||||
* serialVersionUID is now defined in generated messages for java serializing.
|
||||
* Fixed protoc to use java.lang.Object, which makes "Object" now a valid
|
||||
message name again.
|
||||
|
||||
Python
|
||||
* Experimental C++ implementation now requires C++ protobuf library installed.
|
||||
See the README.txt in the python directory for details.
|
||||
|
||||
2011-02-02 version 2.4.0:
|
||||
|
||||
General
|
||||
* The RPC (cc|java|py)_generic_services default value is now false instead of
|
||||
true.
|
||||
* Custom options can have aggregate types. For example,
|
||||
message MyOption {
|
||||
optional string comment = 1;
|
||||
optional string author = 2;
|
||||
}
|
||||
extend google.protobuf.FieldOptions {
|
||||
optional MyOption myoption = 12345;
|
||||
}
|
||||
This option can now be set as follows:
|
||||
message SomeType {
|
||||
optional int32 field = 1 [(myoption) = { comment:'x' author:'y' }];
|
||||
}
|
||||
|
||||
C++
|
||||
* Various speed and code size optimizations.
|
||||
* Added a release_foo() method on string and message fields.
|
||||
* Fixed gzip_output_stream sub-stream handling.
|
||||
|
||||
Java
|
||||
* Builders now maintain sub-builders for sub-messages. Use getFooBuilder() to
|
||||
get the builder for the sub-message "foo". This allows you to repeatedly
|
||||
modify deeply-nested sub-messages without rebuilding them.
|
||||
* Builder.build() no longer invalidates the Builder for generated messages
|
||||
(You may continue to modify it and then build another message).
|
||||
* Code generator will generate efficient equals() and hashCode()
|
||||
implementations if new option java_generate_equals_and_hash is enabled.
|
||||
(Otherwise, reflection-based implementations are used.)
|
||||
* Generated messages now implement Serializable.
|
||||
* Fields with [deprecated=true] will be marked with @Deprecated in Java.
|
||||
* Added lazy conversion of UTF-8 encoded strings to String objects to improve
|
||||
performance.
|
||||
* Various optimizations.
|
||||
* Enum value can be accessed directly, instead of calling getNumber() on the
|
||||
enum member.
|
||||
* For each enum value, an integer constant is also generated with the suffix
|
||||
_VALUE.
|
||||
|
||||
Python
|
||||
* Added an experimental C++ implementation for Python messages via a Python
|
||||
extension. Implementation type is controlled by an environment variable
|
||||
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION (valid values: "cpp" and "python")
|
||||
The default value is currently "python" but will be changed to "cpp" in
|
||||
future release.
|
||||
* Improved performance on message instantiation significantly.
|
||||
Most of the work on message instantiation is done just once per message
|
||||
class, instead of once per message instance.
|
||||
* Improved performance on text message parsing.
|
||||
* Allow add() to forward keyword arguments to the concrete class.
|
||||
E.g. instead of
|
||||
item = repeated_field.add()
|
||||
item.foo = bar
|
||||
item.baz = quux
|
||||
You can do:
|
||||
repeated_field.add(foo=bar, baz=quux)
|
||||
* Added a sort() interface to the BaseContainer.
|
||||
* Added an extend() method to repeated composite fields.
|
||||
* Added UTF8 debug string support.
|
||||
|
||||
2010-01-08 version 2.3.0:
|
||||
|
||||
General
|
||||
* Parsers for repeated numeric fields now always accept both packed and
|
||||
unpacked input. The [packed=true] option only affects serializers.
|
||||
Therefore, it is possible to switch a field to packed format without
|
||||
breaking backwards-compatibility -- as long as all parties are using
|
||||
protobuf 2.3.0 or above, at least.
|
||||
* The generic RPC service code generated by the C++, Java, and Python
|
||||
generators can be disabled via file options:
|
||||
option cc_generic_services = false;
|
||||
option java_generic_services = false;
|
||||
option py_generic_services = false;
|
||||
This allows plugins to generate alternative code, possibly specific to some
|
||||
particular RPC implementation.
|
||||
|
||||
protoc
|
||||
* Now supports a plugin system for code generators. Plugins can generate
|
||||
code for new languages or inject additional code into the output of other
|
||||
code generators. Plugins are just binaries which accept a protocol buffer
|
||||
on stdin and write a protocol buffer to stdout, so they may be written in
|
||||
any language. See src/google/protobuf/compiler/plugin.proto.
|
||||
**WARNING**: Plugins are experimental. The interface may change in a
|
||||
future version.
|
||||
* If the output location ends in .zip or .jar, protoc will write its output
|
||||
to a zip/jar archive instead of a directory. For example:
|
||||
protoc --java_out=myproto_srcs.jar --python_out=myproto.zip myproto.proto
|
||||
Currently the archive contents are not compressed, though this could change
|
||||
in the future.
|
||||
* inf, -inf, and nan can now be used as default values for float and double
|
||||
fields.
|
||||
|
||||
C++
|
||||
* Various speed and code size optimizations.
|
||||
* DynamicMessageFactory is now fully thread-safe.
|
||||
* Message::Utf8DebugString() method is like DebugString() but avoids escaping
|
||||
UTF-8 bytes.
|
||||
* Compiled-in message types can now contain dynamic extensions, through use
|
||||
of CodedInputStream::SetExtensionRegistry().
|
||||
* Now compiles shared libraries (DLLs) by default on Cygwin and MinGW, to
|
||||
match other platforms. Use --disable-shared to avoid this.
|
||||
|
||||
Java
|
||||
* parseDelimitedFrom() and mergeDelimitedFrom() now detect EOF and return
|
||||
false/null instead of throwing an exception.
|
||||
* Fixed some initialization ordering bugs.
|
||||
* Fixes for OpenJDK 7.
|
||||
|
||||
Python
|
||||
* 10-25 times faster than 2.2.0, still pure-Python.
|
||||
* Calling a mutating method on a sub-message always instantiates the message
|
||||
in its parent even if the mutating method doesn't actually mutate anything
|
||||
(e.g. parsing from an empty string).
|
||||
* Expanded descriptors a bit.
|
||||
|
||||
2009-08-11 version 2.2.0:
|
||||
|
||||
C++
|
||||
* Lite mode: The "optimize_for = LITE_RUNTIME" option causes the compiler
|
||||
to generate code which only depends libprotobuf-lite, which is much smaller
|
||||
than libprotobuf but lacks descriptors, reflection, and some other features.
|
||||
* Fixed bug where Message.Swap(Message) was only implemented for
|
||||
optimize_for_speed. Swap now properly implemented in both modes
|
||||
(Issue 91).
|
||||
* Added RemoveLast and SwapElements(index1, index2) to Reflection
|
||||
interface for repeated elements.
|
||||
* Added Swap(Message) to Reflection interface.
|
||||
* Floating-point literals in generated code that are intended to be
|
||||
single-precision now explicitly have 'f' suffix to avoid pedantic warnings
|
||||
produced by some compilers.
|
||||
* The [deprecated=true] option now causes the C++ code generator to generate
|
||||
a GCC-style deprecation annotation (no-op on other compilers).
|
||||
* google::protobuf::GetEnumDescriptor<SomeGeneratedEnumType>() returns the
|
||||
EnumDescriptor for that type -- useful for templates which cannot call
|
||||
SomeGeneratedEnumType_descriptor().
|
||||
* Various optimizations and obscure bug fixes.
|
||||
|
||||
Java
|
||||
* Lite mode: The "optimize_for = LITE_RUNTIME" option causes the compiler
|
||||
to generate code which only depends libprotobuf-lite, which is much smaller
|
||||
than libprotobuf but lacks descriptors, reflection, and some other features.
|
||||
* Lots of style cleanups.
|
||||
|
||||
Python
|
||||
* Fixed endianness bug with floats and doubles.
|
||||
* Text format parsing support.
|
||||
* Fix bug with parsing packed repeated fields in embedded messages.
|
||||
* Ability to initialize fields by passing keyword args to constructor.
|
||||
* Support iterators in extend and __setslice__ for containers.
|
||||
|
||||
2009-05-13 version 2.1.0:
|
||||
|
||||
General
|
||||
* Repeated fields of primitive types (types other that string, group, and
|
||||
nested messages) may now use the option [packed = true] to get a more
|
||||
efficient encoding. In the new encoding, the entire list is written
|
||||
as a single byte blob using the "length-delimited" wire type. Within
|
||||
this blob, the individual values are encoded the same way they would
|
||||
be normally except without a tag before each value (thus, they are
|
||||
tightly "packed").
|
||||
* For each field, the generated code contains an integer constant assigned
|
||||
to the field number. For example, the .proto file:
|
||||
message Foo { optional int bar_baz = 123; }
|
||||
would generate the following constants, all with the integer value 123:
|
||||
C++: Foo::kBarBazFieldNumber
|
||||
Java: Foo.BAR_BAZ_FIELD_NUMBER
|
||||
Python: Foo.BAR_BAZ_FIELD_NUMBER
|
||||
Constants are also generated for extensions, with the same naming scheme.
|
||||
These constants may be used as switch cases.
|
||||
* Updated bundled Google Test to version 1.3.0. Google Test is now bundled
|
||||
in its verbatim form as a nested autoconf package, so you can drop in any
|
||||
other version of Google Test if needed.
|
||||
* optimize_for = SPEED is now the default, by popular demand. Use
|
||||
optimize_for = CODE_SIZE if code size is more important in your app.
|
||||
* It is now an error to define a default value for a repeated field.
|
||||
Previously, this was silently ignored (it had no effect on the generated
|
||||
code).
|
||||
* Fields can now be marked deprecated like:
|
||||
optional int32 foo = 1 [deprecated = true];
|
||||
Currently this does not have any actual effect, but in the future the code
|
||||
generators may generate deprecation annotations in each language.
|
||||
* Cross-compiling should now be possible using the --with-protoc option to
|
||||
configure. See README.txt for more info.
|
||||
|
||||
protoc
|
||||
* --error_format=msvs option causes errors to be printed in Visual Studio
|
||||
format, which should allow them to be clicked on in the build log to go
|
||||
directly to the error location.
|
||||
* The type name resolver will no longer resolve type names to fields. For
|
||||
example, this now works:
|
||||
message Foo {}
|
||||
message Bar {
|
||||
optional int32 Foo = 1;
|
||||
optional Foo baz = 2;
|
||||
}
|
||||
Previously, the type of "baz" would resolve to "Bar.Foo", and you'd get
|
||||
an error because Bar.Foo is a field, not a type. Now the type of "baz"
|
||||
resolves to the message type Foo. This change is unlikely to make a
|
||||
difference to anyone who follows the Protocol Buffers style guide.
|
||||
|
||||
C++
|
||||
* Several optimizations, including but not limited to:
|
||||
- Serialization, especially to flat arrays, is 10%-50% faster, possibly
|
||||
more for small objects.
|
||||
- Several descriptor operations which previously required locking no longer
|
||||
do.
|
||||
- Descriptors are now constructed lazily on first use, rather than at
|
||||
process startup time. This should save memory in programs which do not
|
||||
use descriptors or reflection.
|
||||
- UnknownFieldSet completely redesigned to be more efficient (especially in
|
||||
terms of memory usage).
|
||||
- Various optimizations to reduce code size (though the serialization speed
|
||||
optimizations increased code size).
|
||||
* Message interface has method ParseFromBoundedZeroCopyStream() which parses
|
||||
a limited number of bytes from an input stream rather than parsing until
|
||||
EOF.
|
||||
* GzipInputStream and GzipOutputStream support reading/writing gzip- or
|
||||
zlib-compressed streams if zlib is available.
|
||||
(google/protobuf/io/gzip_stream.h)
|
||||
* DescriptorPool::FindAllExtensions() and corresponding
|
||||
DescriptorDatabase::FindAllExtensions() can be used to enumerate all
|
||||
extensions of a given type.
|
||||
* For each enum type Foo, protoc will generate functions:
|
||||
const string& Foo_Name(Foo value);
|
||||
bool Foo_Parse(const string& name, Foo* result);
|
||||
The former returns the name of the enum constant corresponding to the given
|
||||
value while the latter finds the value corresponding to a name.
|
||||
* RepeatedField and RepeatedPtrField now have back-insertion iterators.
|
||||
* String fields now have setters that take a char* and a size, in addition
|
||||
to the existing ones that took char* or const string&.
|
||||
* DescriptorPool::AllowUnknownDependencies() may be used to tell
|
||||
DescriptorPool to create placeholder descriptors for unknown entities
|
||||
referenced in a FileDescriptorProto. This can allow you to parse a .proto
|
||||
file without having access to other .proto files that it imports, for
|
||||
example.
|
||||
* Updated gtest to latest version. The gtest package is now included as a
|
||||
nested autoconf package, so it should be able to drop new versions into the
|
||||
"gtest" subdirectory without modification.
|
||||
|
||||
Java
|
||||
* Fixed bug where Message.mergeFrom(Message) failed to merge extensions.
|
||||
* Message interface has new method toBuilder() which is equivalent to
|
||||
newBuilderForType().mergeFrom(this).
|
||||
* All enums now implement the ProtocolMessageEnum interface.
|
||||
* Setting a field to null now throws NullPointerException.
|
||||
* Fixed tendency for TextFormat's parsing to overflow the stack when
|
||||
parsing large string values. The underlying problem is with Java's
|
||||
regex implementation (which unfortunately uses recursive backtracking
|
||||
rather than building an NFA). Worked around by making use of possesive
|
||||
quantifiers.
|
||||
* Generated service classes now also generate pure interfaces. For a service
|
||||
Foo, Foo.Interface is a pure interface containing all of the service's
|
||||
defined methods. Foo.newReflectiveService() can be called to wrap an
|
||||
instance of this interface in a class that implements the generic
|
||||
RpcService interface, which provides reflection support that is usually
|
||||
needed by RPC server implementations.
|
||||
* RPC interfaces now support blocking operation in addition to non-blocking.
|
||||
The protocol compiler generates separate blocking and non-blocking stubs
|
||||
which operate against separate blocking and non-blocking RPC interfaces.
|
||||
RPC implementations will have to implement the new interfaces in order to
|
||||
support blocking mode.
|
||||
* New I/O methods parseDelimitedFrom(), mergeDelimitedFrom(), and
|
||||
writeDelimitedTo() read and write "delemited" messages from/to a stream,
|
||||
meaning that the message size precedes the data. This way, you can write
|
||||
multiple messages to a stream without having to worry about delimiting
|
||||
them yourself.
|
||||
* Throw a more descriptive exception when build() is double-called.
|
||||
* Add a method to query whether CodedInputStream is at the end of the input
|
||||
stream.
|
||||
* Add a method to reset a CodedInputStream's size counter; useful when
|
||||
reading many messages with the same stream.
|
||||
* equals() and hashCode() now account for unknown fields.
|
||||
|
||||
Python
|
||||
* Added slicing support for repeated scalar fields. Added slice retrieval and
|
||||
removal of repeated composite fields.
|
||||
* Updated RPC interfaces to allow for blocking operation. A client may
|
||||
now pass None for a callback when making an RPC, in which case the
|
||||
call will block until the response is received, and the response
|
||||
object will be returned directly to the caller. This interface change
|
||||
cannot be used in practice until RPC implementations are updated to
|
||||
implement it.
|
||||
* Changes to input_stream.py should make protobuf compatible with appengine.
|
||||
|
||||
2008-11-25 version 2.0.3:
|
||||
|
||||
protoc
|
||||
* Enum values may now have custom options, using syntax similar to field
|
||||
options.
|
||||
* Fixed bug where .proto files which use custom options but don't actually
|
||||
define them (i.e. they import another .proto file defining the options)
|
||||
had to explicitly import descriptor.proto.
|
||||
* Adjacent string literals in .proto files will now be concatenated, like in
|
||||
C.
|
||||
* If an input file is a Windows absolute path (e.g. "C:\foo\bar.proto") and
|
||||
the import path only contains "." (or contains "." but does not contain
|
||||
the file), protoc incorrectly thought that the file was under ".", because
|
||||
it thought that the path was relative (since it didn't start with a slash).
|
||||
This has been fixed.
|
||||
|
||||
C++
|
||||
* Generated message classes now have a Swap() method which efficiently swaps
|
||||
the contents of two objects.
|
||||
* All message classes now have a SpaceUsed() method which returns an estimate
|
||||
of the number of bytes of allocated memory currently owned by the object.
|
||||
This is particularly useful when you are reusing a single message object
|
||||
to improve performance but want to make sure it doesn't bloat up too large.
|
||||
* New method Message::SerializeAsString() returns a string containing the
|
||||
serialized data. May be more convenient than calling
|
||||
SerializeToString(string*).
|
||||
* In debug mode, log error messages when string-type fields are found to
|
||||
contain bytes that are not valid UTF-8.
|
||||
* Fixed bug where a message with multiple extension ranges couldn't parse
|
||||
extensions.
|
||||
* Fixed bug where MergeFrom(const Message&) didn't do anything if invoked on
|
||||
a message that contained no fields (but possibly contained extensions).
|
||||
* Fixed ShortDebugString() to not be O(n^2). Durr.
|
||||
* Fixed crash in TextFormat parsing if the first token in the input caused a
|
||||
tokenization error.
|
||||
* Fixed obscure bugs in zero_copy_stream_impl.cc.
|
||||
* Added support for HP C++ on Tru64.
|
||||
* Only build tests on "make check", not "make".
|
||||
* Fixed alignment issue that caused crashes when using DynamicMessage on
|
||||
64-bit Sparc machines.
|
||||
* Simplify template usage to work with MSVC 2003.
|
||||
* Work around GCC 4.3.x x86_64 compiler bug that caused crashes on startup.
|
||||
(This affected Fedora 9 in particular.)
|
||||
* Now works on "Solaris 10 using recent Sun Studio".
|
||||
|
||||
Java
|
||||
* New overload of mergeFrom() which parses a slice of a byte array instead
|
||||
of the whole thing.
|
||||
* New method ByteString.asReadOnlyByteBuffer() does what it sounds like.
|
||||
* Improved performance of isInitialized() when optimizing for code size.
|
||||
|
||||
Python
|
||||
* Corrected ListFields() signature in Message base class to match what
|
||||
subclasses actually implement.
|
||||
* Some minor refactoring.
|
||||
* Don't pass self as first argument to superclass constructor (no longer
|
||||
allowed in Python 2.6).
|
||||
|
||||
2008-09-29 version 2.0.2:
|
||||
|
||||
General
|
||||
* License changed from Apache 2.0 to New BSD.
|
||||
* It is now possible to define custom "options", which are basically
|
||||
annotations which may be placed on definitions in a .proto file.
|
||||
For example, you might define a field option called "foo" like so:
|
||||
import "google/protobuf/descriptor.proto"
|
||||
extend google.protobuf.FieldOptions {
|
||||
optional string foo = 12345;
|
||||
}
|
||||
Then you annotate a field using the "foo" option:
|
||||
message MyMessage {
|
||||
optional int32 some_field = 1 [(foo) = "bar"]
|
||||
}
|
||||
The value of this option is then visible via the message's
|
||||
Descriptor:
|
||||
const FieldDescriptor* field =
|
||||
MyMessage::descriptor()->FindFieldByName("some_field");
|
||||
assert(field->options().GetExtension(foo) == "bar");
|
||||
This feature has been implemented and tested in C++ and Java.
|
||||
Other languages may or may not need to do extra work to support
|
||||
custom options, depending on how they construct descriptors.
|
||||
|
||||
C++
|
||||
* Fixed some GCC warnings that only occur when using -pedantic.
|
||||
* Improved static initialization code, making ordering more
|
||||
predictable among other things.
|
||||
* TextFormat will no longer accept messages which contain multiple
|
||||
instances of a singular field. Previously, the latter instance
|
||||
would overwrite the former.
|
||||
* Now works on systems that don't have hash_map.
|
||||
|
||||
Java
|
||||
* Print @Override annotation in generated code where appropriate.
|
||||
|
||||
Python
|
||||
* Strings now use the "unicode" type rather than the "str" type.
|
||||
String fields may still be assigned ASCII "str" values; they will
|
||||
automatically be converted.
|
||||
* Adding a property to an object representing a repeated field now
|
||||
raises an exception. For example:
|
||||
# No longer works (and never should have).
|
||||
message.some_repeated_field.foo = 1
|
||||
|
||||
Windows
|
||||
* We now build static libraries rather than DLLs by default on MSVC.
|
||||
See vsprojects/readme.txt for more information.
|
||||
|
||||
2008-08-15 version 2.0.1:
|
||||
|
||||
protoc
|
||||
* New flags --encode and --decode can be used to convert between protobuf text
|
||||
format and binary format from the command-line.
|
||||
* New flag --descriptor_set_out can be used to write FileDescriptorProtos for
|
||||
all parsed files directly into a single output file. This is particularly
|
||||
useful if you wish to parse .proto files from programs written in languages
|
||||
other than C++: just run protoc as a background process and have it output
|
||||
a FileDescriptorList, then parse that natively.
|
||||
* Improved error message when an enum value's name conflicts with another
|
||||
symbol defined in the enum type's scope, e.g. if two enum types declared
|
||||
in the same scope have values with the same name. This is disallowed for
|
||||
compatibility with C++, but this wasn't clear from the error.
|
||||
* Fixed absolute output paths on Windows.
|
||||
* Allow trailing slashes in --proto_path mappings.
|
||||
|
||||
C++
|
||||
* Reflection objects are now per-class rather than per-instance. To make this
|
||||
possible, the Reflection interface had to be changed such that all methods
|
||||
take the Message instance as a parameter. This change improves performance
|
||||
significantly in memory-bandwidth-limited use cases, since it makes the
|
||||
message objects smaller. Note that source-incompatible interface changes
|
||||
like this will not be made again after the library leaves beta.
|
||||
* Heuristically detect sub-messages when printing unknown fields.
|
||||
* Fix static initialization ordering bug that caused crashes at startup when
|
||||
compiling on Mac with static linking.
|
||||
* Fixed TokenizerTest when compiling with -DNDEBUG on Linux.
|
||||
* Fixed incorrect definition of kint32min.
|
||||
* Fix bytes type setter to work with byte sequences with embedded NULLs.
|
||||
* Other irrelevant tweaks.
|
||||
|
||||
Java
|
||||
* Fixed UnknownFieldSet's parsing of varints larger than 32 bits.
|
||||
* Fixed TextFormat's parsing of "inf" and "nan".
|
||||
* Fixed TextFormat's parsing of comments.
|
||||
* Added info to Java POM that will be required when we upload the
|
||||
package to a Maven repo.
|
||||
|
||||
Python
|
||||
* MergeFrom(message) and CopyFrom(message) are now implemented.
|
||||
* SerializeToString() raises an exception if the message is missing required
|
||||
fields.
|
||||
* Code organization improvements.
|
||||
* Fixed doc comments for RpcController and RpcChannel, which had somehow been
|
||||
swapped.
|
||||
* Fixed text_format_test on Windows where floating-point exponents sometimes
|
||||
contain extra zeros.
|
||||
* Fix Python service CallMethod() implementation.
|
||||
|
||||
Other
|
||||
* Improved readmes.
|
||||
* VIM syntax highlighting improvements.
|
||||
|
||||
2008-07-07 version 2.0.0:
|
||||
|
||||
* First public release.
|
||||
@@ -1,90 +0,0 @@
|
||||
This file contains a list of people who have made large contributions
|
||||
to the public version of Protocol Buffers.
|
||||
|
||||
Original Protocol Buffers design and implementation:
|
||||
Sanjay Ghemawat <[email protected]>
|
||||
Jeff Dean <[email protected]>
|
||||
Daniel Dulitz <[email protected]>
|
||||
Craig Silverstein
|
||||
Paul Haahr <[email protected]>
|
||||
Corey Anderson <[email protected]>
|
||||
(and many others)
|
||||
|
||||
Proto2 C++ and Java primary author:
|
||||
Kenton Varda <[email protected]>
|
||||
|
||||
Proto2 Python primary authors:
|
||||
Will Robinson <[email protected]>
|
||||
Petar Petrov <[email protected]>
|
||||
|
||||
Large code contributions:
|
||||
Jason Hsueh <[email protected]>
|
||||
Joseph Schorr <[email protected]>
|
||||
Wenbo Zhu <[email protected]>
|
||||
|
||||
Large quantity of code reviews:
|
||||
Scott Bruce <[email protected]>
|
||||
Frank Yellin
|
||||
Neal Norwitz <[email protected]>
|
||||
Jeffrey Yasskin <[email protected]>
|
||||
Ambrose Feinstein <[email protected]>
|
||||
|
||||
Documentation:
|
||||
Lisa Carey <[email protected]>
|
||||
|
||||
Maven packaging:
|
||||
Gregory Kick <[email protected]>
|
||||
|
||||
Patch contributors:
|
||||
Kevin Ko <[email protected]>
|
||||
* Small patch to handle trailing slashes in --proto_path flag.
|
||||
Johan Euphrosine <[email protected]>
|
||||
* Small patch to fix Python CallMethod().
|
||||
Ulrich Kunitz <[email protected]>
|
||||
* Small optimizations to Python serialization.
|
||||
Leandro Lucarella <[email protected]>
|
||||
* VI syntax highlighting tweaks.
|
||||
* Fix compiler to not make output executable.
|
||||
Dilip Joseph <[email protected]>
|
||||
* Heuristic detection of sub-messages when printing unknown fields in
|
||||
text format.
|
||||
Brian Atkinson <[email protected]>
|
||||
* Added @Override annotation to generated Java code where appropriate.
|
||||
Vincent Choinière <[email protected]>
|
||||
* Tru64 support.
|
||||
Monty Taylor <[email protected]>
|
||||
* Solaris 10 + Sun Studio fixes.
|
||||
Alek Storm <[email protected]>
|
||||
* Slicing support for repeated scalar fields for the Python API.
|
||||
Oleg Smolsky <[email protected]>
|
||||
* MS Visual Studio error format option.
|
||||
* Detect unordered_map in stl_hash.m4.
|
||||
Brian Olson <[email protected]>
|
||||
* gzip/zlib I/O support.
|
||||
Michael Poole <[email protected]>
|
||||
* Fixed warnings about generated constructors not explicitly initializing
|
||||
all fields (only present with certain compiler settings).
|
||||
* Added generation of field number constants.
|
||||
Wink Saville <[email protected]>
|
||||
* Fixed initialization ordering problem in logging code.
|
||||
Will Pierce <[email protected]>
|
||||
* Small patch improving performance of in Python serialization.
|
||||
Alexandre Vassalotti <[email protected]>
|
||||
* Emacs mode for Protocol Buffers (editors/protobuf-mode.el).
|
||||
Scott Stafford <[email protected]>
|
||||
* Added Swap(), SwapElements(), and RemoveLast() to Reflection interface.
|
||||
Alexander Melnikov <[email protected]>
|
||||
* HPUX support.
|
||||
Oliver Jowett <[email protected]>
|
||||
* Detect whether zlib is new enough in configure script.
|
||||
* Fixes for Solaris 10 32/64-bit confusion.
|
||||
Evan Jones <[email protected]>
|
||||
* Optimize Java serialization code when writing a small message to a stream.
|
||||
* Optimize Java serialization of strings so that UTF-8 encoding happens only
|
||||
once per string per serialization call.
|
||||
* Clean up some Java warnings.
|
||||
* Fix bug with permanent callbacks that delete themselves when run.
|
||||
Michael Kucharski <[email protected]>
|
||||
* Added CodedInputStream.getTotalBytesRead().
|
||||
Kacper Kowalik <[email protected]>
|
||||
* Fixed m4/acx_pthread.m4 problem for some Linux distributions.
|
||||
@@ -1,33 +0,0 @@
|
||||
Copyright 2008, Google Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Code generated by the Protocol Buffer compiler is owned by the owner
|
||||
of the input file used when generating it. This code is not
|
||||
standalone and requires a support library to be linked with it. This
|
||||
support library is itself covered by the above license.
|
||||
@@ -1,237 +0,0 @@
|
||||
This file contains detailed but generic information on building and
|
||||
installing the C++ part of this project. For shorter instructions,
|
||||
as well as instructions for compiling and installing the Java or
|
||||
Python parts, see README.
|
||||
|
||||
======================================================================
|
||||
|
||||
Copyright 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is free documentation; the Free Software Foundation gives
|
||||
unlimited permission to copy, distribute and modify it.
|
||||
|
||||
|
||||
Basic Installation
|
||||
==================
|
||||
|
||||
These are generic installation instructions.
|
||||
|
||||
The `configure' shell script attempts to guess correct values for
|
||||
various system-dependent variables used during compilation. It uses
|
||||
those values to create a `Makefile' in each directory of the package.
|
||||
It may also create one or more `.h' files containing system-dependent
|
||||
definitions. Finally, it creates a shell script `config.status' that
|
||||
you can run in the future to recreate the current configuration, and a
|
||||
file `config.log' containing compiler output (useful mainly for
|
||||
debugging `configure').
|
||||
|
||||
It can also use an optional file (typically called `config.cache'
|
||||
and enabled with `--cache-file=config.cache' or simply `-C') that saves
|
||||
the results of its tests to speed up reconfiguring. (Caching is
|
||||
disabled by default to prevent problems with accidental use of stale
|
||||
cache files.)
|
||||
|
||||
If you need to do unusual things to compile the package, please try
|
||||
to figure out how `configure' could check whether to do them, and mail
|
||||
diffs or instructions to the address given in the `README' so they can
|
||||
be considered for the next release. If you are using the cache, and at
|
||||
some point `config.cache' contains results you don't want to keep, you
|
||||
may remove or edit it.
|
||||
|
||||
The file `configure.ac' (or `configure.in') is used to create
|
||||
`configure' by a program called `autoconf'. You only need
|
||||
`configure.ac' if you want to change it or regenerate `configure' using
|
||||
a newer version of `autoconf'.
|
||||
|
||||
The simplest way to compile this package is:
|
||||
|
||||
1. `cd' to the directory containing the package's source code and type
|
||||
`./configure' to configure the package for your system. If you're
|
||||
using `csh' on an old version of System V, you might need to type
|
||||
`sh ./configure' instead to prevent `csh' from trying to execute
|
||||
`configure' itself.
|
||||
|
||||
Running `configure' takes awhile. While running, it prints some
|
||||
messages telling which features it is checking for.
|
||||
|
||||
2. Type `make' to compile the package.
|
||||
|
||||
3. Optionally, type `make check' to run any self-tests that come with
|
||||
the package.
|
||||
|
||||
4. Type `make install' to install the programs and any data files and
|
||||
documentation.
|
||||
|
||||
5. You can remove the program binaries and object files from the
|
||||
source code directory by typing `make clean'. To also remove the
|
||||
files that `configure' created (so you can compile the package for
|
||||
a different kind of computer), type `make distclean'. There is
|
||||
also a `make maintainer-clean' target, but that is intended mainly
|
||||
for the package's developers. If you use it, you may have to get
|
||||
all sorts of other programs in order to regenerate files that came
|
||||
with the distribution.
|
||||
|
||||
Compilers and Options
|
||||
=====================
|
||||
|
||||
Some systems require unusual options for compilation or linking that
|
||||
the `configure' script does not know about. Run `./configure --help'
|
||||
for details on some of the pertinent environment variables.
|
||||
|
||||
You can give `configure' initial values for configuration parameters
|
||||
by setting variables in the command line or in the environment. Here
|
||||
is an example:
|
||||
|
||||
./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
|
||||
|
||||
*Note Defining Variables::, for more details.
|
||||
|
||||
Compiling For Multiple Architectures
|
||||
====================================
|
||||
|
||||
You can compile the package for more than one kind of computer at the
|
||||
same time, by placing the object files for each architecture in their
|
||||
own directory. To do this, you must use a version of `make' that
|
||||
supports the `VPATH' variable, such as GNU `make'. `cd' to the
|
||||
directory where you want the object files and executables to go and run
|
||||
the `configure' script. `configure' automatically checks for the
|
||||
source code in the directory that `configure' is in and in `..'.
|
||||
|
||||
If you have to use a `make' that does not support the `VPATH'
|
||||
variable, you have to compile the package for one architecture at a
|
||||
time in the source code directory. After you have installed the
|
||||
package for one architecture, use `make distclean' before reconfiguring
|
||||
for another architecture.
|
||||
|
||||
Installation Names
|
||||
==================
|
||||
|
||||
By default, `make install' will install the package's files in
|
||||
`/usr/local/bin', `/usr/local/man', etc. You can specify an
|
||||
installation prefix other than `/usr/local' by giving `configure' the
|
||||
option `--prefix=PATH'.
|
||||
|
||||
You can specify separate installation prefixes for
|
||||
architecture-specific files and architecture-independent files. If you
|
||||
give `configure' the option `--exec-prefix=PATH', the package will use
|
||||
PATH as the prefix for installing programs and libraries.
|
||||
Documentation and other data files will still use the regular prefix.
|
||||
|
||||
In addition, if you use an unusual directory layout you can give
|
||||
options like `--bindir=PATH' to specify different values for particular
|
||||
kinds of files. Run `configure --help' for a list of the directories
|
||||
you can set and what kinds of files go in them.
|
||||
|
||||
If the package supports it, you can cause programs to be installed
|
||||
with an extra prefix or suffix on their names by giving `configure' the
|
||||
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
|
||||
|
||||
Optional Features
|
||||
=================
|
||||
|
||||
Some packages pay attention to `--enable-FEATURE' options to
|
||||
`configure', where FEATURE indicates an optional part of the package.
|
||||
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
|
||||
is something like `gnu-as' or `x' (for the X Window System). The
|
||||
`README' should mention any `--enable-' and `--with-' options that the
|
||||
package recognizes.
|
||||
|
||||
For packages that use the X Window System, `configure' can usually
|
||||
find the X include and library files automatically, but if it doesn't,
|
||||
you can use the `configure' options `--x-includes=DIR' and
|
||||
`--x-libraries=DIR' to specify their locations.
|
||||
|
||||
Specifying the System Type
|
||||
==========================
|
||||
|
||||
There may be some features `configure' cannot figure out
|
||||
automatically, but needs to determine by the type of machine the package
|
||||
will run on. Usually, assuming the package is built to be run on the
|
||||
_same_ architectures, `configure' can figure that out, but if it prints
|
||||
a message saying it cannot guess the machine type, give it the
|
||||
`--build=TYPE' option. TYPE can either be a short name for the system
|
||||
type, such as `sun4', or a canonical name which has the form:
|
||||
|
||||
CPU-COMPANY-SYSTEM
|
||||
|
||||
where SYSTEM can have one of these forms:
|
||||
|
||||
OS KERNEL-OS
|
||||
|
||||
See the file `config.sub' for the possible values of each field. If
|
||||
`config.sub' isn't included in this package, then this package doesn't
|
||||
need to know the machine type.
|
||||
|
||||
If you are _building_ compiler tools for cross-compiling, you should
|
||||
use the `--target=TYPE' option to select the type of system they will
|
||||
produce code for.
|
||||
|
||||
If you want to _use_ a cross compiler, that generates code for a
|
||||
platform different from the build platform, you should specify the
|
||||
"host" platform (i.e., that on which the generated programs will
|
||||
eventually be run) with `--host=TYPE'.
|
||||
|
||||
Sharing Defaults
|
||||
================
|
||||
|
||||
If you want to set default values for `configure' scripts to share,
|
||||
you can create a site shell script called `config.site' that gives
|
||||
default values for variables like `CC', `cache_file', and `prefix'.
|
||||
`configure' looks for `PREFIX/share/config.site' if it exists, then
|
||||
`PREFIX/etc/config.site' if it exists. Or, you can set the
|
||||
`CONFIG_SITE' environment variable to the location of the site script.
|
||||
A warning: not all `configure' scripts look for a site script.
|
||||
|
||||
Defining Variables
|
||||
==================
|
||||
|
||||
Variables not defined in a site shell script can be set in the
|
||||
environment passed to `configure'. However, some packages may run
|
||||
configure again during the build, and the customized values of these
|
||||
variables may be lost. In order to avoid this problem, you should set
|
||||
them in the `configure' command line, using `VAR=value'. For example:
|
||||
|
||||
./configure CC=/usr/local2/bin/gcc
|
||||
|
||||
will cause the specified gcc to be used as the C compiler (unless it is
|
||||
overridden in the site shell script).
|
||||
|
||||
`configure' Invocation
|
||||
======================
|
||||
|
||||
`configure' recognizes the following options to control how it
|
||||
operates.
|
||||
|
||||
`--help'
|
||||
`-h'
|
||||
Print a summary of the options to `configure', and exit.
|
||||
|
||||
`--version'
|
||||
`-V'
|
||||
Print the version of Autoconf used to generate the `configure'
|
||||
script, and exit.
|
||||
|
||||
`--cache-file=FILE'
|
||||
Enable the cache: use and save the results of the tests in FILE,
|
||||
traditionally `config.cache'. FILE defaults to `/dev/null' to
|
||||
disable caching.
|
||||
|
||||
`--config-cache'
|
||||
`-C'
|
||||
Alias for `--cache-file=config.cache'.
|
||||
|
||||
`--quiet'
|
||||
`--silent'
|
||||
`-q'
|
||||
Do not print messages saying which checks are being made. To
|
||||
suppress all normal output, redirect it to `/dev/null' (any error
|
||||
messages will still be shown).
|
||||
|
||||
`--srcdir=DIR'
|
||||
Look for the package's source code in directory DIR. Usually
|
||||
`configure' can determine that directory automatically.
|
||||
|
||||
`configure' also accepts some other, not widely useful, options. Run
|
||||
`configure --help' for more details.
|
||||
|
||||
@@ -1,225 +0,0 @@
|
||||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
AUTOMAKE_OPTIONS = foreign
|
||||
|
||||
# Build . before src so that our all-local and clean-local hooks kicks in at
|
||||
# the right time.
|
||||
SUBDIRS = . src
|
||||
|
||||
# Always include gtest in distributions.
|
||||
DIST_SUBDIRS = $(subdirs) src
|
||||
|
||||
# Build gtest before we build protobuf tests. We don't add gtest to SUBDIRS
|
||||
# because then "make check" would also build and run all of gtest's own tests,
|
||||
# which takes a lot of time and is generally not useful to us. Also, we don't
|
||||
# want "make install" to recurse into gtest since we don't want to overwrite
|
||||
# the installed version of gtest if there is one.
|
||||
check-local:
|
||||
@echo "Making lib/libgtest.a lib/libgtest_main.a in gtest"
|
||||
@cd gtest && $(MAKE) $(AM_MAKEFLAGS) lib/libgtest.la lib/libgtest_main.la
|
||||
|
||||
# We would like to clean gtest when "make clean" is invoked. But we have to
|
||||
# be careful because clean-local is also invoked during "make distclean", but
|
||||
# "make distclean" already recurses into gtest because it's listed among the
|
||||
# DIST_SUBDIRS. distclean will delete gtest/Makefile, so if we then try to
|
||||
# cd to the directory again and "make clean" it will fail. So, check that the
|
||||
# Makefile exists before recursing.
|
||||
clean-local:
|
||||
@if test -e gtest/Makefile; then \
|
||||
echo "Making clean in gtest"; \
|
||||
cd gtest && $(MAKE) $(AM_MAKEFLAGS) clean; \
|
||||
fi
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = protobuf.pc protobuf-lite.pc
|
||||
|
||||
EXTRA_DIST = \
|
||||
autogen.sh \
|
||||
generate_descriptor_proto.sh \
|
||||
README.txt \
|
||||
INSTALL.txt \
|
||||
COPYING.txt \
|
||||
CONTRIBUTORS.txt \
|
||||
CHANGES.txt \
|
||||
editors/README.txt \
|
||||
editors/proto.vim \
|
||||
editors/protobuf-mode.el \
|
||||
vsprojects/config.h \
|
||||
vsprojects/extract_includes.bat \
|
||||
vsprojects/libprotobuf.vcproj \
|
||||
vsprojects/libprotobuf-lite.vcproj \
|
||||
vsprojects/libprotoc.vcproj \
|
||||
vsprojects/protobuf.sln \
|
||||
vsprojects/protoc.vcproj \
|
||||
vsprojects/readme.txt \
|
||||
vsprojects/test_plugin.vcproj \
|
||||
vsprojects/tests.vcproj \
|
||||
vsprojects/lite-test.vcproj \
|
||||
vsprojects/convert2008to2005.sh \
|
||||
examples/README.txt \
|
||||
examples/Makefile \
|
||||
examples/addressbook.proto \
|
||||
examples/add_person.cc \
|
||||
examples/list_people.cc \
|
||||
examples/AddPerson.java \
|
||||
examples/ListPeople.java \
|
||||
examples/add_person.py \
|
||||
examples/list_people.py \
|
||||
java/src/main/java/com/google/protobuf/AbstractMessage.java \
|
||||
java/src/main/java/com/google/protobuf/AbstractMessageLite.java \
|
||||
java/src/main/java/com/google/protobuf/AbstractParser.java \
|
||||
java/src/main/java/com/google/protobuf/BlockingRpcChannel.java \
|
||||
java/src/main/java/com/google/protobuf/BlockingService.java \
|
||||
java/src/main/java/com/google/protobuf/BoundedByteString.java \
|
||||
java/src/main/java/com/google/protobuf/ByteString.java \
|
||||
java/src/main/java/com/google/protobuf/CodedInputStream.java \
|
||||
java/src/main/java/com/google/protobuf/CodedOutputStream.java \
|
||||
java/src/main/java/com/google/protobuf/Descriptors.java \
|
||||
java/src/main/java/com/google/protobuf/DynamicMessage.java \
|
||||
java/src/main/java/com/google/protobuf/ExtensionRegistry.java \
|
||||
java/src/main/java/com/google/protobuf/ExtensionRegistryLite.java \
|
||||
java/src/main/java/com/google/protobuf/FieldSet.java \
|
||||
java/src/main/java/com/google/protobuf/GeneratedMessage.java \
|
||||
java/src/main/java/com/google/protobuf/GeneratedMessageLite.java \
|
||||
java/src/main/java/com/google/protobuf/Internal.java \
|
||||
java/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java \
|
||||
java/src/main/java/com/google/protobuf/LazyField.java \
|
||||
java/src/main/java/com/google/protobuf/LazyStringArrayList.java \
|
||||
java/src/main/java/com/google/protobuf/LazyStringList.java \
|
||||
java/src/main/java/com/google/protobuf/LiteralByteString.java \
|
||||
java/src/main/java/com/google/protobuf/Message.java \
|
||||
java/src/main/java/com/google/protobuf/MessageLite.java \
|
||||
java/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java \
|
||||
java/src/main/java/com/google/protobuf/MessageOrBuilder.java \
|
||||
java/src/main/java/com/google/protobuf/Parser.java \
|
||||
java/src/main/java/com/google/protobuf/ProtocolMessageEnum.java \
|
||||
java/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java \
|
||||
java/src/main/java/com/google/protobuf/RopeByteString.java \
|
||||
java/src/main/java/com/google/protobuf/RpcCallback.java \
|
||||
java/src/main/java/com/google/protobuf/RpcChannel.java \
|
||||
java/src/main/java/com/google/protobuf/RpcController.java \
|
||||
java/src/main/java/com/google/protobuf/RpcUtil.java \
|
||||
java/src/main/java/com/google/protobuf/ServiceException.java \
|
||||
java/src/main/java/com/google/protobuf/Service.java \
|
||||
java/src/main/java/com/google/protobuf/SingleFieldBuilder.java \
|
||||
java/src/main/java/com/google/protobuf/SmallSortedMap.java \
|
||||
java/src/main/java/com/google/protobuf/TextFormat.java \
|
||||
java/src/main/java/com/google/protobuf/UninitializedMessageException.java \
|
||||
java/src/main/java/com/google/protobuf/UnknownFieldSet.java \
|
||||
java/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java \
|
||||
java/src/main/java/com/google/protobuf/Utf8.java \
|
||||
java/src/main/java/com/google/protobuf/WireFormat.java \
|
||||
java/src/test/java/com/google/protobuf/AbstractMessageTest.java \
|
||||
java/src/test/java/com/google/protobuf/BoundedByteStringTest.java \
|
||||
java/src/test/java/com/google/protobuf/ByteStringTest.java \
|
||||
java/src/test/java/com/google/protobuf/CodedInputStreamTest.java \
|
||||
java/src/test/java/com/google/protobuf/CodedOutputStreamTest.java \
|
||||
java/src/test/java/com/google/protobuf/DeprecatedFieldTest.java \
|
||||
java/src/test/java/com/google/protobuf/DescriptorsTest.java \
|
||||
java/src/test/java/com/google/protobuf/DynamicMessageTest.java \
|
||||
java/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java \
|
||||
java/src/test/java/com/google/protobuf/GeneratedMessageTest.java \
|
||||
java/src/test/java/com/google/protobuf/IsValidUtf8Test.java \
|
||||
java/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java \
|
||||
java/src/test/java/com/google/protobuf/LazyStringArrayListTest.java \
|
||||
java/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java \
|
||||
java/src/test/java/com/google/protobuf/LiteralByteStringTest.java \
|
||||
java/src/test/java/com/google/protobuf/LiteTest.java \
|
||||
java/src/test/java/com/google/protobuf/MessageTest.java \
|
||||
java/src/test/java/com/google/protobuf/NestedBuildersTest.java \
|
||||
java/src/test/java/com/google/protobuf/ParserTest.java \
|
||||
java/src/test/java/com/google/protobuf/RepeatedFieldBuilderTest.java \
|
||||
java/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java \
|
||||
java/src/test/java/com/google/protobuf/RopeByteStringTest.java \
|
||||
java/src/test/java/com/google/protobuf/ServiceTest.java \
|
||||
java/src/test/java/com/google/protobuf/SingleFieldBuilderTest.java \
|
||||
java/src/test/java/com/google/protobuf/SmallSortedMapTest.java \
|
||||
java/src/test/java/com/google/protobuf/TestBadIdentifiers.java \
|
||||
java/src/test/java/com/google/protobuf/TestUtil.java \
|
||||
java/src/test/java/com/google/protobuf/TextFormatTest.java \
|
||||
java/src/test/java/com/google/protobuf/UnknownFieldSetTest.java \
|
||||
java/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java \
|
||||
java/src/test/java/com/google/protobuf/WireFormatTest.java \
|
||||
java/src/test/java/com/google/protobuf/multiple_files_test.proto \
|
||||
java/src/test/java/com/google/protobuf/nested_builders_test.proto \
|
||||
java/src/test/java/com/google/protobuf/nested_extension_lite.proto \
|
||||
java/src/test/java/com/google/protobuf/nested_extension.proto \
|
||||
java/src/test/java/com/google/protobuf/non_nested_extension_lite.proto \
|
||||
java/src/test/java/com/google/protobuf/non_nested_extension.proto \
|
||||
java/src/test/java/com/google/protobuf/test_bad_identifiers.proto \
|
||||
java/pom.xml \
|
||||
java/README.txt \
|
||||
python/google/protobuf/internal/generator_test.py \
|
||||
python/google/protobuf/internal/containers.py \
|
||||
python/google/protobuf/internal/decoder.py \
|
||||
python/google/protobuf/internal/descriptor_database_test.py \
|
||||
python/google/protobuf/internal/descriptor_pool_test.py \
|
||||
python/google/protobuf/internal/descriptor_test.py \
|
||||
python/google/protobuf/internal/encoder.py \
|
||||
python/google/protobuf/internal/enum_type_wrapper.py \
|
||||
python/google/protobuf/internal/factory_test1.proto \
|
||||
python/google/protobuf/internal/factory_test2.proto \
|
||||
python/google/protobuf/internal/message_cpp_test.py \
|
||||
python/google/protobuf/internal/message_factory_test.py \
|
||||
python/google/protobuf/internal/message_listener.py \
|
||||
python/google/protobuf/internal/message_test.py \
|
||||
python/google/protobuf/internal/more_extensions.proto \
|
||||
python/google/protobuf/internal/more_extensions_dynamic.proto \
|
||||
python/google/protobuf/internal/more_messages.proto \
|
||||
python/google/protobuf/internal/python_message.py \
|
||||
python/google/protobuf/internal/cpp_message.py \
|
||||
python/google/protobuf/internal/api_implementation.py \
|
||||
python/google/protobuf/internal/reflection_test.py \
|
||||
python/google/protobuf/internal/reflection_cpp_generated_test.py \
|
||||
python/google/protobuf/internal/service_reflection_test.py \
|
||||
python/google/protobuf/internal/test_bad_identifiers.proto \
|
||||
python/google/protobuf/internal/test_util.py \
|
||||
python/google/protobuf/internal/text_format_test.py \
|
||||
python/google/protobuf/internal/type_checkers.py \
|
||||
python/google/protobuf/internal/unknown_fields_test.py \
|
||||
python/google/protobuf/internal/wire_format.py \
|
||||
python/google/protobuf/internal/wire_format_test.py \
|
||||
python/google/protobuf/internal/__init__.py \
|
||||
python/google/protobuf/pyext/python-proto2.cc \
|
||||
python/google/protobuf/pyext/python_descriptor.cc \
|
||||
python/google/protobuf/pyext/python_descriptor.h \
|
||||
python/google/protobuf/pyext/python_protobuf.cc \
|
||||
python/google/protobuf/pyext/python_protobuf.h \
|
||||
python/google/protobuf/descriptor.py \
|
||||
python/google/protobuf/descriptor_database.py \
|
||||
python/google/protobuf/descriptor_pool.py \
|
||||
python/google/protobuf/message.py \
|
||||
python/google/protobuf/message_factory.py \
|
||||
python/google/protobuf/reflection.py \
|
||||
python/google/protobuf/service.py \
|
||||
python/google/protobuf/service_reflection.py \
|
||||
python/google/protobuf/text_format.py \
|
||||
python/google/protobuf/__init__.py \
|
||||
python/google/__init__.py \
|
||||
python/ez_setup.py \
|
||||
python/setup.py \
|
||||
python/mox.py \
|
||||
python/stubout.py \
|
||||
python/README.txt
|
||||
|
||||
# Deletes all the files generated by autogen.sh.
|
||||
MAINTAINERCLEANFILES = \
|
||||
aclocal.m4 \
|
||||
config.guess \
|
||||
config.sub \
|
||||
configure \
|
||||
depcomp \
|
||||
install-sh \
|
||||
ltmain.sh \
|
||||
Makefile.in \
|
||||
missing \
|
||||
mkinstalldirs \
|
||||
config.h.in \
|
||||
stamp.h.in \
|
||||
m4/ltsugar.m4 \
|
||||
m4/libtool.m4 \
|
||||
m4/ltversion.m4 \
|
||||
m4/lt~obsolete.m4 \
|
||||
m4/ltoptions.m4
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,152 +0,0 @@
|
||||
Protocol Buffers - Google's data interchange format
|
||||
Copyright 2008 Google Inc.
|
||||
http://code.google.com/apis/protocolbuffers/
|
||||
|
||||
C++ Installation - Unix
|
||||
=======================
|
||||
|
||||
To build and install the C++ Protocol Buffer runtime and the Protocol
|
||||
Buffer compiler (protoc) execute the following:
|
||||
|
||||
$ ./configure
|
||||
$ make
|
||||
$ make check
|
||||
$ make install
|
||||
|
||||
If "make check" fails, you can still install, but it is likely that
|
||||
some features of this library will not work correctly on your system.
|
||||
Proceed at your own risk.
|
||||
|
||||
"make install" may require superuser privileges.
|
||||
|
||||
For advanced usage information on configure and make, see INSTALL.txt.
|
||||
|
||||
** Hint on install location **
|
||||
|
||||
By default, the package will be installed to /usr/local. However,
|
||||
on many platforms, /usr/local/lib is not part of LD_LIBRARY_PATH.
|
||||
You can add it, but it may be easier to just install to /usr
|
||||
instead. To do this, invoke configure as follows:
|
||||
|
||||
./configure --prefix=/usr
|
||||
|
||||
If you already built the package with a different prefix, make sure
|
||||
to run "make clean" before building again.
|
||||
|
||||
** Compiling dependent packages **
|
||||
|
||||
To compile a package that uses Protocol Buffers, you need to pass
|
||||
various flags to your compiler and linker. As of version 2.2.0,
|
||||
Protocol Buffers integrates with pkg-config to manage this. If you
|
||||
have pkg-config installed, then you can invoke it to get a list of
|
||||
flags like so:
|
||||
|
||||
pkg-config --cflags protobuf # print compiler flags
|
||||
pkg-config --libs protobuf # print linker flags
|
||||
pkg-config --cflags --libs protobuf # print both
|
||||
|
||||
For example:
|
||||
|
||||
c++ my_program.cc my_proto.pb.cc `pkg-config --cflags --libs protobuf`
|
||||
|
||||
Note that packages written prior to the 2.2.0 release of Protocol
|
||||
Buffers may not yet integrate with pkg-config to get flags, and may
|
||||
not pass the correct set of flags to correctly link against
|
||||
libprotobuf. If the package in question uses autoconf, you can
|
||||
often fix the problem by invoking its configure script like:
|
||||
|
||||
configure CXXFLAGS="$(pkg-config --cflags protobuf)" \
|
||||
LIBS="$(pkg-config --libs protobuf)"
|
||||
|
||||
This will force it to use the correct flags.
|
||||
|
||||
If you are writing an autoconf-based package that uses Protocol
|
||||
Buffers, you should probably use the PKG_CHECK_MODULES macro in your
|
||||
configure script like:
|
||||
|
||||
PKG_CHECK_MODULES([protobuf], [protobuf])
|
||||
|
||||
See the pkg-config man page for more info.
|
||||
|
||||
If you only want protobuf-lite, substitute "protobuf-lite" in place
|
||||
of "protobuf" in these examples.
|
||||
|
||||
** Note for cross-compiling **
|
||||
|
||||
The makefiles normally invoke the protoc executable that they just
|
||||
built in order to build tests. When cross-compiling, the protoc
|
||||
executable may not be executable on the host machine. In this case,
|
||||
you must build a copy of protoc for the host machine first, then use
|
||||
the --with-protoc option to tell configure to use it instead. For
|
||||
example:
|
||||
|
||||
./configure --with-protoc=protoc
|
||||
|
||||
This will use the installed protoc (found in your $PATH) instead of
|
||||
trying to execute the one built during the build process. You can
|
||||
also use an executable that hasn't been installed. For example, if
|
||||
you built the protobuf package for your host machine in ../host,
|
||||
you might do:
|
||||
|
||||
./configure --with-protoc=../host/src/protoc
|
||||
|
||||
Either way, you must make sure that the protoc executable you use
|
||||
has the same version as the protobuf source code you are trying to
|
||||
use it with.
|
||||
|
||||
** Note for Solaris users **
|
||||
|
||||
Solaris 10 x86 has a bug that will make linking fail, complaining
|
||||
about libstdc++.la being invalid. We have included a work-around
|
||||
in this package. To use the work-around, run configure as follows:
|
||||
|
||||
./configure LDFLAGS=-L$PWD/src/solaris
|
||||
|
||||
See src/solaris/libstdc++.la for more info on this bug.
|
||||
|
||||
** Note for HP C++ Tru64 users **
|
||||
|
||||
To compile invoke configure as follows:
|
||||
|
||||
./configure CXXFLAGS="-O -std ansi -ieee -D__USE_STD_IOSTREAM"
|
||||
|
||||
Also, you will need to use gmake instead of make.
|
||||
|
||||
C++ Installation - Windows
|
||||
==========================
|
||||
|
||||
If you are using Microsoft Visual C++, see vsprojects/readme.txt.
|
||||
|
||||
If you are using Cygwin or MinGW, follow the Unix installation
|
||||
instructions, above.
|
||||
|
||||
Binary Compatibility Warning
|
||||
============================
|
||||
|
||||
Due to the nature of C++, it is unlikely that any two versions of the
|
||||
Protocol Buffers C++ runtime libraries will have compatible ABIs.
|
||||
That is, if you linked an executable against an older version of
|
||||
libprotobuf, it is unlikely to work with a newer version without
|
||||
re-compiling. This problem, when it occurs, will normally be detected
|
||||
immediately on startup of your app. Still, you may want to consider
|
||||
using static linkage. You can configure this package to install
|
||||
static libraries only using:
|
||||
|
||||
./configure --disable-shared
|
||||
|
||||
Java and Python Installation
|
||||
============================
|
||||
|
||||
The Java and Python runtime libraries for Protocol Buffers are located
|
||||
in the java and python directories. See the README file in each
|
||||
directory for more information on how to compile and install them.
|
||||
Note that both of them require you to first install the Protocol
|
||||
Buffer compiler (protoc), which is part of the C++ package.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
The complete documentation for Protocol Buffers is available via the
|
||||
web at:
|
||||
|
||||
http://code.google.com/apis/protocolbuffers/
|
||||
Vendored
-1020
File diff suppressed because it is too large
Load Diff
@@ -1,41 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Run this script to generate the configure script and other files that will
|
||||
# be included in the distribution. These files are not checked in because they
|
||||
# are automatically generated.
|
||||
|
||||
set -e
|
||||
|
||||
# Check that we're being run from the right directory.
|
||||
if test ! -f src/google/protobuf/stubs/common.h; then
|
||||
cat >&2 << __EOF__
|
||||
Could not find source code. Make sure you are running this script from the
|
||||
root of the distribution tree.
|
||||
__EOF__
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check that gtest is present. Usually it is already there since the
|
||||
# directory is set up as an SVN external.
|
||||
if test ! -e gtest; then
|
||||
echo "Google Test not present. Fetching gtest-1.5.0 from the web..."
|
||||
curl http://googletest.googlecode.com/files/gtest-1.5.0.tar.bz2 | tar jx
|
||||
mv gtest-1.5.0 gtest
|
||||
fi
|
||||
|
||||
set -ex
|
||||
|
||||
# Temporary hack: Must change C runtime library to "multi-threaded DLL",
|
||||
# otherwise it will be set to "multi-threaded static" when MSVC upgrades
|
||||
# the project file to MSVC 2005/2008. vladl of Google Test says gtest will
|
||||
# probably change their default to match, then this will be unnecessary.
|
||||
# One of these mappings converts the debug configuration and the other
|
||||
# converts the release configuration. I don't know which is which.
|
||||
sed -i -e 's/RuntimeLibrary="5"/RuntimeLibrary="3"/g;
|
||||
s/RuntimeLibrary="4"/RuntimeLibrary="2"/g;' gtest/msvc/*.vcproj
|
||||
|
||||
# TODO(kenton): Remove the ",no-obsolete" part and fix the resulting warnings.
|
||||
autoreconf -f -i -Wall,no-obsolete
|
||||
|
||||
rm -rf autom4te.cache config.h.in~
|
||||
exit 0
|
||||
Vendored
-1530
File diff suppressed because it is too large
Load Diff
@@ -1,149 +0,0 @@
|
||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* the name of <hash_map> */
|
||||
#undef HASH_MAP_CLASS
|
||||
|
||||
/* the location of <unordered_map> or <hash_map> */
|
||||
#undef HASH_MAP_H
|
||||
|
||||
/* the namespace of hash_map/hash_set */
|
||||
#undef HASH_NAMESPACE
|
||||
|
||||
/* the name of <hash_set> */
|
||||
#undef HASH_SET_CLASS
|
||||
|
||||
/* the location of <unordered_set> or <hash_set> */
|
||||
#undef HASH_SET_H
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#undef HAVE_DLFCN_H
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#undef HAVE_FCNTL_H
|
||||
|
||||
/* Define to 1 if you have the `ftruncate' function. */
|
||||
#undef HAVE_FTRUNCATE
|
||||
|
||||
/* define if the compiler has hash_map */
|
||||
#undef HAVE_HASH_MAP
|
||||
|
||||
/* define if the compiler has hash_set */
|
||||
#undef HAVE_HASH_SET
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#undef HAVE_LIMITS_H
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#undef HAVE_MEMSET
|
||||
|
||||
/* Define to 1 if you have the `mkdir' function. */
|
||||
#undef HAVE_MKDIR
|
||||
|
||||
/* Define if you have POSIX threads libraries and header files. */
|
||||
#undef HAVE_PTHREAD
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the `strchr' function. */
|
||||
#undef HAVE_STRCHR
|
||||
|
||||
/* Define to 1 if you have the `strerror' function. */
|
||||
#undef HAVE_STRERROR
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the `strtol' function. */
|
||||
#undef HAVE_STRTOL
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Enable classes using zlib compression. */
|
||||
#undef HAVE_ZLIB
|
||||
|
||||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
||||
*/
|
||||
#undef LT_OBJDIR
|
||||
|
||||
/* Name of package */
|
||||
#undef PACKAGE
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#undef PACKAGE_URL
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Define to necessary symbol if this constant uses a non-standard name on
|
||||
your system. */
|
||||
#undef PTHREAD_CREATE_JOINABLE
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Enable extensions on AIX 3, Interix. */
|
||||
#ifndef _ALL_SOURCE
|
||||
# undef _ALL_SOURCE
|
||||
#endif
|
||||
/* Enable GNU extensions on systems that have them. */
|
||||
#ifndef _GNU_SOURCE
|
||||
# undef _GNU_SOURCE
|
||||
#endif
|
||||
/* Enable threading extensions on Solaris. */
|
||||
#ifndef _POSIX_PTHREAD_SEMANTICS
|
||||
# undef _POSIX_PTHREAD_SEMANTICS
|
||||
#endif
|
||||
/* Enable extensions on HP NonStop. */
|
||||
#ifndef _TANDEM_SOURCE
|
||||
# undef _TANDEM_SOURCE
|
||||
#endif
|
||||
/* Enable general extensions on Solaris. */
|
||||
#ifndef __EXTENSIONS__
|
||||
# undef __EXTENSIONS__
|
||||
#endif
|
||||
|
||||
|
||||
/* Version number of package */
|
||||
#undef VERSION
|
||||
|
||||
/* Define to 1 if on MINIX. */
|
||||
#undef _MINIX
|
||||
|
||||
/* Define to 2 if the system does not provide POSIX.1 features except with
|
||||
this defined. */
|
||||
#undef _POSIX_1_SOURCE
|
||||
|
||||
/* Define to 1 if you need to in order for `stat' and other things to work. */
|
||||
#undef _POSIX_SOURCE
|
||||
Vendored
-1773
File diff suppressed because it is too large
Load Diff
Vendored
-19489
File diff suppressed because it is too large
Load Diff
@@ -1,150 +0,0 @@
|
||||
## Process this file with autoconf to produce configure.
|
||||
## In general, the safest way to proceed is to run ./autogen.sh
|
||||
|
||||
AC_PREREQ(2.59)
|
||||
|
||||
# Note: If you change the version, you must also update it in:
|
||||
# * java/pom.xml
|
||||
# * python/setup.py
|
||||
# * src/google/protobuf/stubs/common.h
|
||||
# * src/Makefile.am (Update -version-info for LDFLAGS if needed)
|
||||
#
|
||||
# In the SVN trunk, the version should always be the next anticipated release
|
||||
# version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed
|
||||
# the size of one file name in the dist tarfile over the 99-char limit.)
|
||||
AC_INIT([Protocol Buffers],[2.5.0],[[email protected]],[protobuf])
|
||||
|
||||
AM_MAINTAINER_MODE([enable])
|
||||
|
||||
AC_CONFIG_SRCDIR(src/google/protobuf/message.cc)
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
||||
# autoconf's default CXXFLAGS are usually "-g -O2". These aren't necessarily
|
||||
# the best choice for libprotobuf.
|
||||
AS_IF([test "x${ac_cv_env_CFLAGS_set}" = "x"],
|
||||
[CFLAGS=""])
|
||||
AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],
|
||||
[CXXFLAGS=""])
|
||||
|
||||
AC_CANONICAL_TARGET
|
||||
|
||||
AM_INIT_AUTOMAKE
|
||||
|
||||
AC_ARG_WITH([zlib],
|
||||
[AS_HELP_STRING([--with-zlib],
|
||||
[include classes for streaming compressed data in and out @<:@default=check@:>@])],
|
||||
[],[with_zlib=check])
|
||||
|
||||
AC_ARG_WITH([protoc],
|
||||
[AS_HELP_STRING([--with-protoc=COMMAND],
|
||||
[use the given protoc command instead of building a new one when building tests (useful for cross-compiling)])],
|
||||
[],[with_protoc=no])
|
||||
|
||||
# Checks for programs.
|
||||
AC_PROG_CC
|
||||
AC_PROG_CXX
|
||||
AC_LANG([C++])
|
||||
ACX_USE_SYSTEM_EXTENSIONS
|
||||
AM_CONDITIONAL(GCC, test "$GCC" = yes) # let the Makefile know if we're gcc
|
||||
|
||||
# test_util.cc takes forever to compile with GCC and optimization turned on.
|
||||
AC_MSG_CHECKING([C++ compiler flags...])
|
||||
AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],[
|
||||
AS_IF([test "$GCC" = "yes"],[
|
||||
PROTOBUF_OPT_FLAG="-O2"
|
||||
CXXFLAGS="${CXXFLAGS} -g"
|
||||
])
|
||||
|
||||
# Protocol Buffers contains several checks that are intended to be used only
|
||||
# for debugging and which might hurt performance. Most users are probably
|
||||
# end users who don't want these checks, so add -DNDEBUG by default.
|
||||
CXXFLAGS="$CXXFLAGS -DNDEBUG"
|
||||
|
||||
AC_MSG_RESULT([use default: $PROTOBUF_OPT_FLAG $CXXFLAGS])
|
||||
],[
|
||||
AC_MSG_RESULT([use user-supplied: $CXXFLAGS])
|
||||
])
|
||||
|
||||
AC_SUBST(PROTOBUF_OPT_FLAG)
|
||||
|
||||
ACX_CHECK_SUNCC
|
||||
|
||||
# Have to do libtool after SUNCC, other wise it "helpfully" adds Crun Cstd
|
||||
# to the link
|
||||
AC_PROG_LIBTOOL
|
||||
|
||||
# Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h stdlib.h unistd.h])
|
||||
|
||||
# Checks for library functions.
|
||||
AC_FUNC_MEMCMP
|
||||
AC_FUNC_STRTOD
|
||||
AC_CHECK_FUNCS([ftruncate memset mkdir strchr strerror strtol])
|
||||
|
||||
# Check for zlib.
|
||||
HAVE_ZLIB=0
|
||||
AS_IF([test "$with_zlib" != no], [
|
||||
AC_MSG_CHECKING([zlib version])
|
||||
|
||||
# First check the zlib header version.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_PROGRAM([[
|
||||
#include <zlib.h>
|
||||
#if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1204)
|
||||
# error zlib version too old
|
||||
#endif
|
||||
]], [])], [
|
||||
AC_MSG_RESULT([ok (1.2.0.4 or later)])
|
||||
|
||||
# Also need to add -lz to the linker flags and make sure this succeeds.
|
||||
AC_SEARCH_LIBS([zlibVersion], [z], [
|
||||
AC_DEFINE([HAVE_ZLIB], [1], [Enable classes using zlib compression.])
|
||||
HAVE_ZLIB=1
|
||||
], [
|
||||
AS_IF([test "$with_zlib" != check], [
|
||||
AC_MSG_FAILURE([--with-zlib was given, but no working zlib library was found])
|
||||
])
|
||||
])
|
||||
], [
|
||||
AS_IF([test "$with_zlib" = check], [
|
||||
AC_MSG_RESULT([headers missing or too old (requires 1.2.0.4)])
|
||||
], [
|
||||
AC_MSG_FAILURE([--with-zlib was given, but zlib headers were not present or were too old (requires 1.2.0.4)])
|
||||
])
|
||||
])
|
||||
])
|
||||
AM_CONDITIONAL([HAVE_ZLIB], [test $HAVE_ZLIB = 1])
|
||||
|
||||
AS_IF([test "$with_protoc" != "no"], [
|
||||
PROTOC=$with_protoc
|
||||
AS_IF([test "$with_protoc" = "yes"], [
|
||||
# No argument given. Use system protoc.
|
||||
PROTOC=protoc
|
||||
])
|
||||
AS_IF([echo "$PROTOC" | grep -q '^@<:@^/@:>@.*/'], [
|
||||
# Does not start with a slash, but contains a slash. So, it's a relative
|
||||
# path (as opposed to an absolute path or an executable in $PATH).
|
||||
# Since it will actually be executed from the src directory, prefix with
|
||||
# the current directory. We also insert $ac_top_build_prefix in case this
|
||||
# is a nested package and --with-protoc was actually given on the outer
|
||||
# package's configure script.
|
||||
PROTOC=`pwd`/${ac_top_build_prefix}$PROTOC
|
||||
])
|
||||
AC_SUBST([PROTOC])
|
||||
])
|
||||
AM_CONDITIONAL([USE_EXTERNAL_PROTOC], [test "$with_protoc" != "no"])
|
||||
|
||||
ACX_PTHREAD
|
||||
AC_CXX_STL_HASH
|
||||
|
||||
# HACK: Make gtest's configure script pick up our copy of CFLAGS and CXXFLAGS,
|
||||
# since the flags added by ACX_CHECK_SUNCC must be used when compiling gtest
|
||||
# too.
|
||||
export CFLAGS
|
||||
export CXXFLAGS
|
||||
AC_CONFIG_SUBDIRS([gtest])
|
||||
|
||||
AC_CONFIG_FILES([Makefile src/Makefile protobuf.pc protobuf-lite.pc])
|
||||
AC_OUTPUT
|
||||
@@ -1,688 +0,0 @@
|
||||
#! /bin/sh
|
||||
# depcomp - compile a program generating dependencies as side-effects
|
||||
|
||||
scriptversion=2011-12-04.11; # UTC
|
||||
|
||||
# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010,
|
||||
# 2011 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
# Originally written by Alexandre Oliva <[email protected]>.
|
||||
|
||||
case $1 in
|
||||
'')
|
||||
echo "$0: No command. Try \`$0 --help' for more information." 1>&2
|
||||
exit 1;
|
||||
;;
|
||||
-h | --h*)
|
||||
cat <<\EOF
|
||||
Usage: depcomp [--help] [--version] PROGRAM [ARGS]
|
||||
|
||||
Run PROGRAMS ARGS to compile a file, generating dependencies
|
||||
as side-effects.
|
||||
|
||||
Environment variables:
|
||||
depmode Dependency tracking mode.
|
||||
source Source file read by `PROGRAMS ARGS'.
|
||||
object Object file output by `PROGRAMS ARGS'.
|
||||
DEPDIR directory where to store dependencies.
|
||||
depfile Dependency file to output.
|
||||
tmpdepfile Temporary file to use when outputting dependencies.
|
||||
libtool Whether libtool is used (yes/no).
|
||||
|
||||
Report bugs to <[email protected]>.
|
||||
EOF
|
||||
exit $?
|
||||
;;
|
||||
-v | --v*)
|
||||
echo "depcomp $scriptversion"
|
||||
exit $?
|
||||
;;
|
||||
esac
|
||||
|
||||
if test -z "$depmode" || test -z "$source" || test -z "$object"; then
|
||||
echo "depcomp: Variables source, object and depmode must be set" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
|
||||
depfile=${depfile-`echo "$object" |
|
||||
sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
|
||||
tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
|
||||
|
||||
rm -f "$tmpdepfile"
|
||||
|
||||
# Some modes work just like other modes, but use different flags. We
|
||||
# parameterize here, but still list the modes in the big case below,
|
||||
# to make depend.m4 easier to write. Note that we *cannot* use a case
|
||||
# here, because this file can only contain one case statement.
|
||||
if test "$depmode" = hp; then
|
||||
# HP compiler uses -M and no extra arg.
|
||||
gccflag=-M
|
||||
depmode=gcc
|
||||
fi
|
||||
|
||||
if test "$depmode" = dashXmstdout; then
|
||||
# This is just like dashmstdout with a different argument.
|
||||
dashmflag=-xM
|
||||
depmode=dashmstdout
|
||||
fi
|
||||
|
||||
cygpath_u="cygpath -u -f -"
|
||||
if test "$depmode" = msvcmsys; then
|
||||
# This is just like msvisualcpp but w/o cygpath translation.
|
||||
# Just convert the backslash-escaped backslashes to single forward
|
||||
# slashes to satisfy depend.m4
|
||||
cygpath_u='sed s,\\\\,/,g'
|
||||
depmode=msvisualcpp
|
||||
fi
|
||||
|
||||
if test "$depmode" = msvc7msys; then
|
||||
# This is just like msvc7 but w/o cygpath translation.
|
||||
# Just convert the backslash-escaped backslashes to single forward
|
||||
# slashes to satisfy depend.m4
|
||||
cygpath_u='sed s,\\\\,/,g'
|
||||
depmode=msvc7
|
||||
fi
|
||||
|
||||
case "$depmode" in
|
||||
gcc3)
|
||||
## gcc 3 implements dependency tracking that does exactly what
|
||||
## we want. Yay! Note: for some reason libtool 1.4 doesn't like
|
||||
## it if -MD -MP comes after the -MF stuff. Hmm.
|
||||
## Unfortunately, FreeBSD c89 acceptance of flags depends upon
|
||||
## the command line argument order; so add the flags where they
|
||||
## appear in depend2.am. Note that the slowdown incurred here
|
||||
## affects only configure: in makefiles, %FASTDEP% shortcuts this.
|
||||
for arg
|
||||
do
|
||||
case $arg in
|
||||
-c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
|
||||
*) set fnord "$@" "$arg" ;;
|
||||
esac
|
||||
shift # fnord
|
||||
shift # $arg
|
||||
done
|
||||
"$@"
|
||||
stat=$?
|
||||
if test $stat -eq 0; then :
|
||||
else
|
||||
rm -f "$tmpdepfile"
|
||||
exit $stat
|
||||
fi
|
||||
mv "$tmpdepfile" "$depfile"
|
||||
;;
|
||||
|
||||
gcc)
|
||||
## There are various ways to get dependency output from gcc. Here's
|
||||
## why we pick this rather obscure method:
|
||||
## - Don't want to use -MD because we'd like the dependencies to end
|
||||
## up in a subdir. Having to rename by hand is ugly.
|
||||
## (We might end up doing this anyway to support other compilers.)
|
||||
## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
|
||||
## -MM, not -M (despite what the docs say).
|
||||
## - Using -M directly means running the compiler twice (even worse
|
||||
## than renaming).
|
||||
if test -z "$gccflag"; then
|
||||
gccflag=-MD,
|
||||
fi
|
||||
"$@" -Wp,"$gccflag$tmpdepfile"
|
||||
stat=$?
|
||||
if test $stat -eq 0; then :
|
||||
else
|
||||
rm -f "$tmpdepfile"
|
||||
exit $stat
|
||||
fi
|
||||
rm -f "$depfile"
|
||||
echo "$object : \\" > "$depfile"
|
||||
alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
|
||||
## The second -e expression handles DOS-style file names with drive letters.
|
||||
sed -e 's/^[^:]*: / /' \
|
||||
-e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
|
||||
## This next piece of magic avoids the `deleted header file' problem.
|
||||
## The problem is that when a header file which appears in a .P file
|
||||
## is deleted, the dependency causes make to die (because there is
|
||||
## typically no way to rebuild the header). We avoid this by adding
|
||||
## dummy dependencies for each header file. Too bad gcc doesn't do
|
||||
## this for us directly.
|
||||
tr ' ' '
|
||||
' < "$tmpdepfile" |
|
||||
## Some versions of gcc put a space before the `:'. On the theory
|
||||
## that the space means something, we add a space to the output as
|
||||
## well. hp depmode also adds that space, but also prefixes the VPATH
|
||||
## to the object. Take care to not repeat it in the output.
|
||||
## Some versions of the HPUX 10.20 sed can't process this invocation
|
||||
## correctly. Breaking it into two sed invocations is a workaround.
|
||||
sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
|
||||
| sed -e 's/$/ :/' >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
hp)
|
||||
# This case exists only to let depend.m4 do its work. It works by
|
||||
# looking at the text of this script. This case will never be run,
|
||||
# since it is checked for above.
|
||||
exit 1
|
||||
;;
|
||||
|
||||
sgi)
|
||||
if test "$libtool" = yes; then
|
||||
"$@" "-Wp,-MDupdate,$tmpdepfile"
|
||||
else
|
||||
"$@" -MDupdate "$tmpdepfile"
|
||||
fi
|
||||
stat=$?
|
||||
if test $stat -eq 0; then :
|
||||
else
|
||||
rm -f "$tmpdepfile"
|
||||
exit $stat
|
||||
fi
|
||||
rm -f "$depfile"
|
||||
|
||||
if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
|
||||
echo "$object : \\" > "$depfile"
|
||||
|
||||
# Clip off the initial element (the dependent). Don't try to be
|
||||
# clever and replace this with sed code, as IRIX sed won't handle
|
||||
# lines with more than a fixed number of characters (4096 in
|
||||
# IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
|
||||
# the IRIX cc adds comments like `#:fec' to the end of the
|
||||
# dependency line.
|
||||
tr ' ' '
|
||||
' < "$tmpdepfile" \
|
||||
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
|
||||
tr '
|
||||
' ' ' >> "$depfile"
|
||||
echo >> "$depfile"
|
||||
|
||||
# The second pass generates a dummy entry for each header file.
|
||||
tr ' ' '
|
||||
' < "$tmpdepfile" \
|
||||
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
|
||||
>> "$depfile"
|
||||
else
|
||||
# The sourcefile does not contain any dependencies, so just
|
||||
# store a dummy comment line, to avoid errors with the Makefile
|
||||
# "include basename.Plo" scheme.
|
||||
echo "#dummy" > "$depfile"
|
||||
fi
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
aix)
|
||||
# The C for AIX Compiler uses -M and outputs the dependencies
|
||||
# in a .u file. In older versions, this file always lives in the
|
||||
# current directory. Also, the AIX compiler puts `$object:' at the
|
||||
# start of each line; $object doesn't have directory information.
|
||||
# Version 6 uses the directory in both cases.
|
||||
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
|
||||
test "x$dir" = "x$object" && dir=
|
||||
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
|
||||
if test "$libtool" = yes; then
|
||||
tmpdepfile1=$dir$base.u
|
||||
tmpdepfile2=$base.u
|
||||
tmpdepfile3=$dir.libs/$base.u
|
||||
"$@" -Wc,-M
|
||||
else
|
||||
tmpdepfile1=$dir$base.u
|
||||
tmpdepfile2=$dir$base.u
|
||||
tmpdepfile3=$dir$base.u
|
||||
"$@" -M
|
||||
fi
|
||||
stat=$?
|
||||
|
||||
if test $stat -eq 0; then :
|
||||
else
|
||||
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
|
||||
exit $stat
|
||||
fi
|
||||
|
||||
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
|
||||
do
|
||||
test -f "$tmpdepfile" && break
|
||||
done
|
||||
if test -f "$tmpdepfile"; then
|
||||
# Each line is of the form `foo.o: dependent.h'.
|
||||
# Do two passes, one to just change these to
|
||||
# `$object: dependent.h' and one to simply `dependent.h:'.
|
||||
sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
|
||||
# That's a tab and a space in the [].
|
||||
sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
|
||||
else
|
||||
# The sourcefile does not contain any dependencies, so just
|
||||
# store a dummy comment line, to avoid errors with the Makefile
|
||||
# "include basename.Plo" scheme.
|
||||
echo "#dummy" > "$depfile"
|
||||
fi
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
icc)
|
||||
# Intel's C compiler understands `-MD -MF file'. However on
|
||||
# icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
|
||||
# ICC 7.0 will fill foo.d with something like
|
||||
# foo.o: sub/foo.c
|
||||
# foo.o: sub/foo.h
|
||||
# which is wrong. We want:
|
||||
# sub/foo.o: sub/foo.c
|
||||
# sub/foo.o: sub/foo.h
|
||||
# sub/foo.c:
|
||||
# sub/foo.h:
|
||||
# ICC 7.1 will output
|
||||
# foo.o: sub/foo.c sub/foo.h
|
||||
# and will wrap long lines using \ :
|
||||
# foo.o: sub/foo.c ... \
|
||||
# sub/foo.h ... \
|
||||
# ...
|
||||
|
||||
"$@" -MD -MF "$tmpdepfile"
|
||||
stat=$?
|
||||
if test $stat -eq 0; then :
|
||||
else
|
||||
rm -f "$tmpdepfile"
|
||||
exit $stat
|
||||
fi
|
||||
rm -f "$depfile"
|
||||
# Each line is of the form `foo.o: dependent.h',
|
||||
# or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
|
||||
# Do two passes, one to just change these to
|
||||
# `$object: dependent.h' and one to simply `dependent.h:'.
|
||||
sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
|
||||
# Some versions of the HPUX 10.20 sed can't process this invocation
|
||||
# correctly. Breaking it into two sed invocations is a workaround.
|
||||
sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
|
||||
sed -e 's/$/ :/' >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
hp2)
|
||||
# The "hp" stanza above does not work with aCC (C++) and HP's ia64
|
||||
# compilers, which have integrated preprocessors. The correct option
|
||||
# to use with these is +Maked; it writes dependencies to a file named
|
||||
# 'foo.d', which lands next to the object file, wherever that
|
||||
# happens to be.
|
||||
# Much of this is similar to the tru64 case; see comments there.
|
||||
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
|
||||
test "x$dir" = "x$object" && dir=
|
||||
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
|
||||
if test "$libtool" = yes; then
|
||||
tmpdepfile1=$dir$base.d
|
||||
tmpdepfile2=$dir.libs/$base.d
|
||||
"$@" -Wc,+Maked
|
||||
else
|
||||
tmpdepfile1=$dir$base.d
|
||||
tmpdepfile2=$dir$base.d
|
||||
"$@" +Maked
|
||||
fi
|
||||
stat=$?
|
||||
if test $stat -eq 0; then :
|
||||
else
|
||||
rm -f "$tmpdepfile1" "$tmpdepfile2"
|
||||
exit $stat
|
||||
fi
|
||||
|
||||
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
|
||||
do
|
||||
test -f "$tmpdepfile" && break
|
||||
done
|
||||
if test -f "$tmpdepfile"; then
|
||||
sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
|
||||
# Add `dependent.h:' lines.
|
||||
sed -ne '2,${
|
||||
s/^ *//
|
||||
s/ \\*$//
|
||||
s/$/:/
|
||||
p
|
||||
}' "$tmpdepfile" >> "$depfile"
|
||||
else
|
||||
echo "#dummy" > "$depfile"
|
||||
fi
|
||||
rm -f "$tmpdepfile" "$tmpdepfile2"
|
||||
;;
|
||||
|
||||
tru64)
|
||||
# The Tru64 compiler uses -MD to generate dependencies as a side
|
||||
# effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
|
||||
# At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
|
||||
# dependencies in `foo.d' instead, so we check for that too.
|
||||
# Subdirectories are respected.
|
||||
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
|
||||
test "x$dir" = "x$object" && dir=
|
||||
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
|
||||
|
||||
if test "$libtool" = yes; then
|
||||
# With Tru64 cc, shared objects can also be used to make a
|
||||
# static library. This mechanism is used in libtool 1.4 series to
|
||||
# handle both shared and static libraries in a single compilation.
|
||||
# With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
|
||||
#
|
||||
# With libtool 1.5 this exception was removed, and libtool now
|
||||
# generates 2 separate objects for the 2 libraries. These two
|
||||
# compilations output dependencies in $dir.libs/$base.o.d and
|
||||
# in $dir$base.o.d. We have to check for both files, because
|
||||
# one of the two compilations can be disabled. We should prefer
|
||||
# $dir$base.o.d over $dir.libs/$base.o.d because the latter is
|
||||
# automatically cleaned when .libs/ is deleted, while ignoring
|
||||
# the former would cause a distcleancheck panic.
|
||||
tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4
|
||||
tmpdepfile2=$dir$base.o.d # libtool 1.5
|
||||
tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5
|
||||
tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504
|
||||
"$@" -Wc,-MD
|
||||
else
|
||||
tmpdepfile1=$dir$base.o.d
|
||||
tmpdepfile2=$dir$base.d
|
||||
tmpdepfile3=$dir$base.d
|
||||
tmpdepfile4=$dir$base.d
|
||||
"$@" -MD
|
||||
fi
|
||||
|
||||
stat=$?
|
||||
if test $stat -eq 0; then :
|
||||
else
|
||||
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
|
||||
exit $stat
|
||||
fi
|
||||
|
||||
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
|
||||
do
|
||||
test -f "$tmpdepfile" && break
|
||||
done
|
||||
if test -f "$tmpdepfile"; then
|
||||
sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
|
||||
# That's a tab and a space in the [].
|
||||
sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
|
||||
else
|
||||
echo "#dummy" > "$depfile"
|
||||
fi
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
msvc7)
|
||||
if test "$libtool" = yes; then
|
||||
showIncludes=-Wc,-showIncludes
|
||||
else
|
||||
showIncludes=-showIncludes
|
||||
fi
|
||||
"$@" $showIncludes > "$tmpdepfile"
|
||||
stat=$?
|
||||
grep -v '^Note: including file: ' "$tmpdepfile"
|
||||
if test "$stat" = 0; then :
|
||||
else
|
||||
rm -f "$tmpdepfile"
|
||||
exit $stat
|
||||
fi
|
||||
rm -f "$depfile"
|
||||
echo "$object : \\" > "$depfile"
|
||||
# The first sed program below extracts the file names and escapes
|
||||
# backslashes for cygpath. The second sed program outputs the file
|
||||
# name when reading, but also accumulates all include files in the
|
||||
# hold buffer in order to output them again at the end. This only
|
||||
# works with sed implementations that can handle large buffers.
|
||||
sed < "$tmpdepfile" -n '
|
||||
/^Note: including file: *\(.*\)/ {
|
||||
s//\1/
|
||||
s/\\/\\\\/g
|
||||
p
|
||||
}' | $cygpath_u | sort -u | sed -n '
|
||||
s/ /\\ /g
|
||||
s/\(.*\)/ \1 \\/p
|
||||
s/.\(.*\) \\/\1:/
|
||||
H
|
||||
$ {
|
||||
s/.*/ /
|
||||
G
|
||||
p
|
||||
}' >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
msvc7msys)
|
||||
# This case exists only to let depend.m4 do its work. It works by
|
||||
# looking at the text of this script. This case will never be run,
|
||||
# since it is checked for above.
|
||||
exit 1
|
||||
;;
|
||||
|
||||
#nosideeffect)
|
||||
# This comment above is used by automake to tell side-effect
|
||||
# dependency tracking mechanisms from slower ones.
|
||||
|
||||
dashmstdout)
|
||||
# Important note: in order to support this mode, a compiler *must*
|
||||
# always write the preprocessed file to stdout, regardless of -o.
|
||||
"$@" || exit $?
|
||||
|
||||
# Remove the call to Libtool.
|
||||
if test "$libtool" = yes; then
|
||||
while test "X$1" != 'X--mode=compile'; do
|
||||
shift
|
||||
done
|
||||
shift
|
||||
fi
|
||||
|
||||
# Remove `-o $object'.
|
||||
IFS=" "
|
||||
for arg
|
||||
do
|
||||
case $arg in
|
||||
-o)
|
||||
shift
|
||||
;;
|
||||
$object)
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set fnord "$@" "$arg"
|
||||
shift # fnord
|
||||
shift # $arg
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
test -z "$dashmflag" && dashmflag=-M
|
||||
# Require at least two characters before searching for `:'
|
||||
# in the target name. This is to cope with DOS-style filenames:
|
||||
# a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
|
||||
"$@" $dashmflag |
|
||||
sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
|
||||
rm -f "$depfile"
|
||||
cat < "$tmpdepfile" > "$depfile"
|
||||
tr ' ' '
|
||||
' < "$tmpdepfile" | \
|
||||
## Some versions of the HPUX 10.20 sed can't process this invocation
|
||||
## correctly. Breaking it into two sed invocations is a workaround.
|
||||
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
dashXmstdout)
|
||||
# This case only exists to satisfy depend.m4. It is never actually
|
||||
# run, as this mode is specially recognized in the preamble.
|
||||
exit 1
|
||||
;;
|
||||
|
||||
makedepend)
|
||||
"$@" || exit $?
|
||||
# Remove any Libtool call
|
||||
if test "$libtool" = yes; then
|
||||
while test "X$1" != 'X--mode=compile'; do
|
||||
shift
|
||||
done
|
||||
shift
|
||||
fi
|
||||
# X makedepend
|
||||
shift
|
||||
cleared=no eat=no
|
||||
for arg
|
||||
do
|
||||
case $cleared in
|
||||
no)
|
||||
set ""; shift
|
||||
cleared=yes ;;
|
||||
esac
|
||||
if test $eat = yes; then
|
||||
eat=no
|
||||
continue
|
||||
fi
|
||||
case "$arg" in
|
||||
-D*|-I*)
|
||||
set fnord "$@" "$arg"; shift ;;
|
||||
# Strip any option that makedepend may not understand. Remove
|
||||
# the object too, otherwise makedepend will parse it as a source file.
|
||||
-arch)
|
||||
eat=yes ;;
|
||||
-*|$object)
|
||||
;;
|
||||
*)
|
||||
set fnord "$@" "$arg"; shift ;;
|
||||
esac
|
||||
done
|
||||
obj_suffix=`echo "$object" | sed 's/^.*\././'`
|
||||
touch "$tmpdepfile"
|
||||
${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
|
||||
rm -f "$depfile"
|
||||
# makedepend may prepend the VPATH from the source file name to the object.
|
||||
# No need to regex-escape $object, excess matching of '.' is harmless.
|
||||
sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
|
||||
sed '1,2d' "$tmpdepfile" | tr ' ' '
|
||||
' | \
|
||||
## Some versions of the HPUX 10.20 sed can't process this invocation
|
||||
## correctly. Breaking it into two sed invocations is a workaround.
|
||||
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
|
||||
rm -f "$tmpdepfile" "$tmpdepfile".bak
|
||||
;;
|
||||
|
||||
cpp)
|
||||
# Important note: in order to support this mode, a compiler *must*
|
||||
# always write the preprocessed file to stdout.
|
||||
"$@" || exit $?
|
||||
|
||||
# Remove the call to Libtool.
|
||||
if test "$libtool" = yes; then
|
||||
while test "X$1" != 'X--mode=compile'; do
|
||||
shift
|
||||
done
|
||||
shift
|
||||
fi
|
||||
|
||||
# Remove `-o $object'.
|
||||
IFS=" "
|
||||
for arg
|
||||
do
|
||||
case $arg in
|
||||
-o)
|
||||
shift
|
||||
;;
|
||||
$object)
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set fnord "$@" "$arg"
|
||||
shift # fnord
|
||||
shift # $arg
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
"$@" -E |
|
||||
sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
|
||||
-e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
|
||||
sed '$ s: \\$::' > "$tmpdepfile"
|
||||
rm -f "$depfile"
|
||||
echo "$object : \\" > "$depfile"
|
||||
cat < "$tmpdepfile" >> "$depfile"
|
||||
sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
msvisualcpp)
|
||||
# Important note: in order to support this mode, a compiler *must*
|
||||
# always write the preprocessed file to stdout.
|
||||
"$@" || exit $?
|
||||
|
||||
# Remove the call to Libtool.
|
||||
if test "$libtool" = yes; then
|
||||
while test "X$1" != 'X--mode=compile'; do
|
||||
shift
|
||||
done
|
||||
shift
|
||||
fi
|
||||
|
||||
IFS=" "
|
||||
for arg
|
||||
do
|
||||
case "$arg" in
|
||||
-o)
|
||||
shift
|
||||
;;
|
||||
$object)
|
||||
shift
|
||||
;;
|
||||
"-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
|
||||
set fnord "$@"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set fnord "$@" "$arg"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
"$@" -E 2>/dev/null |
|
||||
sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
|
||||
rm -f "$depfile"
|
||||
echo "$object : \\" > "$depfile"
|
||||
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
|
||||
echo " " >> "$depfile"
|
||||
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
msvcmsys)
|
||||
# This case exists only to let depend.m4 do its work. It works by
|
||||
# looking at the text of this script. This case will never be run,
|
||||
# since it is checked for above.
|
||||
exit 1
|
||||
;;
|
||||
|
||||
none)
|
||||
exec "$@"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown depmode $depmode" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
|
||||
# Local Variables:
|
||||
# mode: shell-script
|
||||
# sh-indentation: 2
|
||||
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
||||
@@ -1,5 +0,0 @@
|
||||
This directory contains syntax highlighting and configuration files for editors
|
||||
to properly display Protocol Buffer files.
|
||||
|
||||
See each file's header comment for directions on how to use it with the
|
||||
appropriate editor.
|
||||
@@ -1,105 +0,0 @@
|
||||
" Protocol Buffers - Google's data interchange format
|
||||
" Copyright 2008 Google Inc. All rights reserved.
|
||||
" http://code.google.com/p/protobuf/
|
||||
"
|
||||
" Redistribution and use in source and binary forms, with or without
|
||||
" modification, are permitted provided that the following conditions are
|
||||
" met:
|
||||
"
|
||||
" * Redistributions of source code must retain the above copyright
|
||||
" notice, this list of conditions and the following disclaimer.
|
||||
" * Redistributions in binary form must reproduce the above
|
||||
" copyright notice, this list of conditions and the following disclaimer
|
||||
" in the documentation and/or other materials provided with the
|
||||
" distribution.
|
||||
" * Neither the name of Google Inc. nor the names of its
|
||||
" contributors may be used to endorse or promote products derived from
|
||||
" this software without specific prior written permission.
|
||||
"
|
||||
" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
" OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
" This is the Vim syntax file for Google Protocol Buffers.
|
||||
"
|
||||
" Usage:
|
||||
"
|
||||
" 1. cp proto.vim ~/.vim/syntax/
|
||||
" 2. Add the following to ~/.vimrc:
|
||||
"
|
||||
" augroup filetype
|
||||
" au! BufRead,BufNewFile *.proto setfiletype proto
|
||||
" augroup end
|
||||
"
|
||||
" Or just create a new file called ~/.vim/ftdetect/proto.vim with the
|
||||
" previous lines on it.
|
||||
|
||||
if version < 600
|
||||
syntax clear
|
||||
elseif exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
syn case match
|
||||
|
||||
syn keyword pbTodo contained TODO FIXME XXX
|
||||
syn cluster pbCommentGrp contains=pbTodo
|
||||
|
||||
syn keyword pbSyntax syntax import option
|
||||
syn keyword pbStructure package message group
|
||||
syn keyword pbRepeat optional required repeated
|
||||
syn keyword pbDefault default
|
||||
syn keyword pbExtend extend extensions to max
|
||||
syn keyword pbRPC service rpc returns
|
||||
|
||||
syn keyword pbType int32 int64 uint32 uint64 sint32 sint64
|
||||
syn keyword pbType fixed32 fixed64 sfixed32 sfixed64
|
||||
syn keyword pbType float double bool string bytes
|
||||
syn keyword pbTypedef enum
|
||||
syn keyword pbBool true false
|
||||
|
||||
syn match pbInt /-\?\<\d\+\>/
|
||||
syn match pbInt /\<0[xX]\x+\>/
|
||||
syn match pbFloat /\<-\?\d*\(\.\d*\)\?/
|
||||
syn region pbComment start="\/\*" end="\*\/" contains=@pbCommentGrp
|
||||
syn region pbComment start="//" skip="\\$" end="$" keepend contains=@pbCommentGrp
|
||||
syn region pbString start=/"/ skip=/\\./ end=/"/
|
||||
syn region pbString start=/'/ skip=/\\./ end=/'/
|
||||
|
||||
if version >= 508 || !exists("did_proto_syn_inits")
|
||||
if version < 508
|
||||
let did_proto_syn_inits = 1
|
||||
command -nargs=+ HiLink hi link <args>
|
||||
else
|
||||
command -nargs=+ HiLink hi def link <args>
|
||||
endif
|
||||
|
||||
HiLink pbTodo Todo
|
||||
|
||||
HiLink pbSyntax Include
|
||||
HiLink pbStructure Structure
|
||||
HiLink pbRepeat Repeat
|
||||
HiLink pbDefault Keyword
|
||||
HiLink pbExtend Keyword
|
||||
HiLink pbRPC Keyword
|
||||
HiLink pbType Type
|
||||
HiLink pbTypedef Typedef
|
||||
HiLink pbBool Boolean
|
||||
|
||||
HiLink pbInt Number
|
||||
HiLink pbFloat Float
|
||||
HiLink pbComment Comment
|
||||
HiLink pbString String
|
||||
|
||||
delcommand HiLink
|
||||
endif
|
||||
|
||||
let b:current_syntax = "proto"
|
||||
@@ -1,220 +0,0 @@
|
||||
;;; protobuf-mode.el --- major mode for editing protocol buffers.
|
||||
|
||||
;; Author: Alexandre Vassalotti <[email protected]>
|
||||
;; Created: 23-Apr-2009
|
||||
;; Version: 0.3
|
||||
;; Keywords: google protobuf languages
|
||||
|
||||
;; Redistribution and use in source and binary forms, with or without
|
||||
;; modification, are permitted provided that the following conditions are
|
||||
;; met:
|
||||
;;
|
||||
;; * Redistributions of source code must retain the above copyright
|
||||
;; notice, this list of conditions and the following disclaimer.
|
||||
;; * Redistributions in binary form must reproduce the above
|
||||
;; copyright notice, this list of conditions and the following disclaimer
|
||||
;; in the documentation and/or other materials provided with the
|
||||
;; distribution.
|
||||
;; * Neither the name of Google Inc. nor the names of its
|
||||
;; contributors may be used to endorse or promote products derived from
|
||||
;; this software without specific prior written permission.
|
||||
;;
|
||||
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Installation:
|
||||
;; - Put `protobuf-mode.el' in your Emacs load-path.
|
||||
;; - Add this line to your .emacs file:
|
||||
;; (require 'protobuf-mode)
|
||||
;;
|
||||
;; You can customize this mode just like any mode derived from CC Mode. If
|
||||
;; you want to add customizations specific to protobuf-mode, you can use the
|
||||
;; `protobuf-mode-hook'. For example, the following would make protocol-mode
|
||||
;; use 2-space indentation:
|
||||
;;
|
||||
;; (defconst my-protobuf-style
|
||||
;; '((c-basic-offset . 2)
|
||||
;; (indent-tabs-mode . nil)))
|
||||
;;
|
||||
;; (add-hook 'protobuf-mode-hook
|
||||
;; (lambda () (c-add-style "my-style" my-protobuf-style t)))
|
||||
;;
|
||||
;; Refer to the documentation of CC Mode for more information about
|
||||
;; customization details and how to use this mode.
|
||||
;;
|
||||
;; TODO:
|
||||
;; - Make highlighting for enum values work properly.
|
||||
;; - Fix the parser to recognize extensions as identifiers and not
|
||||
;; as casts.
|
||||
;; - Improve the parsing of option assignment lists. For example:
|
||||
;; optional int32 foo = 1 [(my_field_option) = 4.5];
|
||||
;; - Add support for fully-qualified identifiers (e.g., with a leading ".").
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'cc-mode)
|
||||
|
||||
(eval-when-compile
|
||||
(require 'cc-langs)
|
||||
(require 'cc-fonts))
|
||||
|
||||
;; This mode does not inherit properties from other modes. So, we do not use
|
||||
;; the usual `c-add-language' function.
|
||||
(eval-and-compile
|
||||
(put 'protobuf-mode 'c-mode-prefix "protobuf-"))
|
||||
|
||||
;; The following code uses of the `c-lang-defconst' macro define syntactic
|
||||
;; features of protocol buffer language. Refer to the documentation in the
|
||||
;; cc-langs.el file for information about the meaning of the -kwds variables.
|
||||
|
||||
(c-lang-defconst c-primitive-type-kwds
|
||||
protobuf '("double" "float" "int32" "int64" "uint32" "uint64" "sint32"
|
||||
"sint64" "fixed32" "fixed64" "sfixed32" "sfixed64" "bool"
|
||||
"string" "bytes" "group"))
|
||||
|
||||
(c-lang-defconst c-modifier-kwds
|
||||
protobuf '("required" "optional" "repeated"))
|
||||
|
||||
(c-lang-defconst c-class-decl-kwds
|
||||
protobuf '("message" "enum" "service"))
|
||||
|
||||
(c-lang-defconst c-constant-kwds
|
||||
protobuf '("true" "false"))
|
||||
|
||||
(c-lang-defconst c-other-decl-kwds
|
||||
protobuf '("package" "import"))
|
||||
|
||||
(c-lang-defconst c-other-kwds
|
||||
protobuf '("default" "max"))
|
||||
|
||||
(c-lang-defconst c-identifier-ops
|
||||
;; Handle extended identifiers like google.protobuf.MessageOptions
|
||||
protobuf '((left-assoc ".")))
|
||||
|
||||
;; The following keywords do not fit well in keyword classes defined by
|
||||
;; cc-mode. So, we approximate as best we can.
|
||||
|
||||
(c-lang-defconst c-type-list-kwds
|
||||
protobuf '("extensions" "to"))
|
||||
|
||||
(c-lang-defconst c-typeless-decl-kwds
|
||||
protobuf '("extend" "rpc" "option" "returns"))
|
||||
|
||||
|
||||
;; Here we remove default syntax for loops, if-statements and other C
|
||||
;; syntactic features that are not supported by the protocol buffer language.
|
||||
|
||||
(c-lang-defconst c-brace-list-decl-kwds
|
||||
;; Remove syntax for C-style enumerations.
|
||||
protobuf nil)
|
||||
|
||||
(c-lang-defconst c-block-stmt-1-kwds
|
||||
;; Remove syntax for "do" and "else" keywords.
|
||||
protobuf nil)
|
||||
|
||||
(c-lang-defconst c-block-stmt-2-kwds
|
||||
;; Remove syntax for "for", "if", "switch" and "while" keywords.
|
||||
protobuf nil)
|
||||
|
||||
(c-lang-defconst c-simple-stmt-kwds
|
||||
;; Remove syntax for "break", "continue", "goto" and "return" keywords.
|
||||
protobuf nil)
|
||||
|
||||
(c-lang-defconst c-paren-stmt-kwds
|
||||
;; Remove special case for the "(;;)" in for-loops.
|
||||
protobuf nil)
|
||||
|
||||
(c-lang-defconst c-label-kwds
|
||||
;; Remove case label syntax for the "case" and "default" keywords.
|
||||
protobuf nil)
|
||||
|
||||
(c-lang-defconst c-before-label-kwds
|
||||
;; Remove special case for the label in a goto statement.
|
||||
protobuf nil)
|
||||
|
||||
(c-lang-defconst c-cpp-matchers
|
||||
;; Disable all the C preprocessor syntax.
|
||||
protobuf nil)
|
||||
|
||||
(c-lang-defconst c-decl-prefix-re
|
||||
;; Same as for C, except it does not match "(". This is needed for disabling
|
||||
;; the syntax for casts.
|
||||
protobuf "\\([\{\};,]+\\)")
|
||||
|
||||
|
||||
;; Add support for variable levels of syntax highlighting.
|
||||
|
||||
(defconst protobuf-font-lock-keywords-1 (c-lang-const c-matchers-1 protobuf)
|
||||
"Minimal highlighting for protobuf-mode.")
|
||||
|
||||
(defconst protobuf-font-lock-keywords-2 (c-lang-const c-matchers-2 protobuf)
|
||||
"Fast normal highlighting for protobuf-mode.")
|
||||
|
||||
(defconst protobuf-font-lock-keywords-3 (c-lang-const c-matchers-3 protobuf)
|
||||
"Accurate normal highlighting for protobuf-mode.")
|
||||
|
||||
(defvar protobuf-font-lock-keywords protobuf-font-lock-keywords-3
|
||||
"Default expressions to highlight in protobuf-mode.")
|
||||
|
||||
;; Our syntax table is auto-generated from the keyword classes we defined
|
||||
;; previously with the `c-lang-const' macro.
|
||||
(defvar protobuf-mode-syntax-table nil
|
||||
"Syntax table used in protobuf-mode buffers.")
|
||||
(or protobuf-mode-syntax-table
|
||||
(setq protobuf-mode-syntax-table
|
||||
(funcall (c-lang-const c-make-mode-syntax-table protobuf))))
|
||||
|
||||
(defvar protobuf-mode-abbrev-table nil
|
||||
"Abbreviation table used in protobuf-mode buffers.")
|
||||
|
||||
(defvar protobuf-mode-map nil
|
||||
"Keymap used in protobuf-mode buffers.")
|
||||
(or protobuf-mode-map
|
||||
(setq protobuf-mode-map (c-make-inherited-keymap)))
|
||||
|
||||
(easy-menu-define protobuf-menu protobuf-mode-map
|
||||
"Protocol Buffers Mode Commands"
|
||||
(cons "Protocol Buffers" (c-lang-const c-mode-menu protobuf)))
|
||||
|
||||
;;;###autoload (add-to-list 'auto-mode-alist '("\\.proto\\'" . protobuf-mode))
|
||||
|
||||
;;;###autoload
|
||||
(defun protobuf-mode ()
|
||||
"Major mode for editing Protocol Buffers description language.
|
||||
|
||||
The hook `c-mode-common-hook' is run with no argument at mode
|
||||
initialization, then `protobuf-mode-hook'.
|
||||
|
||||
Key bindings:
|
||||
\\{protobuf-mode-map}"
|
||||
(interactive)
|
||||
(kill-all-local-variables)
|
||||
(set-syntax-table protobuf-mode-syntax-table)
|
||||
(setq major-mode 'protobuf-mode
|
||||
mode-name "Protocol-Buffers"
|
||||
local-abbrev-table protobuf-mode-abbrev-table
|
||||
abbrev-mode t)
|
||||
(use-local-map protobuf-mode-map)
|
||||
(c-initialize-cc-mode t)
|
||||
(if (fboundp 'c-make-emacs-variables-local)
|
||||
(c-make-emacs-variables-local))
|
||||
(c-init-language-vars protobuf-mode)
|
||||
(c-common-init 'protobuf-mode)
|
||||
(easy-menu-add protobuf-menu)
|
||||
(c-run-mode-hooks 'c-mode-common-hook 'protobuf-mode-hook)
|
||||
(c-update-modeline))
|
||||
|
||||
(provide 'protobuf-mode)
|
||||
|
||||
;;; protobuf-mode.el ends here
|
||||
@@ -1,95 +0,0 @@
|
||||
// See README.txt for information and build instructions.
|
||||
|
||||
import com.example.tutorial.AddressBookProtos.AddressBook;
|
||||
import com.example.tutorial.AddressBookProtos.Person;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
class AddPerson {
|
||||
// This function fills in a Person message based on user input.
|
||||
static Person PromptForAddress(BufferedReader stdin,
|
||||
PrintStream stdout) throws IOException {
|
||||
Person.Builder person = Person.newBuilder();
|
||||
|
||||
stdout.print("Enter person ID: ");
|
||||
person.setId(Integer.valueOf(stdin.readLine()));
|
||||
|
||||
stdout.print("Enter name: ");
|
||||
person.setName(stdin.readLine());
|
||||
|
||||
stdout.print("Enter email address (blank for none): ");
|
||||
String email = stdin.readLine();
|
||||
if (email.length() > 0) {
|
||||
person.setEmail(email);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
stdout.print("Enter a phone number (or leave blank to finish): ");
|
||||
String number = stdin.readLine();
|
||||
if (number.length() == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
Person.PhoneNumber.Builder phoneNumber =
|
||||
Person.PhoneNumber.newBuilder().setNumber(number);
|
||||
|
||||
stdout.print("Is this a mobile, home, or work phone? ");
|
||||
String type = stdin.readLine();
|
||||
if (type.equals("mobile")) {
|
||||
phoneNumber.setType(Person.PhoneType.MOBILE);
|
||||
} else if (type.equals("home")) {
|
||||
phoneNumber.setType(Person.PhoneType.HOME);
|
||||
} else if (type.equals("work")) {
|
||||
phoneNumber.setType(Person.PhoneType.WORK);
|
||||
} else {
|
||||
stdout.println("Unknown phone type. Using default.");
|
||||
}
|
||||
|
||||
person.addPhone(phoneNumber);
|
||||
}
|
||||
|
||||
return person.build();
|
||||
}
|
||||
|
||||
// Main function: Reads the entire address book from a file,
|
||||
// adds one person based on user input, then writes it back out to the same
|
||||
// file.
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 1) {
|
||||
System.err.println("Usage: AddPerson ADDRESS_BOOK_FILE");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
AddressBook.Builder addressBook = AddressBook.newBuilder();
|
||||
|
||||
// Read the existing address book.
|
||||
try {
|
||||
FileInputStream input = new FileInputStream(args[0]);
|
||||
try {
|
||||
addressBook.mergeFrom(input);
|
||||
} finally {
|
||||
try { input.close(); } catch (Throwable ignore) {}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println(args[0] + ": File not found. Creating a new file.");
|
||||
}
|
||||
|
||||
// Add an address.
|
||||
addressBook.addPerson(
|
||||
PromptForAddress(new BufferedReader(new InputStreamReader(System.in)),
|
||||
System.out));
|
||||
|
||||
// Write the new address book back to disk.
|
||||
FileOutputStream output = new FileOutputStream(args[0]);
|
||||
try {
|
||||
addressBook.build().writeTo(output);
|
||||
} finally {
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
// See README.txt for information and build instructions.
|
||||
|
||||
import com.example.tutorial.AddressBookProtos.AddressBook;
|
||||
import com.example.tutorial.AddressBookProtos.Person;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
class ListPeople {
|
||||
// Iterates though all people in the AddressBook and prints info about them.
|
||||
static void Print(AddressBook addressBook) {
|
||||
for (Person person: addressBook.getPersonList()) {
|
||||
System.out.println("Person ID: " + person.getId());
|
||||
System.out.println(" Name: " + person.getName());
|
||||
if (person.hasEmail()) {
|
||||
System.out.println(" E-mail address: " + person.getEmail());
|
||||
}
|
||||
|
||||
for (Person.PhoneNumber phoneNumber : person.getPhoneList()) {
|
||||
switch (phoneNumber.getType()) {
|
||||
case MOBILE:
|
||||
System.out.print(" Mobile phone #: ");
|
||||
break;
|
||||
case HOME:
|
||||
System.out.print(" Home phone #: ");
|
||||
break;
|
||||
case WORK:
|
||||
System.out.print(" Work phone #: ");
|
||||
break;
|
||||
}
|
||||
System.out.println(phoneNumber.getNumber());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Main function: Reads the entire address book from a file and prints all
|
||||
// the information inside.
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 1) {
|
||||
System.err.println("Usage: ListPeople ADDRESS_BOOK_FILE");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
// Read the existing address book.
|
||||
AddressBook addressBook =
|
||||
AddressBook.parseFrom(new FileInputStream(args[0]));
|
||||
|
||||
Print(addressBook);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
# See README.txt.
|
||||
|
||||
.PHONY: all cpp java python clean
|
||||
|
||||
all: cpp java python
|
||||
|
||||
cpp: add_person_cpp list_people_cpp
|
||||
java: add_person_java list_people_java
|
||||
python: add_person_python list_people_python
|
||||
|
||||
clean:
|
||||
rm -f add_person_cpp list_people_cpp add_person_java list_people_java add_person_python list_people_python
|
||||
rm -f javac_middleman AddPerson*.class ListPeople*.class com/example/tutorial/*.class
|
||||
rm -f protoc_middleman addressbook.pb.cc addressbook.pb.h addressbook_pb2.py com/example/tutorial/AddressBookProtos.java
|
||||
rm -f *.pyc
|
||||
rmdir com/example/tutorial 2>/dev/null || true
|
||||
rmdir com/example 2>/dev/null || true
|
||||
rmdir com 2>/dev/null || true
|
||||
|
||||
protoc_middleman: addressbook.proto
|
||||
protoc --cpp_out=. --java_out=. --python_out=. addressbook.proto
|
||||
@touch protoc_middleman
|
||||
|
||||
add_person_cpp: add_person.cc protoc_middleman
|
||||
pkg-config --cflags protobuf # fails if protobuf is not installed
|
||||
c++ add_person.cc addressbook.pb.cc -o add_person_cpp `pkg-config --cflags --libs protobuf`
|
||||
|
||||
list_people_cpp: list_people.cc protoc_middleman
|
||||
pkg-config --cflags protobuf # fails if protobuf is not installed
|
||||
c++ list_people.cc addressbook.pb.cc -o list_people_cpp `pkg-config --cflags --libs protobuf`
|
||||
|
||||
javac_middleman: AddPerson.java ListPeople.java protoc_middleman
|
||||
javac AddPerson.java ListPeople.java com/example/tutorial/AddressBookProtos.java
|
||||
@touch javac_middleman
|
||||
|
||||
add_person_java: javac_middleman
|
||||
@echo "Writing shortcut script add_person_java..."
|
||||
@echo '#! /bin/sh' > add_person_java
|
||||
@echo 'java -classpath .:$$CLASSPATH AddPerson "$$@"' >> add_person_java
|
||||
@chmod +x add_person_java
|
||||
|
||||
list_people_java: javac_middleman
|
||||
@echo "Writing shortcut script list_people_java..."
|
||||
@echo '#! /bin/sh' > list_people_java
|
||||
@echo 'java -classpath .:$$CLASSPATH ListPeople "$$@"' >> list_people_java
|
||||
@chmod +x list_people_java
|
||||
|
||||
add_person_python: add_person.py protoc_middleman
|
||||
@echo "Writing shortcut script add_person_python..."
|
||||
@echo '#! /bin/sh' > add_person_python
|
||||
@echo './add_person.py "$$@"' >> add_person_python
|
||||
@chmod +x add_person_python
|
||||
|
||||
list_people_python: list_people.py protoc_middleman
|
||||
@echo "Writing shortcut script list_people_python..."
|
||||
@echo '#! /bin/sh' > list_people_python
|
||||
@echo './list_people.py "$$@"' >> list_people_python
|
||||
@chmod +x list_people_python
|
||||
@@ -1,29 +0,0 @@
|
||||
This directory contains example code that uses Protocol Buffers to manage an
|
||||
address book. Two programs are provided, each with three different
|
||||
implementations, one written in each of C++, Java, and Python. The add_person
|
||||
example adds a new person to an address book, prompting the user to input
|
||||
the person's information. The list_people example lists people already in the
|
||||
address book. The examples use the exact same format in all three languages,
|
||||
so you can, for example, use add_person_java to create an address book and then
|
||||
use list_people_python to read it.
|
||||
|
||||
You must install the protobuf package before you can build these.
|
||||
|
||||
To build all the examples (on a unix-like system), simply run "make". This
|
||||
creates the following executable files in the current directory:
|
||||
add_person_cpp list_people_cpp
|
||||
add_person_java list_people_java
|
||||
add_person_python list_people_python
|
||||
|
||||
If you only want to compile examples in one language, use "make cpp"*,
|
||||
"make java", or "make python".
|
||||
|
||||
All of these programs simply take an address book file as their parameter.
|
||||
The add_person programs will create the file if it doesn't already exist.
|
||||
|
||||
These examples are part of the Protocol Buffers tutorial, located at:
|
||||
http://code.google.com/apis/protocolbuffers/docs/tutorials.html
|
||||
|
||||
* Note that on some platforms you may have to edit the Makefile and remove
|
||||
"-lpthread" from the linker commands (perhaps replacing it with something else).
|
||||
We didn't do this automatically because we wanted to keep the example simple.
|
||||
@@ -1,95 +0,0 @@
|
||||
// See README.txt for information and build instructions.
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include "addressbook.pb.h"
|
||||
using namespace std;
|
||||
|
||||
// This function fills in a Person message based on user input.
|
||||
void PromptForAddress(tutorial::Person* person) {
|
||||
cout << "Enter person ID number: ";
|
||||
int id;
|
||||
cin >> id;
|
||||
person->set_id(id);
|
||||
cin.ignore(256, '\n');
|
||||
|
||||
cout << "Enter name: ";
|
||||
getline(cin, *person->mutable_name());
|
||||
|
||||
cout << "Enter email address (blank for none): ";
|
||||
string email;
|
||||
getline(cin, email);
|
||||
if (!email.empty()) {
|
||||
person->set_email(email);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
cout << "Enter a phone number (or leave blank to finish): ";
|
||||
string number;
|
||||
getline(cin, number);
|
||||
if (number.empty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
tutorial::Person::PhoneNumber* phone_number = person->add_phone();
|
||||
phone_number->set_number(number);
|
||||
|
||||
cout << "Is this a mobile, home, or work phone? ";
|
||||
string type;
|
||||
getline(cin, type);
|
||||
if (type == "mobile") {
|
||||
phone_number->set_type(tutorial::Person::MOBILE);
|
||||
} else if (type == "home") {
|
||||
phone_number->set_type(tutorial::Person::HOME);
|
||||
} else if (type == "work") {
|
||||
phone_number->set_type(tutorial::Person::WORK);
|
||||
} else {
|
||||
cout << "Unknown phone type. Using default." << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Main function: Reads the entire address book from a file,
|
||||
// adds one person based on user input, then writes it back out to the same
|
||||
// file.
|
||||
int main(int argc, char* argv[]) {
|
||||
// Verify that the version of the library that we linked against is
|
||||
// compatible with the version of the headers we compiled against.
|
||||
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
||||
|
||||
if (argc != 2) {
|
||||
cerr << "Usage: " << argv[0] << " ADDRESS_BOOK_FILE" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tutorial::AddressBook address_book;
|
||||
|
||||
{
|
||||
// Read the existing address book.
|
||||
fstream input(argv[1], ios::in | ios::binary);
|
||||
if (!input) {
|
||||
cout << argv[1] << ": File not found. Creating a new file." << endl;
|
||||
} else if (!address_book.ParseFromIstream(&input)) {
|
||||
cerr << "Failed to parse address book." << endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Add an address.
|
||||
PromptForAddress(address_book.add_person());
|
||||
|
||||
{
|
||||
// Write the new address book back to disk.
|
||||
fstream output(argv[1], ios::out | ios::trunc | ios::binary);
|
||||
if (!address_book.SerializeToOstream(&output)) {
|
||||
cerr << "Failed to write address book." << endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Optional: Delete all global objects allocated by libprotobuf.
|
||||
google::protobuf::ShutdownProtobufLibrary();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
#! /usr/bin/python
|
||||
|
||||
# See README.txt for information and build instructions.
|
||||
|
||||
import addressbook_pb2
|
||||
import sys
|
||||
|
||||
# This function fills in a Person message based on user input.
|
||||
def PromptForAddress(person):
|
||||
person.id = int(raw_input("Enter person ID number: "))
|
||||
person.name = raw_input("Enter name: ")
|
||||
|
||||
email = raw_input("Enter email address (blank for none): ")
|
||||
if email != "":
|
||||
person.email = email
|
||||
|
||||
while True:
|
||||
number = raw_input("Enter a phone number (or leave blank to finish): ")
|
||||
if number == "":
|
||||
break
|
||||
|
||||
phone_number = person.phone.add()
|
||||
phone_number.number = number
|
||||
|
||||
type = raw_input("Is this a mobile, home, or work phone? ")
|
||||
if type == "mobile":
|
||||
phone_number.type = addressbook_pb2.Person.MOBILE
|
||||
elif type == "home":
|
||||
phone_number.type = addressbook_pb2.Person.HOME
|
||||
elif type == "work":
|
||||
phone_number.type = addressbook_pb2.Person.WORK
|
||||
else:
|
||||
print "Unknown phone type; leaving as default value."
|
||||
|
||||
# Main procedure: Reads the entire address book from a file,
|
||||
# adds one person based on user input, then writes it back out to the same
|
||||
# file.
|
||||
if len(sys.argv) != 2:
|
||||
print "Usage:", sys.argv[0], "ADDRESS_BOOK_FILE"
|
||||
sys.exit(-1)
|
||||
|
||||
address_book = addressbook_pb2.AddressBook()
|
||||
|
||||
# Read the existing address book.
|
||||
try:
|
||||
f = open(sys.argv[1], "rb")
|
||||
address_book.ParseFromString(f.read())
|
||||
f.close()
|
||||
except IOError:
|
||||
print sys.argv[1] + ": File not found. Creating a new file."
|
||||
|
||||
# Add an address.
|
||||
PromptForAddress(address_book.person.add())
|
||||
|
||||
# Write the new address book back to disk.
|
||||
f = open(sys.argv[1], "wb")
|
||||
f.write(address_book.SerializeToString())
|
||||
f.close()
|
||||
@@ -1,30 +0,0 @@
|
||||
// See README.txt for information and build instructions.
|
||||
|
||||
package tutorial;
|
||||
|
||||
option java_package = "com.example.tutorial";
|
||||
option java_outer_classname = "AddressBookProtos";
|
||||
|
||||
message Person {
|
||||
required string name = 1;
|
||||
required int32 id = 2; // Unique ID number for this person.
|
||||
optional string email = 3;
|
||||
|
||||
enum PhoneType {
|
||||
MOBILE = 0;
|
||||
HOME = 1;
|
||||
WORK = 2;
|
||||
}
|
||||
|
||||
message PhoneNumber {
|
||||
required string number = 1;
|
||||
optional PhoneType type = 2 [default = HOME];
|
||||
}
|
||||
|
||||
repeated PhoneNumber phone = 4;
|
||||
}
|
||||
|
||||
// Our address book file is just one of these.
|
||||
message AddressBook {
|
||||
repeated Person person = 1;
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
// See README.txt for information and build instructions.
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include "addressbook.pb.h"
|
||||
using namespace std;
|
||||
|
||||
// Iterates though all people in the AddressBook and prints info about them.
|
||||
void ListPeople(const tutorial::AddressBook& address_book) {
|
||||
for (int i = 0; i < address_book.person_size(); i++) {
|
||||
const tutorial::Person& person = address_book.person(i);
|
||||
|
||||
cout << "Person ID: " << person.id() << endl;
|
||||
cout << " Name: " << person.name() << endl;
|
||||
if (person.has_email()) {
|
||||
cout << " E-mail address: " << person.email() << endl;
|
||||
}
|
||||
|
||||
for (int j = 0; j < person.phone_size(); j++) {
|
||||
const tutorial::Person::PhoneNumber& phone_number = person.phone(j);
|
||||
|
||||
switch (phone_number.type()) {
|
||||
case tutorial::Person::MOBILE:
|
||||
cout << " Mobile phone #: ";
|
||||
break;
|
||||
case tutorial::Person::HOME:
|
||||
cout << " Home phone #: ";
|
||||
break;
|
||||
case tutorial::Person::WORK:
|
||||
cout << " Work phone #: ";
|
||||
break;
|
||||
}
|
||||
cout << phone_number.number() << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Main function: Reads the entire address book from a file and prints all
|
||||
// the information inside.
|
||||
int main(int argc, char* argv[]) {
|
||||
// Verify that the version of the library that we linked against is
|
||||
// compatible with the version of the headers we compiled against.
|
||||
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
||||
|
||||
if (argc != 2) {
|
||||
cerr << "Usage: " << argv[0] << " ADDRESS_BOOK_FILE" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tutorial::AddressBook address_book;
|
||||
|
||||
{
|
||||
// Read the existing address book.
|
||||
fstream input(argv[1], ios::in | ios::binary);
|
||||
if (!address_book.ParseFromIstream(&input)) {
|
||||
cerr << "Failed to parse address book." << endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
ListPeople(address_book);
|
||||
|
||||
// Optional: Delete all global objects allocated by libprotobuf.
|
||||
google::protobuf::ShutdownProtobufLibrary();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
#! /usr/bin/python
|
||||
|
||||
# See README.txt for information and build instructions.
|
||||
|
||||
import addressbook_pb2
|
||||
import sys
|
||||
|
||||
# Iterates though all people in the AddressBook and prints info about them.
|
||||
def ListPeople(address_book):
|
||||
for person in address_book.person:
|
||||
print "Person ID:", person.id
|
||||
print " Name:", person.name
|
||||
if person.HasField('email'):
|
||||
print " E-mail address:", person.email
|
||||
|
||||
for phone_number in person.phone:
|
||||
if phone_number.type == addressbook_pb2.Person.MOBILE:
|
||||
print " Mobile phone #:",
|
||||
elif phone_number.type == addressbook_pb2.Person.HOME:
|
||||
print " Home phone #:",
|
||||
elif phone_number.type == addressbook_pb2.Person.WORK:
|
||||
print " Work phone #:",
|
||||
print phone_number.number
|
||||
|
||||
# Main procedure: Reads the entire address book from a file and prints all
|
||||
# the information inside.
|
||||
if len(sys.argv) != 2:
|
||||
print "Usage:", sys.argv[0], "ADDRESS_BOOK_FILE"
|
||||
sys.exit(-1)
|
||||
|
||||
address_book = addressbook_pb2.AddressBook()
|
||||
|
||||
# Read the existing address book.
|
||||
f = open(sys.argv[1], "rb")
|
||||
address_book.ParseFromString(f.read())
|
||||
f.close()
|
||||
|
||||
ListPeople(address_book)
|
||||
@@ -1,33 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Run this script to regenerate descriptor.pb.{h,cc} after the protocol
|
||||
# compiler changes. Since these files are compiled into the protocol compiler
|
||||
# itself, they cannot be generated automatically by a make rule. "make check"
|
||||
# will fail if these files do not match what the protocol compiler would
|
||||
# generate.
|
||||
#
|
||||
# HINT: Flags passed to generate_descriptor_proto.sh will be passed directly
|
||||
# to make when building protoc. This is particularly useful for passing
|
||||
# -j4 to run 4 jobs simultaneously.
|
||||
|
||||
if test ! -e src/google/protobuf/stubs/common.h; then
|
||||
cat >&2 << __EOF__
|
||||
Could not find source code. Make sure you are running this script from the
|
||||
root of the distribution tree.
|
||||
__EOF__
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if test ! -e src/Makefile; then
|
||||
cat >&2 << __EOF__
|
||||
Could not find src/Makefile. You must run ./configure (and perhaps
|
||||
./autogen.sh) first.
|
||||
__EOF__
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd src
|
||||
make $@ protoc &&
|
||||
./protoc --cpp_out=dllexport_decl=LIBPROTOBUF_EXPORT:. google/protobuf/descriptor.proto && \
|
||||
./protoc --cpp_out=dllexport_decl=LIBPROTOC_EXPORT:. google/protobuf/compiler/plugin.proto
|
||||
cd ..
|
||||
@@ -1,130 +0,0 @@
|
||||
Changes for 1.6.0:
|
||||
|
||||
* New feature: ADD_FAILURE_AT() for reporting a test failure at the
|
||||
given source location -- useful for writing testing utilities.
|
||||
* New feature: the universal value printer is moved from Google Mock
|
||||
to Google Test.
|
||||
* New feature: type parameters and value parameters are reported in
|
||||
the XML report now.
|
||||
* A gtest_disable_pthreads CMake option.
|
||||
* Colored output works in GNU Screen sessions now.
|
||||
* Parameters of value-parameterized tests are now printed in the
|
||||
textual output.
|
||||
* Failures from ad hoc test assertions run before RUN_ALL_TESTS() are
|
||||
now correctly reported.
|
||||
* Arguments of ASSERT_XY and EXPECT_XY no longer need to support << to
|
||||
ostream.
|
||||
* More complete handling of exceptions.
|
||||
* GTEST_ASSERT_XY can be used instead of ASSERT_XY in case the latter
|
||||
name is already used by another library.
|
||||
* --gtest_catch_exceptions is now true by default, allowing a test
|
||||
program to continue after an exception is thrown.
|
||||
* Value-parameterized test fixtures can now derive from Test and
|
||||
WithParamInterface<T> separately, easing conversion of legacy tests.
|
||||
* Death test messages are clearly marked to make them more
|
||||
distinguishable from other messages.
|
||||
* Compatibility fixes for Android, Google Native Client, MinGW, HP UX,
|
||||
PowerPC, Lucid autotools, libCStd, Sun C++, Borland C++ Builder (Code Gear),
|
||||
IBM XL C++ (Visual Age C++), and C++0x.
|
||||
* Bug fixes and implementation clean-ups.
|
||||
* Potentially incompatible changes: disables the harmful 'make install'
|
||||
command in autotools.
|
||||
|
||||
Changes for 1.5.0:
|
||||
|
||||
* New feature: assertions can be safely called in multiple threads
|
||||
where the pthreads library is available.
|
||||
* New feature: predicates used inside EXPECT_TRUE() and friends
|
||||
can now generate custom failure messages.
|
||||
* New feature: Google Test can now be compiled as a DLL.
|
||||
* New feature: fused source files are included.
|
||||
* New feature: prints help when encountering unrecognized Google Test flags.
|
||||
* Experimental feature: CMake build script (requires CMake 2.6.4+).
|
||||
* Experimental feature: the Pump script for meta programming.
|
||||
* double values streamed to an assertion are printed with enough precision
|
||||
to differentiate any two different values.
|
||||
* Google Test now works on Solaris and AIX.
|
||||
* Build and test script improvements.
|
||||
* Bug fixes and implementation clean-ups.
|
||||
|
||||
Potentially breaking changes:
|
||||
|
||||
* Stopped supporting VC++ 7.1 with exceptions disabled.
|
||||
* Dropped support for 'make install'.
|
||||
|
||||
Changes for 1.4.0:
|
||||
|
||||
* New feature: the event listener API
|
||||
* New feature: test shuffling
|
||||
* New feature: the XML report format is closer to junitreport and can
|
||||
be parsed by Hudson now.
|
||||
* New feature: when a test runs under Visual Studio, its failures are
|
||||
integrated in the IDE.
|
||||
* New feature: /MD(d) versions of VC++ projects.
|
||||
* New feature: elapsed time for the tests is printed by default.
|
||||
* New feature: comes with a TR1 tuple implementation such that Boost
|
||||
is no longer needed for Combine().
|
||||
* New feature: EXPECT_DEATH_IF_SUPPORTED macro and friends.
|
||||
* New feature: the Xcode project can now produce static gtest
|
||||
libraries in addition to a framework.
|
||||
* Compatibility fixes for Solaris, Cygwin, minGW, Windows Mobile,
|
||||
Symbian, gcc, and C++Builder.
|
||||
* Bug fixes and implementation clean-ups.
|
||||
|
||||
Changes for 1.3.0:
|
||||
|
||||
* New feature: death tests on Windows, Cygwin, and Mac.
|
||||
* New feature: ability to use Google Test assertions in other testing
|
||||
frameworks.
|
||||
* New feature: ability to run disabled test via
|
||||
--gtest_also_run_disabled_tests.
|
||||
* New feature: the --help flag for printing the usage.
|
||||
* New feature: access to Google Test flag values in user code.
|
||||
* New feature: a script that packs Google Test into one .h and one
|
||||
.cc file for easy deployment.
|
||||
* New feature: support for distributing test functions to multiple
|
||||
machines (requires support from the test runner).
|
||||
* Bug fixes and implementation clean-ups.
|
||||
|
||||
Changes for 1.2.1:
|
||||
|
||||
* Compatibility fixes for Linux IA-64 and IBM z/OS.
|
||||
* Added support for using Boost and other TR1 implementations.
|
||||
* Changes to the build scripts to support upcoming release of Google C++
|
||||
Mocking Framework.
|
||||
* Added Makefile to the distribution package.
|
||||
* Improved build instructions in README.
|
||||
|
||||
Changes for 1.2.0:
|
||||
|
||||
* New feature: value-parameterized tests.
|
||||
* New feature: the ASSERT/EXPECT_(NON)FATAL_FAILURE(_ON_ALL_THREADS)
|
||||
macros.
|
||||
* Changed the XML report format to match JUnit/Ant's.
|
||||
* Added tests to the Xcode project.
|
||||
* Added scons/SConscript for building with SCons.
|
||||
* Added src/gtest-all.cc for building Google Test from a single file.
|
||||
* Fixed compatibility with Solaris and z/OS.
|
||||
* Enabled running Python tests on systems with python 2.3 installed,
|
||||
e.g. Mac OS X 10.4.
|
||||
* Bug fixes.
|
||||
|
||||
Changes for 1.1.0:
|
||||
|
||||
* New feature: type-parameterized tests.
|
||||
* New feature: exception assertions.
|
||||
* New feature: printing elapsed time of tests.
|
||||
* Improved the robustness of death tests.
|
||||
* Added an Xcode project and samples.
|
||||
* Adjusted the output format on Windows to be understandable by Visual Studio.
|
||||
* Minor bug fixes.
|
||||
|
||||
Changes for 1.0.1:
|
||||
|
||||
* Added project files for Visual Studio 7.1.
|
||||
* Fixed issues with compiling on Mac OS X.
|
||||
* Fixed issues with compiling on Cygwin.
|
||||
|
||||
Changes for 1.0.0:
|
||||
|
||||
* Initial Open Source release of Google Test
|
||||
@@ -1,250 +0,0 @@
|
||||
########################################################################
|
||||
# CMake build script for Google Test.
|
||||
#
|
||||
# To run the tests for Google Test itself on Linux, use 'make test' or
|
||||
# ctest. You can select which tests to run using 'ctest -R regex'.
|
||||
# For more options, run 'ctest --help'.
|
||||
|
||||
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
|
||||
# make it prominent in the GUI.
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
|
||||
|
||||
# When other libraries are using a shared version of runtime libraries,
|
||||
# Google Test also has to use one.
|
||||
option(
|
||||
gtest_force_shared_crt
|
||||
"Use shared (DLL) run-time lib even when Google Test is built as static lib."
|
||||
OFF)
|
||||
|
||||
option(gtest_build_tests "Build all of gtest's own tests." OFF)
|
||||
|
||||
option(gtest_build_samples "Build gtest's sample programs." OFF)
|
||||
|
||||
option(gtest_disable_pthreads "Disable uses of pthreads in gtest." OFF)
|
||||
|
||||
# Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
|
||||
include(cmake/hermetic_build.cmake OPTIONAL)
|
||||
|
||||
if (COMMAND pre_project_set_up_hermetic_build)
|
||||
pre_project_set_up_hermetic_build()
|
||||
endif()
|
||||
|
||||
########################################################################
|
||||
#
|
||||
# Project-wide settings
|
||||
|
||||
# Name of the project.
|
||||
#
|
||||
# CMake files in this project can refer to the root source directory
|
||||
# as ${gtest_SOURCE_DIR} and to the root binary directory as
|
||||
# ${gtest_BINARY_DIR}.
|
||||
# Language "C" is required for find_package(Threads).
|
||||
project(gtest CXX C)
|
||||
cmake_minimum_required(VERSION 2.6.2)
|
||||
|
||||
if (COMMAND set_up_hermetic_build)
|
||||
set_up_hermetic_build()
|
||||
endif()
|
||||
|
||||
# Define helper functions and macros used by Google Test.
|
||||
include(cmake/internal_utils.cmake)
|
||||
|
||||
config_compiler_and_linker() # Defined in internal_utils.cmake.
|
||||
|
||||
# Where Google Test's .h files can be found.
|
||||
include_directories(
|
||||
${gtest_SOURCE_DIR}/include
|
||||
${gtest_SOURCE_DIR})
|
||||
|
||||
# Where Google Test's libraries can be found.
|
||||
link_directories(${gtest_BINARY_DIR}/src)
|
||||
|
||||
########################################################################
|
||||
#
|
||||
# Defines the gtest & gtest_main libraries. User tests should link
|
||||
# with one of them.
|
||||
|
||||
# Google Test libraries. We build them using more strict warnings than what
|
||||
# are used for other targets, to ensure that gtest can be compiled by a user
|
||||
# aggressive about warnings.
|
||||
cxx_library(gtest "${cxx_strict}" src/gtest-all.cc)
|
||||
cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc)
|
||||
target_link_libraries(gtest_main gtest)
|
||||
|
||||
########################################################################
|
||||
#
|
||||
# Samples on how to link user tests with gtest or gtest_main.
|
||||
#
|
||||
# They are not built by default. To build them, set the
|
||||
# gtest_build_samples option to ON. You can do it by running ccmake
|
||||
# or specifying the -Dbuild_gtest_samples=ON flag when running cmake.
|
||||
|
||||
if (gtest_build_samples)
|
||||
cxx_executable(sample1_unittest samples gtest_main samples/sample1.cc)
|
||||
cxx_executable(sample2_unittest samples gtest_main samples/sample2.cc)
|
||||
cxx_executable(sample3_unittest samples gtest_main)
|
||||
cxx_executable(sample4_unittest samples gtest_main samples/sample4.cc)
|
||||
cxx_executable(sample5_unittest samples gtest_main samples/sample1.cc)
|
||||
cxx_executable(sample6_unittest samples gtest_main)
|
||||
cxx_executable(sample7_unittest samples gtest_main)
|
||||
cxx_executable(sample8_unittest samples gtest_main)
|
||||
cxx_executable(sample9_unittest samples gtest)
|
||||
cxx_executable(sample10_unittest samples gtest)
|
||||
endif()
|
||||
|
||||
########################################################################
|
||||
#
|
||||
# Google Test's own tests.
|
||||
#
|
||||
# You can skip this section if you aren't interested in testing
|
||||
# Google Test itself.
|
||||
#
|
||||
# The tests are not built by default. To build them, set the
|
||||
# gtest_build_tests option to ON. You can do it by running ccmake
|
||||
# or specifying the -Dgtest_build_tests=ON flag when running cmake.
|
||||
|
||||
if (gtest_build_tests)
|
||||
# This must be set in the root directory for the tests to be run by
|
||||
# 'make test' or ctest.
|
||||
enable_testing()
|
||||
|
||||
############################################################
|
||||
# C++ tests built with standard compiler flags.
|
||||
|
||||
cxx_test(gtest-death-test_test gtest_main)
|
||||
cxx_test(gtest_environment_test gtest)
|
||||
cxx_test(gtest-filepath_test gtest_main)
|
||||
cxx_test(gtest-linked_ptr_test gtest_main)
|
||||
cxx_test(gtest-listener_test gtest_main)
|
||||
cxx_test(gtest_main_unittest gtest_main)
|
||||
cxx_test(gtest-message_test gtest_main)
|
||||
cxx_test(gtest_no_test_unittest gtest)
|
||||
cxx_test(gtest-options_test gtest_main)
|
||||
cxx_test(gtest-param-test_test gtest
|
||||
test/gtest-param-test2_test.cc)
|
||||
cxx_test(gtest-port_test gtest_main)
|
||||
cxx_test(gtest_pred_impl_unittest gtest_main)
|
||||
cxx_test(gtest-printers_test gtest_main)
|
||||
cxx_test(gtest_prod_test gtest_main
|
||||
test/production.cc)
|
||||
cxx_test(gtest_repeat_test gtest)
|
||||
cxx_test(gtest_sole_header_test gtest_main)
|
||||
cxx_test(gtest_stress_test gtest)
|
||||
cxx_test(gtest-test-part_test gtest_main)
|
||||
cxx_test(gtest_throw_on_failure_ex_test gtest)
|
||||
cxx_test(gtest-typed-test_test gtest_main
|
||||
test/gtest-typed-test2_test.cc)
|
||||
cxx_test(gtest_unittest gtest_main)
|
||||
cxx_test(gtest-unittest-api_test gtest)
|
||||
|
||||
############################################################
|
||||
# C++ tests built with non-standard compiler flags.
|
||||
|
||||
# MSVC 7.1 does not support STL with exceptions disabled.
|
||||
if (NOT MSVC OR MSVC_VERSION GREATER 1310)
|
||||
cxx_library(gtest_no_exception "${cxx_no_exception}"
|
||||
src/gtest-all.cc)
|
||||
cxx_library(gtest_main_no_exception "${cxx_no_exception}"
|
||||
src/gtest-all.cc src/gtest_main.cc)
|
||||
endif()
|
||||
cxx_library(gtest_main_no_rtti "${cxx_no_rtti}"
|
||||
src/gtest-all.cc src/gtest_main.cc)
|
||||
|
||||
cxx_test_with_flags(gtest-death-test_ex_nocatch_test
|
||||
"${cxx_exception} -DGTEST_ENABLE_CATCH_EXCEPTIONS_=0"
|
||||
gtest test/gtest-death-test_ex_test.cc)
|
||||
cxx_test_with_flags(gtest-death-test_ex_catch_test
|
||||
"${cxx_exception} -DGTEST_ENABLE_CATCH_EXCEPTIONS_=1"
|
||||
gtest test/gtest-death-test_ex_test.cc)
|
||||
|
||||
cxx_test_with_flags(gtest_no_rtti_unittest "${cxx_no_rtti}"
|
||||
gtest_main_no_rtti test/gtest_unittest.cc)
|
||||
|
||||
cxx_shared_library(gtest_dll "${cxx_default}"
|
||||
src/gtest-all.cc src/gtest_main.cc)
|
||||
|
||||
cxx_executable_with_flags(gtest_dll_test_ "${cxx_default}"
|
||||
gtest_dll test/gtest_all_test.cc)
|
||||
set_target_properties(gtest_dll_test_
|
||||
PROPERTIES
|
||||
COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
|
||||
|
||||
if (NOT MSVC OR NOT MSVC_VERSION EQUAL 1600)
|
||||
# The C++ Standard specifies tuple_element<int, class>.
|
||||
# Yet MSVC 10's <utility> declares tuple_element<size_t, class>.
|
||||
# That declaration conflicts with our own standard-conforming
|
||||
# tuple implementation. Therefore using our own tuple with
|
||||
# MSVC 10 doesn't compile.
|
||||
cxx_library(gtest_main_use_own_tuple "${cxx_use_own_tuple}"
|
||||
src/gtest-all.cc src/gtest_main.cc)
|
||||
|
||||
cxx_test_with_flags(gtest-tuple_test "${cxx_use_own_tuple}"
|
||||
gtest_main_use_own_tuple test/gtest-tuple_test.cc)
|
||||
|
||||
cxx_test_with_flags(gtest_use_own_tuple_test "${cxx_use_own_tuple}"
|
||||
gtest_main_use_own_tuple
|
||||
test/gtest-param-test_test.cc test/gtest-param-test2_test.cc)
|
||||
endif()
|
||||
|
||||
############################################################
|
||||
# Python tests.
|
||||
|
||||
cxx_executable(gtest_break_on_failure_unittest_ test gtest)
|
||||
py_test(gtest_break_on_failure_unittest)
|
||||
|
||||
# MSVC 7.1 does not support STL with exceptions disabled.
|
||||
if (NOT MSVC OR MSVC_VERSION GREATER 1310)
|
||||
cxx_executable_with_flags(
|
||||
gtest_catch_exceptions_no_ex_test_
|
||||
"${cxx_no_exception}"
|
||||
gtest_main_no_exception
|
||||
test/gtest_catch_exceptions_test_.cc)
|
||||
endif()
|
||||
|
||||
cxx_executable_with_flags(
|
||||
gtest_catch_exceptions_ex_test_
|
||||
"${cxx_exception}"
|
||||
gtest_main
|
||||
test/gtest_catch_exceptions_test_.cc)
|
||||
py_test(gtest_catch_exceptions_test)
|
||||
|
||||
cxx_executable(gtest_color_test_ test gtest)
|
||||
py_test(gtest_color_test)
|
||||
|
||||
cxx_executable(gtest_env_var_test_ test gtest)
|
||||
py_test(gtest_env_var_test)
|
||||
|
||||
cxx_executable(gtest_filter_unittest_ test gtest)
|
||||
py_test(gtest_filter_unittest)
|
||||
|
||||
cxx_executable(gtest_help_test_ test gtest_main)
|
||||
py_test(gtest_help_test)
|
||||
|
||||
cxx_executable(gtest_list_tests_unittest_ test gtest)
|
||||
py_test(gtest_list_tests_unittest)
|
||||
|
||||
cxx_executable(gtest_output_test_ test gtest)
|
||||
py_test(gtest_output_test)
|
||||
|
||||
cxx_executable(gtest_shuffle_test_ test gtest)
|
||||
py_test(gtest_shuffle_test)
|
||||
|
||||
# MSVC 7.1 does not support STL with exceptions disabled.
|
||||
if (NOT MSVC OR MSVC_VERSION GREATER 1310)
|
||||
cxx_executable(gtest_throw_on_failure_test_ test gtest_no_exception)
|
||||
set_target_properties(gtest_throw_on_failure_test_
|
||||
PROPERTIES
|
||||
COMPILE_FLAGS "${cxx_no_exception}")
|
||||
py_test(gtest_throw_on_failure_test)
|
||||
endif()
|
||||
|
||||
cxx_executable(gtest_uninitialized_test_ test gtest)
|
||||
py_test(gtest_uninitialized_test)
|
||||
|
||||
cxx_executable(gtest_xml_outfile1_test_ test gtest_main)
|
||||
cxx_executable(gtest_xml_outfile2_test_ test gtest_main)
|
||||
py_test(gtest_xml_outfiles_test)
|
||||
|
||||
cxx_executable(gtest_xml_output_unittest_ test gtest)
|
||||
py_test(gtest_xml_output_unittest)
|
||||
endif()
|
||||
@@ -1,37 +0,0 @@
|
||||
# This file contains a list of people who've made non-trivial
|
||||
# contribution to the Google C++ Testing Framework project. People
|
||||
# who commit code to the project are encouraged to add their names
|
||||
# here. Please keep the list sorted by first names.
|
||||
|
||||
Ajay Joshi <[email protected]>
|
||||
Balázs Dán <[email protected]>
|
||||
Bharat Mediratta <[email protected]>
|
||||
Chandler Carruth <[email protected]>
|
||||
Chris Prince <[email protected]>
|
||||
Chris Taylor <[email protected]>
|
||||
Dan Egnor <[email protected]>
|
||||
Eric Roman <[email protected]>
|
||||
Hady Zalek <[email protected]>
|
||||
Jeffrey Yasskin <[email protected]>
|
||||
Jói Sigurðsson <[email protected]>
|
||||
Keir Mierle <[email protected]>
|
||||
Keith Ray <[email protected]>
|
||||
Kenton Varda <[email protected]>
|
||||
Manuel Klimek <[email protected]>
|
||||
Markus Heule <[email protected]>
|
||||
Mika Raento <[email protected]>
|
||||
Miklós Fazekas <[email protected]>
|
||||
Pasi Valminen <[email protected]>
|
||||
Patrick Hanna <[email protected]>
|
||||
Patrick Riley <[email protected]>
|
||||
Peter Kaminski <[email protected]>
|
||||
Preston Jackson <[email protected]>
|
||||
Rainer Klaffenboeck <[email protected]>
|
||||
Russ Cox <[email protected]>
|
||||
Russ Rufer <[email protected]>
|
||||
Sean Mcafee <[email protected]>
|
||||
Sigurður Ásgeirsson <[email protected]>
|
||||
Tracy Bialik <[email protected]>
|
||||
Vadim Berman <[email protected]>
|
||||
Vlad Losev <[email protected]>
|
||||
Zhanyong Wan <[email protected]>
|
||||
@@ -1,28 +0,0 @@
|
||||
Copyright 2008, Google Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -1,305 +0,0 @@
|
||||
# Automake file
|
||||
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
# Nonstandard package files for distribution
|
||||
EXTRA_DIST = \
|
||||
CHANGES \
|
||||
CONTRIBUTORS \
|
||||
LICENSE \
|
||||
include/gtest/gtest-param-test.h.pump \
|
||||
include/gtest/internal/gtest-param-util-generated.h.pump \
|
||||
include/gtest/internal/gtest-tuple.h.pump \
|
||||
include/gtest/internal/gtest-type-util.h.pump \
|
||||
make/Makefile \
|
||||
scripts/fuse_gtest_files.py \
|
||||
scripts/gen_gtest_pred_impl.py \
|
||||
scripts/pump.py \
|
||||
scripts/test/Makefile
|
||||
|
||||
# gtest source files that we don't compile directly. They are
|
||||
# #included by gtest-all.cc.
|
||||
GTEST_SRC = \
|
||||
src/gtest-death-test.cc \
|
||||
src/gtest-filepath.cc \
|
||||
src/gtest-internal-inl.h \
|
||||
src/gtest-port.cc \
|
||||
src/gtest-printers.cc \
|
||||
src/gtest-test-part.cc \
|
||||
src/gtest-typed-test.cc \
|
||||
src/gtest.cc
|
||||
|
||||
EXTRA_DIST += $(GTEST_SRC)
|
||||
|
||||
# Sample files that we don't compile.
|
||||
EXTRA_DIST += \
|
||||
samples/prime_tables.h \
|
||||
samples/sample2_unittest.cc \
|
||||
samples/sample3_unittest.cc \
|
||||
samples/sample4_unittest.cc \
|
||||
samples/sample5_unittest.cc \
|
||||
samples/sample6_unittest.cc \
|
||||
samples/sample7_unittest.cc \
|
||||
samples/sample8_unittest.cc \
|
||||
samples/sample9_unittest.cc
|
||||
|
||||
# C++ test files that we don't compile directly.
|
||||
EXTRA_DIST += \
|
||||
test/gtest-death-test_ex_test.cc \
|
||||
test/gtest-death-test_test.cc \
|
||||
test/gtest-filepath_test.cc \
|
||||
test/gtest-linked_ptr_test.cc \
|
||||
test/gtest-listener_test.cc \
|
||||
test/gtest-message_test.cc \
|
||||
test/gtest-options_test.cc \
|
||||
test/gtest-param-test2_test.cc \
|
||||
test/gtest-param-test2_test.cc \
|
||||
test/gtest-param-test_test.cc \
|
||||
test/gtest-param-test_test.cc \
|
||||
test/gtest-param-test_test.h \
|
||||
test/gtest-port_test.cc \
|
||||
test/gtest-printers_test.cc \
|
||||
test/gtest-test-part_test.cc \
|
||||
test/gtest-tuple_test.cc \
|
||||
test/gtest-typed-test2_test.cc \
|
||||
test/gtest-typed-test_test.cc \
|
||||
test/gtest-typed-test_test.h \
|
||||
test/gtest-unittest-api_test.cc \
|
||||
test/gtest_break_on_failure_unittest_.cc \
|
||||
test/gtest_catch_exceptions_test_.cc \
|
||||
test/gtest_color_test_.cc \
|
||||
test/gtest_env_var_test_.cc \
|
||||
test/gtest_environment_test.cc \
|
||||
test/gtest_filter_unittest_.cc \
|
||||
test/gtest_help_test_.cc \
|
||||
test/gtest_list_tests_unittest_.cc \
|
||||
test/gtest_main_unittest.cc \
|
||||
test/gtest_no_test_unittest.cc \
|
||||
test/gtest_output_test_.cc \
|
||||
test/gtest_pred_impl_unittest.cc \
|
||||
test/gtest_prod_test.cc \
|
||||
test/gtest_repeat_test.cc \
|
||||
test/gtest_shuffle_test_.cc \
|
||||
test/gtest_sole_header_test.cc \
|
||||
test/gtest_stress_test.cc \
|
||||
test/gtest_throw_on_failure_ex_test.cc \
|
||||
test/gtest_throw_on_failure_test_.cc \
|
||||
test/gtest_uninitialized_test_.cc \
|
||||
test/gtest_unittest.cc \
|
||||
test/gtest_unittest.cc \
|
||||
test/gtest_xml_outfile1_test_.cc \
|
||||
test/gtest_xml_outfile2_test_.cc \
|
||||
test/gtest_xml_output_unittest_.cc \
|
||||
test/production.cc \
|
||||
test/production.h
|
||||
|
||||
# Python tests that we don't run.
|
||||
EXTRA_DIST += \
|
||||
test/gtest_break_on_failure_unittest.py \
|
||||
test/gtest_catch_exceptions_test.py \
|
||||
test/gtest_color_test.py \
|
||||
test/gtest_env_var_test.py \
|
||||
test/gtest_filter_unittest.py \
|
||||
test/gtest_help_test.py \
|
||||
test/gtest_list_tests_unittest.py \
|
||||
test/gtest_output_test.py \
|
||||
test/gtest_output_test_golden_lin.txt \
|
||||
test/gtest_shuffle_test.py \
|
||||
test/gtest_test_utils.py \
|
||||
test/gtest_throw_on_failure_test.py \
|
||||
test/gtest_uninitialized_test.py \
|
||||
test/gtest_xml_outfiles_test.py \
|
||||
test/gtest_xml_output_unittest.py \
|
||||
test/gtest_xml_test_utils.py
|
||||
|
||||
# CMake script
|
||||
EXTRA_DIST += \
|
||||
CMakeLists.txt \
|
||||
cmake/internal_utils.cmake
|
||||
|
||||
# MSVC project files
|
||||
EXTRA_DIST += \
|
||||
msvc/gtest-md.sln \
|
||||
msvc/gtest-md.vcproj \
|
||||
msvc/gtest.sln \
|
||||
msvc/gtest.vcproj \
|
||||
msvc/gtest_main-md.vcproj \
|
||||
msvc/gtest_main.vcproj \
|
||||
msvc/gtest_prod_test-md.vcproj \
|
||||
msvc/gtest_prod_test.vcproj \
|
||||
msvc/gtest_unittest-md.vcproj \
|
||||
msvc/gtest_unittest.vcproj
|
||||
|
||||
# xcode project files
|
||||
EXTRA_DIST += \
|
||||
xcode/Config/DebugProject.xcconfig \
|
||||
xcode/Config/FrameworkTarget.xcconfig \
|
||||
xcode/Config/General.xcconfig \
|
||||
xcode/Config/ReleaseProject.xcconfig \
|
||||
xcode/Config/StaticLibraryTarget.xcconfig \
|
||||
xcode/Config/TestTarget.xcconfig \
|
||||
xcode/Resources/Info.plist \
|
||||
xcode/Scripts/runtests.sh \
|
||||
xcode/Scripts/versiongenerate.py \
|
||||
xcode/gtest.xcodeproj/project.pbxproj
|
||||
|
||||
# xcode sample files
|
||||
EXTRA_DIST += \
|
||||
xcode/Samples/FrameworkSample/Info.plist \
|
||||
xcode/Samples/FrameworkSample/WidgetFramework.xcodeproj/project.pbxproj \
|
||||
xcode/Samples/FrameworkSample/runtests.sh \
|
||||
xcode/Samples/FrameworkSample/widget.cc \
|
||||
xcode/Samples/FrameworkSample/widget.h \
|
||||
xcode/Samples/FrameworkSample/widget_test.cc
|
||||
|
||||
# C++Builder project files
|
||||
EXTRA_DIST += \
|
||||
codegear/gtest.cbproj \
|
||||
codegear/gtest.groupproj \
|
||||
codegear/gtest_all.cc \
|
||||
codegear/gtest_link.cc \
|
||||
codegear/gtest_main.cbproj \
|
||||
codegear/gtest_unittest.cbproj
|
||||
|
||||
# Distribute and install M4 macro
|
||||
m4datadir = $(datadir)/aclocal
|
||||
m4data_DATA = m4/gtest.m4
|
||||
EXTRA_DIST += $(m4data_DATA)
|
||||
|
||||
# We define the global AM_CPPFLAGS as everything we compile includes from these
|
||||
# directories.
|
||||
AM_CPPFLAGS = -I$(srcdir) -I$(srcdir)/include
|
||||
|
||||
# Modifies compiler and linker flags for pthreads compatibility.
|
||||
if HAVE_PTHREADS
|
||||
AM_CXXFLAGS = @PTHREAD_CFLAGS@ -DGTEST_HAS_PTHREAD=1
|
||||
AM_LIBS = @PTHREAD_LIBS@
|
||||
else
|
||||
AM_CXXFLAGS = -DGTEST_HAS_PTHREAD=0
|
||||
endif
|
||||
|
||||
# Build rules for libraries.
|
||||
lib_LTLIBRARIES = lib/libgtest.la lib/libgtest_main.la
|
||||
|
||||
lib_libgtest_la_SOURCES = src/gtest-all.cc
|
||||
|
||||
pkginclude_HEADERS = \
|
||||
include/gtest/gtest-death-test.h \
|
||||
include/gtest/gtest-message.h \
|
||||
include/gtest/gtest-param-test.h \
|
||||
include/gtest/gtest-printers.h \
|
||||
include/gtest/gtest-spi.h \
|
||||
include/gtest/gtest-test-part.h \
|
||||
include/gtest/gtest-typed-test.h \
|
||||
include/gtest/gtest.h \
|
||||
include/gtest/gtest_pred_impl.h \
|
||||
include/gtest/gtest_prod.h
|
||||
|
||||
pkginclude_internaldir = $(pkgincludedir)/internal
|
||||
pkginclude_internal_HEADERS = \
|
||||
include/gtest/internal/gtest-death-test-internal.h \
|
||||
include/gtest/internal/gtest-filepath.h \
|
||||
include/gtest/internal/gtest-internal.h \
|
||||
include/gtest/internal/gtest-linked_ptr.h \
|
||||
include/gtest/internal/gtest-param-util-generated.h \
|
||||
include/gtest/internal/gtest-param-util.h \
|
||||
include/gtest/internal/gtest-port.h \
|
||||
include/gtest/internal/gtest-string.h \
|
||||
include/gtest/internal/gtest-tuple.h \
|
||||
include/gtest/internal/gtest-type-util.h
|
||||
|
||||
lib_libgtest_main_la_SOURCES = src/gtest_main.cc
|
||||
lib_libgtest_main_la_LIBADD = lib/libgtest.la
|
||||
|
||||
# Bulid rules for samples and tests. Automake's naming for some of
|
||||
# these variables isn't terribly obvious, so this is a brief
|
||||
# reference:
|
||||
#
|
||||
# TESTS -- Programs run automatically by "make check"
|
||||
# check_PROGRAMS -- Programs built by "make check" but not necessarily run
|
||||
|
||||
noinst_LTLIBRARIES = samples/libsamples.la
|
||||
|
||||
samples_libsamples_la_SOURCES = \
|
||||
samples/sample1.cc \
|
||||
samples/sample1.h \
|
||||
samples/sample2.cc \
|
||||
samples/sample2.h \
|
||||
samples/sample3-inl.h \
|
||||
samples/sample4.cc \
|
||||
samples/sample4.h
|
||||
|
||||
TESTS=
|
||||
TESTS_ENVIRONMENT = GTEST_SOURCE_DIR="$(srcdir)/test" \
|
||||
GTEST_BUILD_DIR="$(top_builddir)/test"
|
||||
check_PROGRAMS=
|
||||
|
||||
# A simple sample on using gtest.
|
||||
TESTS += samples/sample1_unittest
|
||||
check_PROGRAMS += samples/sample1_unittest
|
||||
samples_sample1_unittest_SOURCES = samples/sample1_unittest.cc
|
||||
samples_sample1_unittest_LDADD = lib/libgtest_main.la \
|
||||
lib/libgtest.la \
|
||||
samples/libsamples.la
|
||||
|
||||
# Another sample. It also verifies that libgtest works.
|
||||
TESTS += samples/sample10_unittest
|
||||
check_PROGRAMS += samples/sample10_unittest
|
||||
samples_sample10_unittest_SOURCES = samples/sample10_unittest.cc
|
||||
samples_sample10_unittest_LDADD = lib/libgtest.la
|
||||
|
||||
# This tests most constructs of gtest and verifies that libgtest_main
|
||||
# and libgtest work.
|
||||
TESTS += test/gtest_all_test
|
||||
check_PROGRAMS += test/gtest_all_test
|
||||
test_gtest_all_test_SOURCES = test/gtest_all_test.cc
|
||||
test_gtest_all_test_LDADD = lib/libgtest_main.la \
|
||||
lib/libgtest.la
|
||||
|
||||
# Tests that fused gtest files compile and work.
|
||||
FUSED_GTEST_SRC = \
|
||||
fused-src/gtest/gtest-all.cc \
|
||||
fused-src/gtest/gtest.h \
|
||||
fused-src/gtest/gtest_main.cc
|
||||
|
||||
if HAVE_PYTHON
|
||||
TESTS += test/fused_gtest_test
|
||||
check_PROGRAMS += test/fused_gtest_test
|
||||
test_fused_gtest_test_SOURCES = $(FUSED_GTEST_SRC) \
|
||||
samples/sample1.cc samples/sample1_unittest.cc
|
||||
test_fused_gtest_test_CPPFLAGS = -I"$(srcdir)/fused-src"
|
||||
|
||||
# Build rules for putting fused Google Test files into the distribution
|
||||
# package. The user can also create those files by manually running
|
||||
# scripts/fuse_gtest_files.py.
|
||||
$(test_fused_gtest_test_SOURCES): fused-gtest
|
||||
|
||||
fused-gtest: $(pkginclude_HEADERS) $(pkginclude_internal_HEADERS) \
|
||||
$(GTEST_SRC) src/gtest-all.cc src/gtest_main.cc \
|
||||
scripts/fuse_gtest_files.py
|
||||
mkdir -p "$(srcdir)/fused-src"
|
||||
chmod -R u+w "$(srcdir)/fused-src"
|
||||
rm -f "$(srcdir)/fused-src/gtest/gtest-all.cc"
|
||||
rm -f "$(srcdir)/fused-src/gtest/gtest.h"
|
||||
"$(srcdir)/scripts/fuse_gtest_files.py" "$(srcdir)/fused-src"
|
||||
cp -f "$(srcdir)/src/gtest_main.cc" "$(srcdir)/fused-src/gtest/"
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -rf "$(srcdir)/fused-src"
|
||||
endif
|
||||
|
||||
# Death tests may produce core dumps in the build directory. In case
|
||||
# this happens, clean them to keep distcleancheck happy.
|
||||
CLEANFILES = core
|
||||
|
||||
# Disables 'make install' as installing a compiled version of Google
|
||||
# Test can lead to undefined behavior due to violation of the
|
||||
# One-Definition Rule.
|
||||
|
||||
install-exec-local:
|
||||
echo "'make install' is dangerous and not supported. Instead, see README for how to integrate Google Test into your build system."
|
||||
false
|
||||
|
||||
install-data-local:
|
||||
echo "'make install' is dangerous and not supported. Instead, see README for how to integrate Google Test into your build system."
|
||||
false
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,434 +0,0 @@
|
||||
Google C++ Testing Framework
|
||||
============================
|
||||
|
||||
http://code.google.com/p/googletest/
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
Google's framework for writing C++ tests on a variety of platforms
|
||||
(Linux, Mac OS X, Windows, Windows CE, Symbian, etc). Based on the
|
||||
xUnit architecture. Supports automatic test discovery, a rich set of
|
||||
assertions, user-defined assertions, death tests, fatal and non-fatal
|
||||
failures, various options for running the tests, and XML test report
|
||||
generation.
|
||||
|
||||
Please see the project page above for more information as well as the
|
||||
mailing list for questions, discussions, and development. There is
|
||||
also an IRC channel on OFTC (irc.oftc.net) #gtest available. Please
|
||||
join us!
|
||||
|
||||
Requirements for End Users
|
||||
--------------------------
|
||||
|
||||
Google Test is designed to have fairly minimal requirements to build
|
||||
and use with your projects, but there are some. Currently, we support
|
||||
Linux, Windows, Mac OS X, and Cygwin. We will also make our best
|
||||
effort to support other platforms (e.g. Solaris, AIX, and z/OS).
|
||||
However, since core members of the Google Test project have no access
|
||||
to these platforms, Google Test may have outstanding issues there. If
|
||||
you notice any problems on your platform, please notify
|
||||
[email protected]. Patches for fixing them are
|
||||
even more welcome!
|
||||
|
||||
### Linux Requirements ###
|
||||
|
||||
These are the base requirements to build and use Google Test from a source
|
||||
package (as described below):
|
||||
* GNU-compatible Make or gmake
|
||||
* POSIX-standard shell
|
||||
* POSIX(-2) Regular Expressions (regex.h)
|
||||
* A C++98-standard-compliant compiler
|
||||
|
||||
### Windows Requirements ###
|
||||
|
||||
* Microsoft Visual C++ 7.1 or newer
|
||||
|
||||
### Cygwin Requirements ###
|
||||
|
||||
* Cygwin 1.5.25-14 or newer
|
||||
|
||||
### Mac OS X Requirements ###
|
||||
|
||||
* Mac OS X 10.4 Tiger or newer
|
||||
* Developer Tools Installed
|
||||
|
||||
Also, you'll need CMake 2.6.4 or higher if you want to build the
|
||||
samples using the provided CMake script, regardless of the platform.
|
||||
|
||||
Requirements for Contributors
|
||||
-----------------------------
|
||||
|
||||
We welcome patches. If you plan to contribute a patch, you need to
|
||||
build Google Test and its own tests from an SVN checkout (described
|
||||
below), which has further requirements:
|
||||
|
||||
* Python version 2.3 or newer (for running some of the tests and
|
||||
re-generating certain source files from templates)
|
||||
* CMake 2.6.4 or newer
|
||||
|
||||
Getting the Source
|
||||
------------------
|
||||
|
||||
There are two primary ways of getting Google Test's source code: you
|
||||
can download a stable source release in your preferred archive format,
|
||||
or directly check out the source from our Subversion (SVN) repositary.
|
||||
The SVN checkout requires a few extra steps and some extra software
|
||||
packages on your system, but lets you track the latest development and
|
||||
make patches much more easily, so we highly encourage it.
|
||||
|
||||
### Source Package ###
|
||||
|
||||
Google Test is released in versioned source packages which can be
|
||||
downloaded from the download page [1]. Several different archive
|
||||
formats are provided, but the only difference is the tools used to
|
||||
manipulate them, and the size of the resulting file. Download
|
||||
whichever you are most comfortable with.
|
||||
|
||||
[1] http://code.google.com/p/googletest/downloads/list
|
||||
|
||||
Once the package is downloaded, expand it using whichever tools you
|
||||
prefer for that type. This will result in a new directory with the
|
||||
name "gtest-X.Y.Z" which contains all of the source code. Here are
|
||||
some examples on Linux:
|
||||
|
||||
tar -xvzf gtest-X.Y.Z.tar.gz
|
||||
tar -xvjf gtest-X.Y.Z.tar.bz2
|
||||
unzip gtest-X.Y.Z.zip
|
||||
|
||||
### SVN Checkout ###
|
||||
|
||||
To check out the main branch (also known as the "trunk") of Google
|
||||
Test, run the following Subversion command:
|
||||
|
||||
svn checkout http://googletest.googlecode.com/svn/trunk/ gtest-svn
|
||||
|
||||
Setting up the Build
|
||||
--------------------
|
||||
|
||||
To build Google Test and your tests that use it, you need to tell your
|
||||
build system where to find its headers and source files. The exact
|
||||
way to do it depends on which build system you use, and is usually
|
||||
straightforward.
|
||||
|
||||
### Generic Build Instructions ###
|
||||
|
||||
Suppose you put Google Test in directory ${GTEST_DIR}. To build it,
|
||||
create a library build target (or a project as called by Visual Studio
|
||||
and Xcode) to compile
|
||||
|
||||
${GTEST_DIR}/src/gtest-all.cc
|
||||
|
||||
with
|
||||
|
||||
${GTEST_DIR}/include and ${GTEST_DIR}
|
||||
|
||||
in the header search path. Assuming a Linux-like system and gcc,
|
||||
something like the following will do:
|
||||
|
||||
g++ -I${GTEST_DIR}/include -I${GTEST_DIR} -c ${GTEST_DIR}/src/gtest-all.cc
|
||||
ar -rv libgtest.a gtest-all.o
|
||||
|
||||
Next, you should compile your test source file with
|
||||
${GTEST_DIR}/include in the header search path, and link it with gtest
|
||||
and any other necessary libraries:
|
||||
|
||||
g++ -I${GTEST_DIR}/include path/to/your_test.cc libgtest.a -o your_test
|
||||
|
||||
As an example, the make/ directory contains a Makefile that you can
|
||||
use to build Google Test on systems where GNU make is available
|
||||
(e.g. Linux, Mac OS X, and Cygwin). It doesn't try to build Google
|
||||
Test's own tests. Instead, it just builds the Google Test library and
|
||||
a sample test. You can use it as a starting point for your own build
|
||||
script.
|
||||
|
||||
If the default settings are correct for your environment, the
|
||||
following commands should succeed:
|
||||
|
||||
cd ${GTEST_DIR}/make
|
||||
make
|
||||
./sample1_unittest
|
||||
|
||||
If you see errors, try to tweak the contents of make/Makefile to make
|
||||
them go away. There are instructions in make/Makefile on how to do
|
||||
it.
|
||||
|
||||
### Using CMake ###
|
||||
|
||||
Google Test comes with a CMake build script (CMakeLists.txt) that can
|
||||
be used on a wide range of platforms ("C" stands for cross-platofrm.).
|
||||
If you don't have CMake installed already, you can download it for
|
||||
free from http://www.cmake.org/.
|
||||
|
||||
CMake works by generating native makefiles or build projects that can
|
||||
be used in the compiler environment of your choice. The typical
|
||||
workflow starts with:
|
||||
|
||||
mkdir mybuild # Create a directory to hold the build output.
|
||||
cd mybuild
|
||||
cmake ${GTEST_DIR} # Generate native build scripts.
|
||||
|
||||
If you want to build Google Test's samples, you should replace the
|
||||
last command with
|
||||
|
||||
cmake -Dgtest_build_samples=ON ${GTEST_DIR}
|
||||
|
||||
If you are on a *nix system, you should now see a Makefile in the
|
||||
current directory. Just type 'make' to build gtest.
|
||||
|
||||
If you use Windows and have Vistual Studio installed, a gtest.sln file
|
||||
and several .vcproj files will be created. You can then build them
|
||||
using Visual Studio.
|
||||
|
||||
On Mac OS X with Xcode installed, a .xcodeproj file will be generated.
|
||||
|
||||
### Legacy Build Scripts ###
|
||||
|
||||
Before settling on CMake, we have been providing hand-maintained build
|
||||
projects/scripts for Visual Studio, Xcode, and Autotools. While we
|
||||
continue to provide them for convenience, they are not actively
|
||||
maintained any more. We highly recommend that you follow the
|
||||
instructions in the previous two sections to integrate Google Test
|
||||
with your existing build system.
|
||||
|
||||
If you still need to use the legacy build scripts, here's how:
|
||||
|
||||
The msvc\ folder contains two solutions with Visual C++ projects.
|
||||
Open the gtest.sln or gtest-md.sln file using Visual Studio, and you
|
||||
are ready to build Google Test the same way you build any Visual
|
||||
Studio project. Files that have names ending with -md use DLL
|
||||
versions of Microsoft runtime libraries (the /MD or the /MDd compiler
|
||||
option). Files without that suffix use static versions of the runtime
|
||||
libraries (the /MT or the /MTd option). Please note that one must use
|
||||
the same option to compile both gtest and the test code. If you use
|
||||
Visual Studio 2005 or above, we recommend the -md version as /MD is
|
||||
the default for new projects in these versions of Visual Studio.
|
||||
|
||||
On Mac OS X, open the gtest.xcodeproj in the xcode/ folder using
|
||||
Xcode. Build the "gtest" target. The universal binary framework will
|
||||
end up in your selected build directory (selected in the Xcode
|
||||
"Preferences..." -> "Building" pane and defaults to xcode/build).
|
||||
Alternatively, at the command line, enter:
|
||||
|
||||
xcodebuild
|
||||
|
||||
This will build the "Release" configuration of gtest.framework in your
|
||||
default build location. See the "xcodebuild" man page for more
|
||||
information about building different configurations and building in
|
||||
different locations.
|
||||
|
||||
If you wish to use the Google Test Xcode project with Xcode 4.x and
|
||||
above, you need to either:
|
||||
* update the SDK configuration options in xcode/Config/General.xconfig.
|
||||
Comment options SDKROOT, MACOS_DEPLOYMENT_TARGET, and GCC_VERSION. If
|
||||
you choose this route you lose the ability to target earlier versions
|
||||
of MacOS X.
|
||||
* Install an SDK for an earlier version. This doesn't appear to be
|
||||
supported by Apple, but has been reported to work
|
||||
(http://stackoverflow.com/questions/5378518).
|
||||
|
||||
Tweaking Google Test
|
||||
--------------------
|
||||
|
||||
Google Test can be used in diverse environments. The default
|
||||
configuration may not work (or may not work well) out of the box in
|
||||
some environments. However, you can easily tweak Google Test by
|
||||
defining control macros on the compiler command line. Generally,
|
||||
these macros are named like GTEST_XYZ and you define them to either 1
|
||||
or 0 to enable or disable a certain feature.
|
||||
|
||||
We list the most frequently used macros below. For a complete list,
|
||||
see file include/gtest/internal/gtest-port.h.
|
||||
|
||||
### Choosing a TR1 Tuple Library ###
|
||||
|
||||
Some Google Test features require the C++ Technical Report 1 (TR1)
|
||||
tuple library, which is not yet available with all compilers. The
|
||||
good news is that Google Test implements a subset of TR1 tuple that's
|
||||
enough for its own need, and will automatically use this when the
|
||||
compiler doesn't provide TR1 tuple.
|
||||
|
||||
Usually you don't need to care about which tuple library Google Test
|
||||
uses. However, if your project already uses TR1 tuple, you need to
|
||||
tell Google Test to use the same TR1 tuple library the rest of your
|
||||
project uses, or the two tuple implementations will clash. To do
|
||||
that, add
|
||||
|
||||
-DGTEST_USE_OWN_TR1_TUPLE=0
|
||||
|
||||
to the compiler flags while compiling Google Test and your tests. If
|
||||
you want to force Google Test to use its own tuple library, just add
|
||||
|
||||
-DGTEST_USE_OWN_TR1_TUPLE=1
|
||||
|
||||
to the compiler flags instead.
|
||||
|
||||
If you don't want Google Test to use tuple at all, add
|
||||
|
||||
-DGTEST_HAS_TR1_TUPLE=0
|
||||
|
||||
and all features using tuple will be disabled.
|
||||
|
||||
### Multi-threaded Tests ###
|
||||
|
||||
Google Test is thread-safe where the pthread library is available.
|
||||
After #include "gtest/gtest.h", you can check the GTEST_IS_THREADSAFE
|
||||
macro to see whether this is the case (yes if the macro is #defined to
|
||||
1, no if it's undefined.).
|
||||
|
||||
If Google Test doesn't correctly detect whether pthread is available
|
||||
in your environment, you can force it with
|
||||
|
||||
-DGTEST_HAS_PTHREAD=1
|
||||
|
||||
or
|
||||
|
||||
-DGTEST_HAS_PTHREAD=0
|
||||
|
||||
When Google Test uses pthread, you may need to add flags to your
|
||||
compiler and/or linker to select the pthread library, or you'll get
|
||||
link errors. If you use the CMake script or the deprecated Autotools
|
||||
script, this is taken care of for you. If you use your own build
|
||||
script, you'll need to read your compiler and linker's manual to
|
||||
figure out what flags to add.
|
||||
|
||||
### As a Shared Library (DLL) ###
|
||||
|
||||
Google Test is compact, so most users can build and link it as a
|
||||
static library for the simplicity. You can choose to use Google Test
|
||||
as a shared library (known as a DLL on Windows) if you prefer.
|
||||
|
||||
To compile *gtest* as a shared library, add
|
||||
|
||||
-DGTEST_CREATE_SHARED_LIBRARY=1
|
||||
|
||||
to the compiler flags. You'll also need to tell the linker to produce
|
||||
a shared library instead - consult your linker's manual for how to do
|
||||
it.
|
||||
|
||||
To compile your *tests* that use the gtest shared library, add
|
||||
|
||||
-DGTEST_LINKED_AS_SHARED_LIBRARY=1
|
||||
|
||||
to the compiler flags.
|
||||
|
||||
Note: while the above steps aren't technically necessary today when
|
||||
using some compilers (e.g. GCC), they may become necessary in the
|
||||
future, if we decide to improve the speed of loading the library (see
|
||||
http://gcc.gnu.org/wiki/Visibility for details). Therefore you are
|
||||
recommended to always add the above flags when using Google Test as a
|
||||
shared library. Otherwise a future release of Google Test may break
|
||||
your build script.
|
||||
|
||||
### Avoiding Macro Name Clashes ###
|
||||
|
||||
In C++, macros don't obey namespaces. Therefore two libraries that
|
||||
both define a macro of the same name will clash if you #include both
|
||||
definitions. In case a Google Test macro clashes with another
|
||||
library, you can force Google Test to rename its macro to avoid the
|
||||
conflict.
|
||||
|
||||
Specifically, if both Google Test and some other code define macro
|
||||
FOO, you can add
|
||||
|
||||
-DGTEST_DONT_DEFINE_FOO=1
|
||||
|
||||
to the compiler flags to tell Google Test to change the macro's name
|
||||
from FOO to GTEST_FOO. Currently FOO can be FAIL, SUCCEED, or TEST.
|
||||
For example, with -DGTEST_DONT_DEFINE_TEST=1, you'll need to write
|
||||
|
||||
GTEST_TEST(SomeTest, DoesThis) { ... }
|
||||
|
||||
instead of
|
||||
|
||||
TEST(SomeTest, DoesThis) { ... }
|
||||
|
||||
in order to define a test.
|
||||
|
||||
Upgrating from an Earlier Version
|
||||
---------------------------------
|
||||
|
||||
We strive to keep Google Test releases backward compatible.
|
||||
Sometimes, though, we have to make some breaking changes for the
|
||||
users' long-term benefits. This section describes what you'll need to
|
||||
do if you are upgrading from an earlier version of Google Test.
|
||||
|
||||
### Upgrading from 1.3.0 or Earlier ###
|
||||
|
||||
You may need to explicitly enable or disable Google Test's own TR1
|
||||
tuple library. See the instructions in section "Choosing a TR1 Tuple
|
||||
Library".
|
||||
|
||||
### Upgrading from 1.4.0 or Earlier ###
|
||||
|
||||
The Autotools build script (configure + make) is no longer officially
|
||||
supportted. You are encouraged to migrate to your own build system or
|
||||
use CMake. If you still need to use Autotools, you can find
|
||||
instructions in the README file from Google Test 1.4.0.
|
||||
|
||||
On platforms where the pthread library is available, Google Test uses
|
||||
it in order to be thread-safe. See the "Multi-threaded Tests" section
|
||||
for what this means to your build script.
|
||||
|
||||
If you use Microsoft Visual C++ 7.1 with exceptions disabled, Google
|
||||
Test will no longer compile. This should affect very few people, as a
|
||||
large portion of STL (including <string>) doesn't compile in this mode
|
||||
anyway. We decided to stop supporting it in order to greatly simplify
|
||||
Google Test's implementation.
|
||||
|
||||
Developing Google Test
|
||||
----------------------
|
||||
|
||||
This section discusses how to make your own changes to Google Test.
|
||||
|
||||
### Testing Google Test Itself ###
|
||||
|
||||
To make sure your changes work as intended and don't break existing
|
||||
functionality, you'll want to compile and run Google Test's own tests.
|
||||
For that you can use CMake:
|
||||
|
||||
mkdir mybuild
|
||||
cd mybuild
|
||||
cmake -Dgtest_build_tests=ON ${GTEST_DIR}
|
||||
|
||||
Make sure you have Python installed, as some of Google Test's tests
|
||||
are written in Python. If the cmake command complains about not being
|
||||
able to find Python ("Could NOT find PythonInterp (missing:
|
||||
PYTHON_EXECUTABLE)"), try telling it explicitly where your Python
|
||||
executable can be found:
|
||||
|
||||
cmake -DPYTHON_EXECUTABLE=path/to/python -Dgtest_build_tests=ON ${GTEST_DIR}
|
||||
|
||||
Next, you can build Google Test and all of its own tests. On *nix,
|
||||
this is usually done by 'make'. To run the tests, do
|
||||
|
||||
make test
|
||||
|
||||
All tests should pass.
|
||||
|
||||
### Regenerating Source Files ###
|
||||
|
||||
Some of Google Test's source files are generated from templates (not
|
||||
in the C++ sense) using a script. A template file is named FOO.pump,
|
||||
where FOO is the name of the file it will generate. For example, the
|
||||
file include/gtest/internal/gtest-type-util.h.pump is used to generate
|
||||
gtest-type-util.h in the same directory.
|
||||
|
||||
Normally you don't need to worry about regenerating the source files,
|
||||
unless you need to modify them. In that case, you should modify the
|
||||
corresponding .pump files instead and run the pump.py Python script to
|
||||
regenerate them. You can find pump.py in the scripts/ directory.
|
||||
Read the Pump manual [2] for how to use it.
|
||||
|
||||
[2] http://code.google.com/p/googletest/wiki/PumpManual
|
||||
|
||||
### Contributing a Patch ###
|
||||
|
||||
We welcome patches. Please read the Google Test developer's guide [3]
|
||||
for how you can contribute. In particular, make sure you have signed
|
||||
the Contributor License Agreement, or we won't be able to accept the
|
||||
patch.
|
||||
|
||||
[3] http://code.google.com/p/googletest/wiki/GoogleTestDevGuide
|
||||
|
||||
Happy testing!
|
||||
-1198
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user