Permalink
Browse files

read clientsecrets on startup from ./clientsecrets

  • Loading branch information...
1 parent 54276cc commit ad472a3f1033809201fafe7f35d9f78cf9d9330a @jcline jcline committed Apr 26, 2012
Showing with 68 additions and 4 deletions.
  1. +5 −4 gd_fuse_operations.c
  2. +54 −0 gd_interface.c
  3. +9 −0 gd_interface.h
View
@@ -397,20 +397,21 @@ struct fuse_operations gd_oper = {
* Store any state about this mount in this structure.
*
* root: The path to the mount point of the drive.
- * TODO:
- * Tokens - should they be char*s?
+ * credentials: Struct which stores necessary credentials for this mount.
*/
struct gd_state {
char* root;
+ struct gdi_state credentials;
};
int main(int argc, char* argv[])
{
int fuse_stat;
struct gd_state gd_data;
- char url[] = "http://www.google.com";
- urlencode(url, strlen(url));
+ int ret = gdi_init(&gd_data.credentials);
+ if(ret != 0)
+ return ret;
// Start fuse
fuse_stat = fuse_main(argc, argv, &gd_oper, &gd_data);
View
@@ -16,9 +16,12 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <errno.h>
+#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <unistd.h>
#include "gd_interface.h"
@@ -97,3 +100,54 @@ char* urlencode (const char *url, size_t length)
result[(length+count*3)-1] = 0;
return result;
}
+
+
+int gdi_get_credentials()
+{
+ return 0;
+}
+
+/** Reads in the clientsecrets from a file.
+ *
+ */
+char* gdi_load_clientsecrets(const char *path)
+{
+ FILE *f = fopen(path, "rb");
+ if(f == NULL)
+ {
+ printf("fopen(\"%s\"): %s\n", path, strerror(errno));
+ return NULL;
+ }
+
+ fseek(f, 0, SEEK_END);
+ size_t size = ftell(f);
+ rewind(f);
+ char *result = (char *) malloc(sizeof(char) * size);
+ if(result == NULL)
+ {
+ perror("malloc");
+ return NULL;
+ }
+
+ fread(result, 1, size, f);
+ if(ferror(f))
+ {
+ printf("fread(\"%s\"): %s\n", path, strerror(errno));
+ return NULL;
+ }
+
+ return result;
+}
+
+int gdi_init(struct gdi_state* state)
+{
+ state->clientsecrets = gdi_load_clientsecrets("clientsecrets");
+ if(state->clientsecrets == NULL)
+ return 1;
+
+ return 0;
+}
+
+void gdi_destroy()
+{
+}
View
@@ -21,7 +21,16 @@
#include <stdlib.h>
+struct gdi_state {
+ char *clientsecrets;
+};
+
char* urlencode (const char *url, size_t length);
+int gdi_get_credentials();
+char* gdi_load_clientsecrets(const char *path);
+
+int gdi_init();
+void gdi_destroy();
#endif

0 comments on commit ad472a3

Please sign in to comment.