$ git clone https://socialnetwork.ion.nu/socialnetwork-web.git
commit b523250738402537d3d26e8b9b11205dad50952b
Author: Alicia <...>
Date: Fri Jun 30 06:37:46 2017 +0200
Dropped the jsglue file functions in favor of emscripten's FS API.
diff --git a/Makefile b/Makefile
index 04aeb62..b2787f2 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@ toolchain/usr/lib/libsocial.so: toolchain/usr/bin/emcc
./buildlibs.sh '$(GMPVERSION)' '$(NETTLEVERSION)' '$(GNUTLSVERSION)'
libsocial.js: jsglue.c toolchain/usr/lib/libsocial.so
- toolchain/usr/bin/emcc -O3 -s EXPORTED_FUNCTIONS="['_social_init','_peer_handlesocket','_peer_new_unique','_websockproxy_read','_websockproxy_setwrite','_jsglue_addfile']" -s RESERVED_FUNCTION_POINTERS=1 -s NO_EXIT_RUNTIME=1 -s NODEJS_CATCH_EXIT=0 -s EXPORTED_RUNTIME_METHODS="['ccall','cwrap']" -s INVOKE_RUN=0 $(JSCFLAGS) $^ $(JSLIBS) -o $@
+ toolchain/usr/bin/emcc -O3 -s EXPORTED_FUNCTIONS="['_social_init','_peer_handlesocket','_peer_new_unique','_websockproxy_read','_websockproxy_setwrite','_jsglue_addfile']" -s RESERVED_FUNCTION_POINTERS=1 -s NO_EXIT_RUNTIME=1 -s NODEJS_CATCH_EXIT=0 -s EXPORTED_RUNTIME_METHODS="['ccall','cwrap','readFile','writeFile']" -s INVOKE_RUN=0 $(JSCFLAGS) $^ $(JSLIBS) -o $@
./squeezeandcomment.sh '$@' 'This code was built from gmp $(GMPVERSION), nettle $(NETTLEVERSION), gnutls $(GNUTLSVERSION) and socialnetwork git revision $(SOCIALNETWORKREVISION) with tweaks from socialnetwork-web git revision $(REVISION) using emscripten (fastcomp) $(EMSCRIPTVERSION)'
# Download all external sources we'll need
diff --git a/jsglue.c b/jsglue.c
index deb8f25..d5ae414 100644
--- a/jsglue.c
+++ b/jsglue.c
@@ -24,97 +24,6 @@
#include "jsglue.h"
extern struct udpstream* stream_new(int sock, struct sockaddr_storage* addr, socklen_t addrlen);
-struct file
-{
- char* name;
- void* content;
- size_t size;
-};
-
-struct fileinfo
-{
- struct file* file;
- unsigned int pos;
-};
-
-static struct file* files=0;
-static unsigned int filecount=0;
-static struct fileinfo* fds=0;
-static unsigned int fdcount=0;
-
-static struct file* getfile(const char* path)
-{
- unsigned int i;
- for(i=0; i<filecount; ++i)
- {
- if(!strcmp(files[i].name, path)){return &files[i];}
- }
- return 0;
-}
-
-ssize_t jsglue_read(int fd, void* buf, size_t size)
-{
- if(fd<0){return -1;}
- if(size>fds[fd].file->size-fds[fd].pos){size=fds[fd].file->size-fds[fd].pos;}
- memcpy(buf, fds[fd].file->content+fds[fd].pos, size);
- return size;
-}
-
-ssize_t jsglue_write(int fd, const void* buf, size_t size)
-{
-// TODO: Writing
- return size;
-}
-
-int jsglue_open(const char* path, int flags, mode_t mode)
-{
- struct file* f=getfile(path);
- if(!f){return -1;}
- unsigned int i;
- for(i=0; i<fdcount; ++i)
- {
- if(!fds[i].file){break;}
- }
- if(i==fdcount)
- {
- fds=realloc(fds, (++fdcount)*sizeof(struct fileinfo));
- }
- fds[i].file=f;
- fds[i].pos=0;
- return i;
-}
-
-int jsglue_stat(const char* path, struct stat* st)
-{
- struct file* f=getfile(path);
- if(!f){return 1;}
- st->st_size=f->size;
- return 0;
-}
-
-void jsglue_close(int fd)
-{
- fds[fd].file=0;
-}
-
-void jsglue_addfile(const char* path, const void* data, size_t size)
-{
- struct file* f=getfile(path);
- if(!f) // New file
- {
- ++filecount;
- files=realloc(files, filecount*sizeof(struct file));
- f=&files[filecount-1];
- }else{ // Overwrite old
- free(f->name);
- free(f->content);
- }
- f->name=strdup(path);
- f->content=malloc(size);
- memcpy(f->content, data, size);
- f->size=size;
-}
-
void(*websockproxy_write)(struct sockaddr_storage*, socklen_t, const void*, size_t);
void websockproxy_setwrite(void(*writefunc)(struct sockaddr_storage*, socklen_t, const void*, size_t))
{
diff --git a/jsglue.h b/jsglue.h
index bde4eae..efd833d 100644
--- a/jsglue.h
+++ b/jsglue.h
@@ -17,18 +17,5 @@
#include <unistd.h> // Include it first because we're going to override some functions from there, but don't want to get any mess from the declarations
#include <fcntl.h>
#include <sys/socket.h>
-#include <sys/stat.h>
-#define read(fd,buf,size) jsglue_read(fd,buf,size)
-#define write(fd,buf,size) jsglue_write(fd,buf,size)
-#define open(path,flags,...) jsglue_open(path,flags,0)
-#define stat(path,st) jsglue_stat(path,st)
-#define close(fd) jsglue_close(fd)
-#define mkdir(path,mode) 0 // Screw directories :)
-
-extern ssize_t jsglue_read(int fd, void* buf, size_t size);
-extern ssize_t jsglue_write(int fd, const void* buf, size_t size);
-extern int jsglue_open(const char* path, int flags, mode_t mode);
-extern int jsglue_stat(const char* path, struct stat* st);
-extern void jsglue_close(int fd);
extern void(*websockproxy_write)(struct sockaddr_storage*, socklen_t, const void*, size_t);
diff --git a/libsocialjs.js b/libsocialjs.js
index 0bb0e8a..557afed 100644
--- a/libsocialjs.js
+++ b/libsocialjs.js
@@ -60,7 +60,7 @@ function init(privkey)
websockproxy_read=Module.cwrap('websockproxy_read', null, ['array', 'number', 'array', 'number']);
peer_new_unique=Module.cwrap('peer_new_unique', 'array', ['number', 'array', 'number']);
_websockproxy_setwrite(Runtime.addFunction(websockwrite));
- Module.ccall('jsglue_addfile', null, ['string', 'string', 'number'], ['privkey.pem', privkey, privkey.length]);
+ FS.writeFile('privkey.pem', privkey, {});
Module.ccall('social_init', null, ['string', 'string'], ['privkey.pem', '']);
connection=new WebSocket('wss://'+document.domain+':5000/', 'socialwebsock-0.1');
connection.onmessage=handlenet;
diff --git a/websocial.js b/websocial.js
index c67523d..14bc944 100644
--- a/websocial.js
+++ b/websocial.js
@@ -11,7 +11,8 @@ function initgui()
chdisplay('login_window',false);
if(key=='')
{
-// TODO: get the generated key and hand it to the user (as text or fileblob? or both?)
+ alert('Key:\n'+FS.readFile('privkey.pem', {'encoding':'utf8'}));
+// TODO: Display generated key in a nicer modal window, possibly with a fileblob download option
}
// TODO: display any updates we may have (actually we probably won't have any yet, update when we get them, callback for 'updates' command?)
}