Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: native_client_sdk/src/examples/demo/googledrivefs_demo/handlers.cc

Issue 2156503002: [NaCl SDK] Expose Google Drive to nacl_io. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/examples/demo/googledrivefs_demo/handlers.cc
diff --git a/native_client_sdk/src/examples/demo/nacl_io_demo/handlers.c b/native_client_sdk/src/examples/demo/googledrivefs_demo/handlers.cc
similarity index 77%
copy from native_client_sdk/src/examples/demo/nacl_io_demo/handlers.c
copy to native_client_sdk/src/examples/demo/googledrivefs_demo/handlers.cc
index e11351178098bb8c925fca1a9f99421bfc6f66d2..3ad8a710aa35ea26d02358ec6846bca43e0e4772 100644
--- a/native_client_sdk/src/examples/demo/nacl_io_demo/handlers.c
+++ b/native_client_sdk/src/examples/demo/googledrivefs_demo/handlers.cc
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
+/* Copyright (c) 2016 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. */
@@ -22,7 +22,7 @@
#include "nacl_io/osdirent.h"
#include "nacl_io/osinttypes.h"
-#include "nacl_io_demo.h"
+#include "googledrivefs_demo.h"
#define MAX_OPEN_FILES 10
#define MAX_OPEN_DIRS 10
@@ -171,7 +171,6 @@ static int GetParamString(struct PP_Var params,
free(g_ParamStrings[index]);
g_ParamStrings[index] = string;
-
*out_string = string;
*out_string_len = length;
return 0;
@@ -246,7 +245,7 @@ static int GetParamDir(struct PP_Var params,
return 1;
}
- *out_dir = g_OpenDirs[dir_index];
+ *out_dir = (DIR *) g_OpenDirs[dir_index];
*out_dir_index = dir_index;
return 0;
}
@@ -861,255 +860,3 @@ int HandleGetcwd(struct PP_Var params,
return 0;
}
-/**
- * Handle a call to getaddrinfo() made by JavaScript.
- *
- * getaddrinfo expects 1 parameter:
- * 0: The name of the host to look up.
- * on success, getaddrinfo returns a result in |output|:
- * 0: "getaddrinfo"
- * 1: The canonical name
- * 2*n+2: Host name
- * 2*n+3: Address type (either "AF_INET" or "AF_INET6")
- * on failure, getaddrinfo returns an error string in |out_error|.
- */
-int HandleGetaddrinfo(struct PP_Var params,
- struct PP_Var* output,
- const char** out_error) {
- CHECK_PARAM_COUNT(getaddrinfo, 2);
- PARAM_STRING(0, name);
- PARAM_STRING(1, family);
-
- struct addrinfo hints;
- memset(&hints, 0, sizeof(hints));
- hints.ai_flags = AI_CANONNAME;
- if (!strcmp(family, "AF_INET"))
- hints.ai_family = AF_INET;
- else if (!strcmp(family, "AF_INET6"))
- hints.ai_family = AF_INET6;
- else if (!strcmp(family, "AF_UNSPEC"))
- hints.ai_family = AF_UNSPEC;
- else {
- *out_error = PrintfToNewString("getaddrinfo uknown family: %s", family);
- return 1;
- }
-
- struct addrinfo* ai;
- int rtn = getaddrinfo(name, NULL, &hints, &ai);
- if (rtn != 0) {
- *out_error = PrintfToNewString("getaddrinfo failed, error is \"%s\"",
- gai_strerror(rtn));
- return 2;
- }
-
- CREATE_RESPONSE(getaddrinfo);
- RESPONSE_STRING(ai->ai_canonname);
- struct addrinfo* current = ai;
- while (current) {
- char addr_str[INET6_ADDRSTRLEN];
- if (ai->ai_family == AF_INET6) {
- struct sockaddr_in6* in6 = (struct sockaddr_in6*)current->ai_addr;
- inet_ntop(
- ai->ai_family, &in6->sin6_addr.s6_addr, addr_str, sizeof(addr_str));
- } else if (ai->ai_family == AF_INET) {
- struct sockaddr_in* in = (struct sockaddr_in*)current->ai_addr;
- inet_ntop(ai->ai_family, &in->sin_addr, addr_str, sizeof(addr_str));
- }
-
- RESPONSE_STRING(addr_str);
- RESPONSE_STRING(ai->ai_family == AF_INET ? "AF_INET" : "AF_INET6");
-
- current = current->ai_next;
- }
-
- freeaddrinfo(ai);
- return 0;
-}
-
-/**
- * Handle a call to gethostbyname() made by JavaScript.
- *
- * gethostbyname expects 1 parameter:
- * 0: The name of the host to look up.
- * on success, gethostbyname returns a result in |output|:
- * 0: "gethostbyname"
- * 1: Host name
- * 2: Address type (either "AF_INET" or "AF_INET6")
- * 3: The first address.
- * 4+ The second, third, etc. addresses.
- * on failure, gethostbyname returns an error string in |out_error|.
- */
-int HandleGethostbyname(struct PP_Var params,
- struct PP_Var* output,
- const char** out_error) {
- CHECK_PARAM_COUNT(gethostbyname, 1);
- PARAM_STRING(0, name);
-
- struct hostent* info = gethostbyname(name);
- if (!info) {
- *out_error = PrintfToNewString("gethostbyname failed, error is \"%s\"",
- hstrerror(h_errno));
- return 1;
- }
-
- CREATE_RESPONSE(gethostbyname);
- RESPONSE_STRING(info->h_name);
- RESPONSE_STRING(info->h_addrtype == AF_INET ? "AF_INET" : "AF_INET6");
-
- struct in_addr** addr_list = (struct in_addr**)info->h_addr_list;
- int i;
- for (i = 0; addr_list[i] != NULL; i++) {
- if (info->h_addrtype == AF_INET) {
- RESPONSE_STRING(inet_ntoa(*addr_list[i]));
- } else { // IPv6
- char addr_str[INET6_ADDRSTRLEN];
- inet_ntop(AF_INET6, addr_list[i], addr_str, sizeof(addr_str));
- RESPONSE_STRING(addr_str);
- }
- }
- return 0;
-}
-
-/**
- * Handle a call to connect() made by JavaScript.
- *
- * connect expects 2 parameters:
- * 0: The hostname to connect to.
- * 1: The port number to connect to.
- * on success, connect returns a result in |output|:
- * 0: "connect"
- * 1: The socket file descriptor.
- * on failure, connect returns an error string in |out_error|.
- */
-int HandleConnect(struct PP_Var params,
- struct PP_Var* output,
- const char** out_error) {
- CHECK_PARAM_COUNT(connect, 2);
- PARAM_STRING(0, hostname);
- PARAM_INT(1, port);
-
- // Lookup host
- struct hostent* hostent = gethostbyname(hostname);
- if (hostent == NULL) {
- *out_error = PrintfToNewString("gethostbyname() returned error: %d", errno);
- return 1;
- }
-
- struct sockaddr_in addr;
- socklen_t addrlen = sizeof(addr);
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- memcpy(&addr.sin_addr.s_addr, hostent->h_addr_list[0], hostent->h_length);
-
- int sock = socket(AF_INET, SOCK_STREAM, 0);
- if (sock < 0) {
- *out_error = PrintfToNewString("socket() failed: %s", strerror(errno));
- return 1;
- }
-
- int result = connect(sock, (struct sockaddr*)&addr, addrlen);
- if (result != 0) {
- *out_error = PrintfToNewString("connect() failed: %s", strerror(errno));
- close(sock);
- return 1;
- }
-
- CREATE_RESPONSE(connect);
- RESPONSE_INT(sock);
- return 0;
-}
-
-/**
- * Handle a call to send() made by JavaScript.
- *
- * send expects 2 parameters:
- * 0: The socket file descriptor to send using.
- * 1: The NULL terminated string to send.
- * on success, send returns a result in |output|:
- * 0: "send"
- * 1: The number of bytes sent.
- * on failure, send returns an error string in |out_error|.
- */
-int HandleSend(struct PP_Var params,
- struct PP_Var* output,
- const char** out_error) {
- CHECK_PARAM_COUNT(send, 2);
- PARAM_INT(0, sock);
- PARAM_STRING(1, buffer);
-
- int result = send(sock, buffer, strlen(buffer), 0);
- if (result <= 0) {
- *out_error = PrintfToNewString("send failed: %s", strerror(errno));
- return 1;
- }
-
- CREATE_RESPONSE(send);
- RESPONSE_INT(result);
- return 0;
-}
-
-/**
- * Handle a call to recv() made by JavaScript.
- *
- * recv expects 2 parameters:
- * 0: The socket file descriptor to recv from.
- * 1: The size of the buffer to pass to recv.
- * on success, send returns a result in |output|:
- * 0: "recv"
- * 1: The number of bytes received.
- * 2: The data received.
- * on failure, recv returns an error string in |out_error|.
- */
-int HandleRecv(struct PP_Var params,
- struct PP_Var* output,
- const char** out_error) {
- CHECK_PARAM_COUNT(recv, 2);
- PARAM_INT(0, sock);
- PARAM_INT(1, buffersize);
-
- if (buffersize < 0 || buffersize > 65 * 1024) {
- *out_error =
- PrintfToNewString("recv buffersize must be between 0 and 65k.");
- return 1;
- }
-
- char* buffer = alloca(buffersize);
- memset(buffer, 0, buffersize);
- int result = recv(sock, buffer, buffersize, 0);
- if (result <= 0) {
- *out_error = PrintfToNewString("recv failed: %s", strerror(errno));
- return 1;
- }
-
- CREATE_RESPONSE(recv);
- RESPONSE_INT(result);
- RESPONSE_STRING(buffer);
- return 0;
-}
-
-/**
- * Handle a call to close() made by JavaScript.
- *
- * close expects 1 parameters:
- * 0: The socket file descriptor to close.
- * on success, close returns a result in |output|:
- * 0: "close"
- * 1: The socket file descriptor closed.
- * on failure, close returns an error string in |out_error|.
- */
-int HandleClose(struct PP_Var params,
- struct PP_Var* output,
- const char** out_error) {
- CHECK_PARAM_COUNT(close, 1);
- PARAM_INT(0, sock);
-
- int result = close(sock);
- if (result != 0) {
- *out_error = PrintfToNewString("close returned error: %d", errno);
- return 1;
- }
-
- CREATE_RESPONSE(close);
- RESPONSE_INT(sock);
- return 0;
-}

Powered by Google App Engine
This is Rietveld 408576698