Commit 573fb53c authored by uzchoi's avatar uzchoi

Merge branch '1.2-rel' of ssh://gerrit.iotivity.org:29418/iotivity into 1.2-rel

parents 0d14a365 c8d50992
This diff is collapsed.
......@@ -570,13 +570,13 @@ public final class OcPlatform {
public static void setPropertyValue(
int path, String propName, String propValue) throws OcException {
OcPlatform.initCheck();
OcPlatform.setPropertyValue0(path, propName, propValue);
OcPlatform.setPropertyValue1(path, propName, propValue);
}
public static void setPropertyValue(
int path, String propName, List<String> propValue) throws OcException {
OcPlatform.initCheck();
OcPlatform.setPropertyValue1(path, propName, propValue.toArray(new String[propValue.size()]));
OcPlatform.setPropertyValue0(path, propName, propValue.toArray(new String[propValue.size()]));
}
public static void getPropertyValue(
......@@ -585,14 +585,14 @@ public final class OcPlatform {
OcPlatform.getPropertyValue0(path, propName, propValue);
}
private static native void setPropertyValue0(
private static native void setPropertyValue1(
int path,
String propName,
String propValue
) throws OcException;
private static native void setPropertyValue1(
private static native void setPropertyValue0(
int path,
String propName,
String[] propValue
......
......@@ -150,6 +150,35 @@ public class CloudProvisioningClient extends Activity implements OcAccountManage
}
}
};
OcAccountManager.OnPostListener onSignOut = new OcAccountManager.OnPostListener() {
@Override
public synchronized void onPostCompleted(List<OcHeaderOption> list,
OcRepresentation ocRepresentation) {
logMessage("signOut was successful");
runOnUiThread(new Runnable() {
@Override
public void run() {
lyt1.setVisibility(View.GONE);
lyt2.setVisibility(View.GONE);
signinLyt.setVisibility(View.VISIBLE);
}
});
}
@Override
public synchronized void onPostFailed(Throwable throwable) {
logMessage("Failed to signOut");
if (throwable instanceof OcException) {
OcException ocEx = (OcException) throwable;
Log.e(TAG, ocEx.toString());
ErrorCode errCode = ocEx.getErrorCode();
logMessage("Error code: " + errCode);
}
}
};
OcCloudProvisioning.GetIndividualAclInfoListener getIndividualAclInfoListener =
new OcCloudProvisioning.GetIndividualAclInfoListener() {
@Override
......@@ -382,10 +411,7 @@ public class CloudProvisioningClient extends Activity implements OcAccountManage
EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP));
}
mAccountManager.signOut(CloudProvisioningClient.this);
lyt1.setVisibility(View.GONE);
lyt2.setVisibility(View.GONE);
signinLyt.setVisibility(View.VISIBLE);
mAccountManager.signOut(settingPreference.getString("accesstoken", ""),onSignOut);
} catch (OcException e) {
e.printStackTrace();
}
......
......@@ -401,7 +401,12 @@ def unit_tests():
'SECURED':1,
'RELEASE':'false',
}
extra_option_str = "resource"
call_scons(build_options, extra_option_str)
build_options = {
'TEST':1,
'SECURED':1,
'RELEASE':'false',
}
call_scons(build_options, extra_option_str)
print ("*********** Unit test Stop *************")
......
......@@ -141,9 +141,6 @@ env.AddMethod(__download, "Download")
env.AddMethod(__install_head_file, "InstallHeadFile")
env.AddMethod(__install_lib, "InstallLib")
if env.get('SECURED') == '1' and target_os not in ['linux', 'tizen']:
SConscript(os.path.join(env.get('SRC_DIR'), 'extlibs', 'sqlite3', 'SConscript'))
if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
if target_os not in ['linux', 'tizen']:
SConscript(os.path.join(env.get('SRC_DIR'), 'extlibs', 'sqlite3', 'SConscript'))
if env.get('SECURED') == '1' or 'SERVER' in rd_mode:
if target_os not in ['linux', 'tizen']:
SConscript('#extlibs/sqlite3/SConscript')
......@@ -27,7 +27,7 @@ import java.util.Scanner;
import org.iotivity.cloud.base.connector.ConnectorPool;
import org.iotivity.cloud.base.server.CoapServer;
import org.iotivity.cloud.ciserver.DeviceServerSystem.CoapDevicePool;
import org.iotivity.cloud.ciserver.resources.DiResource;
import org.iotivity.cloud.ciserver.resources.RouteResource;
import org.iotivity.cloud.ciserver.resources.KeepAliveResource;
import org.iotivity.cloud.ciserver.resources.proxy.account.Account;
import org.iotivity.cloud.ciserver.resources.proxy.account.AccountSession;
......@@ -113,7 +113,7 @@ public class CloudInterfaceServer {
deviceServer.addResource(resKeepAlive);
deviceServer.addResource(new DiResource(devicePool));
deviceServer.addResource(new RouteResource(devicePool));
deviceServer.addServer(new CoapServer(
new InetSocketAddress(Integer.parseInt(args[0]))));
......
......@@ -43,6 +43,7 @@ public class Constants extends OICConstants {
public static final String REQ_MEMBER_ID = "mid";
public static final String REQ_MEMBER_LIST = "members";
public static final String REQ_DEVICE_ID = "di";
public static final String REQ_DEVICE_ROUTE = "route";
public static final String REQ_DEVICE_LIST = "devices";
public static final String REQ_INVITE = "invite";
public static final String REQ_PING_ARRAY = "inarray";
......
......@@ -109,8 +109,7 @@ public class DeviceServerSystem extends ServerSystem {
Iterator<String> iterator = mMapDevice.keySet().iterator();
while (iterator.hasNext()) {
String deviceId = iterator.next();
CoapDevice getDevice = (CoapDevice) mDevicePool
.queryDevice(deviceId);
CoapDevice getDevice = (CoapDevice) queryDevice(deviceId);
getDevice.removeObserveChannel(
((CoapDevice) device).getRequestChannel());
}
......@@ -154,11 +153,14 @@ public class DeviceServerSystem extends ServerSystem {
CoapRequest coapRequest = (CoapRequest) msg;
IRequestChannel targetChannel = null;
if (coapRequest.getUriPathSegments()
.contains(Constants.REQ_DEVICE_ID)) {
if (coapRequest.getUriPath()
.contains(Constants.ROUTE_FULL_URI)) {
int RouteResourcePathSize = Constants.ROUTE_FULL_URI
.split("/").length;
CoapDevice targetDevice = (CoapDevice) mDevicePool
.queryDevice(coapRequest.getUriPathSegments()
.get(1));
.get(RouteResourcePathSize - 1));
targetChannel = targetDevice.getRequestChannel();
}
switch (coapRequest.getObserve()) {
......@@ -194,34 +196,32 @@ public class DeviceServerSystem extends ServerSystem {
public void write(ChannelHandlerContext ctx, Object msg,
ChannelPromise promise) throws Exception {
if (!(msg instanceof CoapResponse)) {
throw new BadRequestException(
"this msg type is not CoapResponse");
}
// This is CoapResponse
// Once the response is valid, add this to deviceList
CoapResponse response = (CoapResponse) msg;
switch (response.getUriPath()) {
case OICConstants.ACCOUNT_SESSION_FULL_URI:
if (response.getStatus() != ResponseStatus.CHANGED) {
throw new UnAuthorizedException();
}
boolean bCloseConnection = false;
if (response.getPayload() != null) {
break;
}
if (msg instanceof CoapResponse) {
// This is CoapResponse
// Once the response is valid, add this to deviceList
CoapResponse response = (CoapResponse) msg;
ctx.close();
break;
case OICConstants.ACCOUNT_FULL_URI:
if (response.getStatus() != ResponseStatus.DELETED) {
switch (response.getUriPath()) {
case OICConstants.ACCOUNT_SESSION_FULL_URI:
if (response.getStatus() != ResponseStatus.CHANGED) {
bCloseConnection = true;
}
break;
}
ctx.close();
break;
case OICConstants.ACCOUNT_FULL_URI:
if (response.getStatus() == ResponseStatus.DELETED) {
bCloseConnection = true;
}
break;
}
}
ctx.writeAndFlush(msg);
if (bCloseConnection == true) {
ctx.close();
}
}
@Override
......
......@@ -33,9 +33,6 @@ import org.iotivity.cloud.base.device.Device;
import org.iotivity.cloud.base.device.IRequestChannel;
import org.iotivity.cloud.base.device.IResponseEventHandler;
import org.iotivity.cloud.base.exception.ServerException;
import org.iotivity.cloud.base.exception.ServerException.BadRequestException;
import org.iotivity.cloud.base.exception.ServerException.NotFoundException;
import org.iotivity.cloud.base.exception.ServerException.PreconditionFailedException;
import org.iotivity.cloud.base.protocols.IRequest;
import org.iotivity.cloud.base.protocols.IResponse;
import org.iotivity.cloud.base.protocols.MessageBuilder;
......@@ -54,32 +51,26 @@ import org.iotivity.cloud.util.Cbor;
* device
*
*/
public class DiResource extends Resource {
public class RouteResource extends Resource {
private CoapDevicePool mDevicePool = null;
private IRequestChannel mASServer = null;
private Cbor<HashMap<String, Object>> mCbor = new Cbor<>();
public DiResource(CoapDevicePool devicePool) {
super(Arrays.asList(Constants.REQ_DEVICE_ID));
public RouteResource(CoapDevicePool devicePool) {
super(Arrays.asList(Constants.PREFIX_OIC, Constants.REQ_DEVICE_ROUTE));
mASServer = ConnectorPool.getConnection("account");
mDevicePool = devicePool;
}
private IRequestChannel getTargetDeviceChannel(IRequest request)
throws ServerException {
List<String> uriPathSegment = request.getUriPathSegments();
if (uriPathSegment.size() < 2) {
throw new PreconditionFailedException();
}
String deviceId = uriPathSegment.get(1);
CoapDevice targetDevice = (CoapDevice) mDevicePool
.queryDevice(deviceId);
.queryDevice(getDeviceId(request));
if (targetDevice == null) {
throw new NotFoundException();
return null;
}
// Do request and receive response
......@@ -90,7 +81,9 @@ public class DiResource extends Resource {
List<String> uriPathSegment = request.getUriPathSegments();
// Remove prefix path
uriPathSegment.remove(0);
for (String path : getUriPathSegments()) {
uriPathSegment.remove(path);
}
uriPathSegment.remove(0);
StringBuilder uriPath = new StringBuilder();
......@@ -107,14 +100,24 @@ public class DiResource extends Resource {
CoapResponse coapResponse = (CoapResponse) response;
StringBuilder uriPath = new StringBuilder();
for (String path : getUriPathSegments()) {
uriPath.append("/" + path);
}
if (coapResponse.getUriPath().isEmpty() == false) {
convertedUri = "/di/" + di + "/" + coapResponse.getUriPath();
convertedUri = uriPath.toString() + "/" + di
+ coapResponse.getUriPath();
}
return MessageBuilder.modifyResponse(response, convertedUri, null,
null);
}
private String getDeviceId(IRequest request) {
return request.getUriPathSegments().get(getUriPathSegments().size());
}
/**
*
* This class provides a set of APIs to handling message contains link
......@@ -125,30 +128,40 @@ public class DiResource extends Resource {
private Cbor<List<HashMap<String, Object>>> mCbor = new Cbor<>();
private String mTargetDI = null;
private Device mSrcDevice = null;
private IRequest mRequest = null;
public LinkInterfaceHandler(String targetDI, Device srcDevice) {
public LinkInterfaceHandler(String targetDI, Device srcDevice,
IRequest request) {
mTargetDI = targetDI;
mSrcDevice = srcDevice;
mRequest = request;
}
private void convertHref(List<HashMap<String, Object>> linkPayload) {
StringBuilder uriPath = new StringBuilder();
for (String path : getUriPathSegments()) {
uriPath.append("/" + path);
}
for (HashMap<String, Object> link : linkPayload) {
link.put("href", "/di/" + mTargetDI + link.get("href"));
link.put("href", uriPath.toString() + "/" + mTargetDI
+ link.get("href"));
}
}
@Override
public void onResponseReceived(IResponse response) {
List<HashMap<String, Object>> linkPayload = null;
if (response.getStatus() == ResponseStatus.CONTENT) {
if (response.getStatus().equals(ResponseStatus.CONTENT)) {
linkPayload = mCbor.parsePayloadFromCbor(response.getPayload(),
ArrayList.class);
if (linkPayload == null) {
throw new BadRequestException("payload is null");
mSrcDevice.sendResponse(MessageBuilder.createResponse(
mRequest, ResponseStatus.NOT_FOUND));
}
convertHref(linkPayload);
}
mSrcDevice.sendResponse(MessageBuilder.modifyResponse(
convertReponseUri(response, mTargetDI),
ContentFormat.APPLICATION_CBOR, linkPayload != null
......@@ -194,9 +207,9 @@ public class DiResource extends Resource {
.get(Constants.RESP_GRANT_POLICY);
verifyRequest(mSrcDevice, mRequest, gp);
break;
default:
mSrcDevice.sendResponse(MessageBuilder.createResponse(
mRequest, ResponseStatus.BAD_REQUEST));
mSrcDevice.sendResponse(response);
}
}
......@@ -205,42 +218,35 @@ public class DiResource extends Resource {
private void verifyRequest(Device srcDevice, IRequest request,
String grantPermisson) {
switch (grantPermisson) {
case Constants.RESP_ACL_DENIED:
srcDevice.sendResponse(MessageBuilder.createResponse(request,
ResponseStatus.UNAUTHORIZED));
break;
case Constants.RESP_ACL_ALLOWED:
IRequestChannel requestChannel = getTargetDeviceChannel(
request);
if (requestChannel == null) {
throw new NotFoundException();
srcDevice.sendResponse(MessageBuilder
.createResponse(request, ResponseStatus.NOT_FOUND));
break;
}
String deviceId = request.getUriPathSegments().get(1);
IResponseEventHandler responseHandler = null;
if (request.getUriQuery() != null && checkQueryException(
Constants.RS_INTERFACE, request.getUriQueryMap())) {
boolean hasLinkInterface = request.getUriQuery()
.contains(Constants.LINK_INTERFACE);
if (hasLinkInterface) {
responseHandler = new LinkInterfaceHandler(deviceId,
srcDevice);
}
} else {
responseHandler = new DefaultResponseHandler(deviceId,
srcDevice);
IResponseEventHandler responseHandler = new DefaultResponseHandler(
getDeviceId(request), srcDevice);
if (request.getUriQuery() != null && request.getUriQuery()
.contains(Constants.LINK_INTERFACE)) {
responseHandler = new LinkInterfaceHandler(
getDeviceId(request), srcDevice, request);
}
String uriPath = extractTargetUriPath(request);
IRequest requestToResource = MessageBuilder
.modifyRequest(request, uriPath, null, null, null);
requestChannel.sendRequest(requestToResource, responseHandler);
break;
case Constants.RESP_ACL_DENIED:
srcDevice.sendResponse(MessageBuilder.createResponse(request,
ResponseStatus.UNAUTHORIZED));
break;
default:
srcDevice.sendResponse(MessageBuilder.createResponse(request,
ResponseStatus.BAD_REQUEST));
}
}
......@@ -251,8 +257,8 @@ public class DiResource extends Resource {
StringBuffer uriQuery = new StringBuffer();
uriQuery.append(Constants.REQ_SEARCH_USER_ID + "="
+ srcDevice.getUserId() + ";");
uriQuery.append(Constants.REQ_DEVICE_ID + "="
+ request.getUriPathSegments().get(1) + ";");
uriQuery.append(
Constants.REQ_DEVICE_ID + "=" + getDeviceId(request) + ";");
uriQuery.append(
Constants.REQ_REQUEST_METHOD + "=" + request.getMethod() + ";");
uriQuery.append(Constants.REQ_REQUEST_URI + "="
......
......@@ -33,7 +33,6 @@ import org.iotivity.cloud.base.protocols.IRequest;
import org.iotivity.cloud.base.protocols.IResponse;
import org.iotivity.cloud.base.protocols.MessageBuilder;
import org.iotivity.cloud.base.protocols.enums.RequestMethod;
import org.iotivity.cloud.base.protocols.enums.ResponseStatus;
import org.iotivity.cloud.base.resource.Resource;
import org.iotivity.cloud.ciserver.Constants;
......@@ -52,33 +51,6 @@ public class Account extends Resource {
mASServer = ConnectorPool.getConnection("account");
}
class RDReceiveHandler implements IResponseEventHandler {
private Device mSrcDevice;
private IResponse mResponse;
private IRequest mRequest;
public RDReceiveHandler(IRequest request, IResponse response,
Device srcDevice) {
mSrcDevice = srcDevice;
mRequest = request;
mResponse = response;
}
@Override
public void onResponseReceived(IResponse response)
throws ClientException {
switch (response.getStatus()) {
case DELETED:
mSrcDevice.sendResponse(mResponse);
break;
default:
mSrcDevice.sendResponse(MessageBuilder.createResponse(
mRequest, ResponseStatus.BAD_REQUEST));
}
}
}
class AccountReceiveHandler implements IResponseEventHandler {
IRequestChannel mRDServer = null;
......@@ -102,16 +74,10 @@ public class Account extends Resource {
mRDServer.sendRequest(
MessageBuilder.createRequest(RequestMethod.DELETE,
uriPath.toString(), mRequest.getUriQuery()),
new RDReceiveHandler(mRequest, response,
mSrcDevice));
break;
case CHANGED:
case CONTENT:
mSrcDevice.sendResponse(response);
mSrcDevice);
break;
default:
mSrcDevice.sendResponse(MessageBuilder.createResponse(
mRequest, ResponseStatus.BAD_REQUEST));
mSrcDevice.sendResponse(response);
}
}
}
......
......@@ -80,12 +80,6 @@ public class DevicePresence extends Resource {
.parsePayloadFromCbor(response.getPayload(),
HashMap.class);
if (payloadData == null) {
mSrcDevice.sendResponse(MessageBuilder.createResponse(
mRequest, ResponseStatus.BAD_REQUEST));
return;
}
ArrayList<String> devices = (ArrayList<String>) getResponseDeviceList(
payloadData);
......@@ -101,12 +95,7 @@ public class DevicePresence extends Resource {
} else {
String additionalQuery = makeAdditionalQuery(
payloadData, mSrcDevice.getDeviceId());
if (additionalQuery == null) {
mSrcDevice.sendResponse(