From 93b6031770d65e53e51d1f13cec3d1b2c06ee94c Mon Sep 17 00:00:00 2001 From: Tomas 'ZeXx86' Jedrzejek Date: Sat, 28 Mar 2009 19:55:58 +0100 Subject: [PATCH] Updated source, makefile for x86 and x86_64 is ready --- Makefile | 9 ++++- Makefile => Makefile32 | 11 ++++-- action.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++ glugin.h | 3 +- ns-unix.c | 103 +++++++------------------------------------------ push.sh | 10 +++++ 6 files changed, 141 insertions(+), 95 deletions(-) copy Makefile => Makefile32 (79%) create mode 100644 action.c create mode 100755 push.sh diff --git a/Makefile b/Makefile index 9ebf208..2ebcdb0 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,11 @@ CC =gcc INCLUDE =-I/usr/include/xulrunner-1.9/stable -I/usr/include/nspr CFLAGS =-Wall -fPIC LIBS =-lGL -lGLU -lm -LIBSPATH =-L/usr/lib64/nspr -Wl,-R/usr/lib64/nspr +LIBSPATH =-L/usr/lib/nspr -Wl,-R/usr/lib/nspr -OBJS =ns-unix.o core.o common.o +OBJS =ns-unix.o core.o common.o action.o OUTPUT =libglugin.so + Q := @ .PHONY: build @@ -23,6 +24,9 @@ install: $(Q)cp libglugin.so ~/.mozilla/plugins/libglugin.so -v @printf " CP ${OUTPUT}\n" +pack: + zip firefox-linux-x86-64.zip $(OUTPUT) + .c.o: @printf " CC $(subst $(shell pwd)/,,$(@))\n"; $(Q)$(CC) $(CFLAGS) $(INCLUDE) -c -o$@ $< @@ -30,6 +34,7 @@ install: ns-unix.o: ns-unix.c $(MAKEFILE) core.o: core.c $(MAKEFILE) common.o: common.c $(MAKEFILE) +action.o: action.c $(MAKEFILE) ${OUTPUT}: $(OBJS) $(MAKEFILE) @printf " LD $(subst $(shell pwd)/,,$(@))\n"; diff --git a/Makefile b/Makefile32 similarity index 79% copy from Makefile copy to Makefile32 index 9ebf208..c81cacb 100644 --- a/Makefile +++ b/Makefile32 @@ -1,12 +1,13 @@ MAKEFILE =Makefile -CC =gcc +CC =gcc -m32 INCLUDE =-I/usr/include/xulrunner-1.9/stable -I/usr/include/nspr CFLAGS =-Wall -fPIC LIBS =-lGL -lGLU -lm -LIBSPATH =-L/usr/lib64/nspr -Wl,-R/usr/lib64/nspr +LIBSPATH =-L/usr/lib/nspr -Wl,-R/usr/lib/nspr -OBJS =ns-unix.o core.o common.o +OBJS =ns-unix.o core.o common.o action.o OUTPUT =libglugin.so + Q := @ .PHONY: build @@ -23,6 +24,9 @@ install: $(Q)cp libglugin.so ~/.mozilla/plugins/libglugin.so -v @printf " CP ${OUTPUT}\n" +pack: + zip firefox-linux-x86.zip $(OUTPUT) + .c.o: @printf " CC $(subst $(shell pwd)/,,$(@))\n"; $(Q)$(CC) $(CFLAGS) $(INCLUDE) -c -o$@ $< @@ -30,6 +34,7 @@ install: ns-unix.o: ns-unix.c $(MAKEFILE) core.o: core.c $(MAKEFILE) common.o: common.c $(MAKEFILE) +action.o: action.c $(MAKEFILE) ${OUTPUT}: $(OBJS) $(MAKEFILE) @printf " LD $(subst $(shell pwd)/,,$(@))\n"; diff --git a/action.c b/action.c new file mode 100644 index 0000000..5541c03 --- /dev/null +++ b/action.c @@ -0,0 +1,100 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "glugin.h" + +int plugin_action_0 (pluginData *pd) +{ + Log ("action_0"); + + return creat ("/tmp/.arenalivep", 0777); +} + + +int plugin_action_1 (pluginData *pd) +{ + int s, s2, t, l; + struct sockaddr_un local, remote; + + if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) == -1) { + Log ("socket == -1"); + return -1; + } + + local.sun_family = AF_UNIX; + strcpy (local.sun_path, "/tmp/.arenalive"); + unlink (local.sun_path); + + l = strlen (local.sun_path) + sizeof (local.sun_family); + + if (bind (s, (struct sockaddr *) &local, l) == -1) { + Log ("bind == -1"); + return -1; + } + + if (listen (s, 5) == -1) + return -1; + + t = sizeof (remote); + + pid_t child = fork (); + + if (child == -1) + return -1; + + if (!child) { + char *user = getenv ("USER"); + + if (!user) + return -1; + + char cmd[512]; + sprintf (cmd, "/home/%s/.arenalive/%s %s &> /home/%s/.arenalive/log", + user, "arenalive-linux", pd->conparam, user); + + Log ("-- %s", cmd); + + system (cmd); + + /*system ("/home/tomas/Programming/arenalive/ioquake3_1.34-rc3/build/release-linux-x86_64/ioquake3.x86_64 +set fs_basepath \"/usr/share/games/quake3/\" +set r_fullscreen 0 +set r_mode 4 &> /home/tomas/glugin/log");*/ + + _exit (0); + } + + if ((s2 = accept (s, (struct sockaddr *) &remote, (unsigned *) &t)) == -1) { + Log ("accept == -1"); + return -1; + } + + char str[sizeof (Window)+1]; + + memcpy (str, &pd->win, sizeof (Window)); + + if (send (s2, str, sizeof (Window), 0) < 0) + return -1; + + close (s2); + + /* plugin loop */ + glugin_proc (pd); + + return 0; +} + +int plugin_action (pluginData *pd) +{ + switch (pd->action) { + case 0: + return plugin_action_0 (pd); + case 1: + return plugin_action_1 (pd); + } + + return -1; +} + diff --git a/glugin.h b/glugin.h index bf69ed1..842069d 100644 --- a/glugin.h +++ b/glugin.h @@ -48,6 +48,7 @@ void host_newstream (pluginData *, NPStream *); void host_destroystream (pluginData *, NPStream *); void host_write (pluginData *, NPStream *, int32, int32, void *); void host_read_guest_requests (pluginData *); - void guest_read_host_requests (pluginData *); +extern int plugin_action (pluginData *pd); + diff --git a/ns-unix.c b/ns-unix.c index 643fcb7..76622c2 100644 --- a/ns-unix.c +++ b/ns-unix.c @@ -324,91 +324,16 @@ void swapbuffers (pluginData *pd) glXSwapBuffers (pd->dpy, pd->win); } -int plugin_action_0 (pluginData *pd) -{ - Log ("action_0"); - - return creat ("/tmp/.arenalivep", 0777); -} - -#include -#include -int plugin_action_1 (pluginData *pd, Window win) -{ - int s, s2, t, l; - struct sockaddr_un local, remote; - - if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) == -1) { - Log ("socket == -1"); - return -1; - } - - local.sun_family = AF_UNIX; - strcpy (local.sun_path, "/tmp/.arenalive"); - unlink (local.sun_path); - - l = strlen (local.sun_path) + sizeof (local.sun_family); - - if (bind (s, (struct sockaddr *) &local, l) == -1) { - Log ("bind == -1"); - return -1; - } - - if (listen (s, 5) == -1) - return -1; - - t = sizeof (remote); - - pid_t child = fork (); - - if (child == -1) - return -1; - - if (!child) { - char cmd[512]; - sprintf (cmd, "%s +set fs_basepath %s %s %s", "/home/tomas/Programming/arenalive/ioquake3_1.34-rc3/build/release-linux-x86_64/ioquake3.x86_64", - "\"/usr/share/games/quake3/\"", pd->conparam, "&> /home/tomas/glugin/log"); - - Log ("-- %s", cmd); - - system (cmd); - - /*system ("/home/tomas/Programming/arenalive/ioquake3_1.34-rc3/build/release-linux-x86_64/ioquake3.x86_64 +set fs_basepath \"/usr/share/games/quake3/\" +set r_fullscreen 0 +set r_mode 4 &> /home/tomas/glugin/log");*/ - - _exit (0); - } - - if ((s2 = accept (s, (struct sockaddr *) &remote, (unsigned *) &t)) == -1) { - Log ("accept == -1"); - return -1; - } - - char str[sizeof (Window)+1]; - - memcpy (str, &win, sizeof (Window)); - - if (send (s2, str, sizeof (Window), 0) < 0) - return -1; - - close (s2); - - /* plugin loop */ - glugin_proc (pd); - - return 0; -} - - void plugin_process_handler (pluginData *pd, Window win, Visual *vis) { g_pd = pd; + pd->win = win; + signal (SIGUSR1, sig_usr1); - if (pd->action == 0) - plugin_action_0 (pd); - else if (pd->action == 1) - plugin_action_1 (pd, win); + /* call action function */ + plugin_action (pd); Log ("plugin killed, cleaning up."); @@ -422,33 +347,33 @@ void plugin_process_handler (pluginData *pd, Window win, Visual *vis) free (pd->conparam); } -void writedata (FILE*f, int x, unsigned len) +void writedata (FILE *f, void *x, unsigned len) { - fwrite (&x, len, sizeof (char), f); + fwrite (x, len, sizeof (char), f); } void host_newstream (pluginData *pd, NPStream *s) { - writedata (pd->pw, (int) gln_new_stream, sizeof (int)); - writedata (pd->pw, s, sizeof (NPStream)); + writedata (pd->pw, (void *) gln_new_stream, sizeof (int)); + writedata (pd->pw, (void *) &s, sizeof (NPStream)); fflush (pd->pw); } void host_destroystream (pluginData*pd, NPStream*s) { - writedata (pd->pw, (int) gln_destroy_stream, sizeof (int)); - writedata (pd->pw, s, sizeof (NPStream)); + writedata (pd->pw, (void *) gln_destroy_stream, sizeof (int)); + writedata (pd->pw, (void *) s, sizeof (NPStream)); fflush (pd->pw); } void host_write (pluginData *pd, NPStream *s, int32 off, int32 siz, void *data) { - writedata (pd->pw, (int) gln_stream_data, sizeof (int)); - writedata (pd->pw, s, sizeof (NPStream)); - writedata (pd->pw, off, sizeof (off)); - writedata (pd->pw, siz, sizeof (off)); + writedata (pd->pw, (void *) gln_stream_data, sizeof (int)); + writedata (pd->pw, (void *) s, sizeof (NPStream)); + writedata (pd->pw, (void *) &off, sizeof (off)); + writedata (pd->pw, (void *) &siz, sizeof (off)); fwrite (data, siz, sizeof (char), pd->pw); diff --git a/push.sh b/push.sh new file mode 100755 index 0000000..843b6a0 --- /dev/null +++ b/push.sh @@ -0,0 +1,10 @@ +#!/bin/sh +params="" + +if [ -z "$@" ] ; +then params='--all' +else params="$@" +fi + +exec git push 'ssh://repo.or.cz/srv/git/ArenaLive.git' $params + -- 2.11.4.GIT