Fixed bug with unallowed characters
[ArenaLive.git] / core.c
blobd0fc8a30a55ce53573f1711714a6e44d04515dda
1 /*
2 * (C) Copyright 2009 ZeXx86 (zexx86@gmail.com)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Based on GLugin http://exa.czweb.org/repos/glugin.tar.bz2
19 * Big thanks for "exa"
23 #include "glugin.h"
24 #include <GL/gl.h>
25 #include <GL/glu.h>
26 #include <unistd.h>
27 #include <math.h>
29 void guest_read_host_requests (pluginData *pd)
31 int cmd;
32 NPStream *s;
34 if (fread (&cmd, sizeof (int), 1, pd->pr) <= 0)
35 return; //no data
37 switch (cmd) {
38 case gln_new_stream:
39 fread (&s, sizeof (s), 1, pd->pr);
41 pd->handle_newstream (pd,s);
42 break;
43 case gln_destroy_stream:
44 fread (&s, sizeof (s), 1, pd->pr);
46 pd->handle_destroystream (pd, s);
47 break;
48 case gln_stream_data:
50 int32 off, len;
51 void *data;
53 fread (&s, sizeof (s), 1, pd->pr);
54 fread (&off, sizeof (off), 1, pd->pr);
55 fread (&len, sizeof (len), 1, pd->pr);
57 if (len > 0) {
58 data = malloc (len);
60 fread (data,len,1,pd->pr);
62 pd->handle_write (pd, s, off, len, data);
64 free (data);
65 } else
66 Log ("w: zero len!");
68 break;
69 default:
70 Log ("Unhandled request to guest: %d", cmd);
74 void guest_newstream (pluginData *pd, NPStream *s)
76 Log ("guest has NEWSTREAM: %p",s);
79 void guest_destroystream (pluginData *pd, NPStream *s)
81 Log ("guest has DESTROYSTREAM: %p",s);
84 void guest_write (pluginData *pd, NPStream*s, int32 off, int32 len, void *data)
86 Log ("guest has WRITE: %p %d %d, data followz:", s, off, len);
88 int i;
89 for (i = 0; i < len; ++ i)
90 Log ("%8X: %c",i, ((char *) data)[i]);
93 void glugin_proc (pluginData *pd)
95 while (!(pd->exit_request)) {
96 guest_read_host_requests (pd);
98 usleep (1000);
101 pd->exit_ack = 1;