32 #include "../threads.h"
34 #include <libFreeWRL.h>
39 #include "../vrml_parser/Structs.h"
40 #include "../main/headers.h"
41 #include "../main/MainLoop.h"
42 #include "../input/EAIHeaders.h"
44 #include "../x3d_parser/Bindable.h"
45 #include "../opengl/OpenGL_Utils.h"
46 #include "../scenegraph/RenderFuncs.h"
47 #include "../main/ProdCon.h"
48 #include "pluginUtils.h"
49 #include "PluginSocket.h"
51 #define UNUSED(v) ((void) v)
53 static int checkIfX3DVRMLFile(
char *fn);
62 #define MAXPROCESSLIST 128
63 pid_t childProcess[MAXPROCESSLIST];
64 int lastchildProcess = 0;
65 int childProcessListInit = FALSE;
72 int waitingForURLtoLoad;
75 void *pluginUtils_constructor(){
80 void pluginUtils_init(
struct tpluginUtils *t){
83 t->prv = pluginUtils_constructor();
87 p->waitingForURLtoLoad = FALSE;
94 void killErrantChildren(
void) {
98 for (count = 0; count < MAXPROCESSLIST; count++) {
99 if (childProcess[count] != 0) {
102 kill (childProcess[count],SIGINT);
110 void goToViewpoint(
char *vp) {
114 struct tProdCon *t = &gglobal()->ProdCon;
117 localNode = EAI_GetViewpoint(vp);
120 if (localNode != NULL) {
121 for (flen=0; flen<vectorSize(t->viewpointNodes);flen++) {
122 if (localNode == vector_get(
struct X3D_Node *,t->viewpointNodes,flen)) {
126 send_bind_to((
struct X3D_Node*)vp,0);
127 t->currboundvpno=flen;
129 send_bind_to((
struct X3D_Node*)vp,1);
137 #if !defined(_MSC_VER) && !defined(ANDROIDNDK)
138 void startNewHTMLWindow(
char *url) {
141 #define ERRLINELEN 4200
142 char sysline[LINELEN];
144 char syslineFailed[ERRLINELEN];
156 browser = freewrl_get_browser_program();
158 ConsoleMessage (
"Error: no Internet browser found.");
164 if (browser) testlen = (int) strlen(browser);
166 testlen += (int) strlen(url) + 10;
167 if (testlen > LINELEN) {
168 ConsoleMessage (
"Anchor: combination of browser name and file name too long.");
171 if (browser) strcpy (sysline, browser);
172 else strcpy (sysline, browser);
173 strcat (sysline,
" ");
174 strcat (sysline, url);
175 strcat (sysline,
" &");
176 freewrlSystem (sysline);
180 if (browser) sprintf(sysline,
"%s %s &", browser, url);
181 else sprintf(sysline,
"open %s &", url);
182 sysReturnCode = system (sysline);
183 if (sysReturnCode < 0) {
184 sprintf(syslineFailed ,
"ERR %s %d system call failed, returned %d. Was: %s\n",__FILE__,__LINE__,sysReturnCode,sysline);
185 ConsoleMessage (syslineFailed);
199 static int urlLoadingStatus() {
205 switch (p->plugin_res->status) {
206 case ress_downloaded:
208 EAI_Anchor_Response(TRUE);
209 p->waitingForURLtoLoad = FALSE;
212 ConsoleMessage (
"Failed to load URL\n");
213 EAI_Anchor_Response(FALSE);
214 p->waitingForURLtoLoad = FALSE;
219 return p->waitingForURLtoLoad;
225 int doBrowserAction()
237 if (p->waitingForURLtoLoad)
return urlLoadingStatus();
241 if (AnchorsAnchor() != NULL) {
243 Anchor_url = AnchorsAnchor()->url;
244 description = AnchorsAnchor()->description->strptr;
246 TRACE_MSG(
"doBrowserAction: description: %s\n", description);
249 if (Anchor_url.n <= 0) {
251 setAnchorsAnchor( NULL );
275 if (Anchor_url.p[0]->strptr[0] ==
'#') {
276 setAnchorsAnchor( NULL );
277 fwl_gotoViewpoint(&(Anchor_url.p[0]->strptr[1]));
282 p->plugin_res = resource_create_multi0(&AnchorsAnchor()->url);
283 #define DO_THIS_BLOC 1
284 #ifdef DO_THIS_BLOC //EXPERIMENT_FAILED
296 for (i = 0; i < Anchor_url.n; i++)
297 isScene = isScene && checkIfX3DVRMLFile(Anchor_url.p[i]->strptr);
299 resource_identify(parentPath, p->plugin_res);
300 fwl_replaceWorldNeededRes(p->plugin_res);
305 p->plugin_res->actions = resa_download;
306 p->plugin_res->media_type = resm_external;
307 p->plugin_res->type = rest_multi;
308 resource_identify(parentPath, p->plugin_res);
309 resitem_enqueue(ml_new(p->plugin_res));
315 Multi_String_print(&AnchorsAnchor()->url);
316 PRINTF(
"parent resource: \n");
317 resource_dump(parentPath);
318 PRINTF(
"file resource: \n");
319 resource_dump(p->plugin_res);
325 head_of_list = p->plugin_res->m_request;
330 resource_identify(parentPath, p->plugin_res);
333 p->plugin_res->media_type = resm_image;
335 if (resource_fetch(p->plugin_res)) {
341 if (checkIfX3DVRMLFile(p->plugin_res->actual_file)) {
345 kill_oldWorld(TRUE,TRUE,__FILE__,__LINE__);
349 resToLoad = resource_create_single(p->plugin_res->actual_file);
350 resToLoad->afterPoundCharacters = p->plugin_res->afterPoundCharacters;
352 send_resource_to_parser(resToLoad);
353 p->waitingForURLtoLoad = TRUE;
363 kill_oldWorld(TRUE,TRUE,__FILE__,__LINE__);
367 resToLoad = resource_create_single(p->plugin_res->parsed_request);
368 resToLoad->afterPoundCharacters = p->plugin_res->afterPoundCharacters;
370 send_resource_to_parser(resToLoad);
372 p->waitingForURLtoLoad = TRUE;
375 p->plugin_res->complete = TRUE;
376 startNewHTMLWindow(p->plugin_res->parsed_request);
381 p->plugin_res->type=rest_multi;
383 }
while ((p->plugin_res->status != ress_downloaded) && (p->plugin_res->m_request != NULL));
386 if (head_of_list != NULL) {
387 ml_delete_all(head_of_list);
391 if (p->plugin_res->status != ress_loaded) {
392 ERROR_MSG(
"Could not load new world: %s\n", p->plugin_res->actual_file);
415 static int checkIfX3DVRMLFile(
char *fn) {
416 if ((strstr(fn,
".wrl") > 0) ||
417 (strstr(fn,
".WRL") > 0) ||
418 (strstr(fn,
".x3d") > 0) ||
419 (strstr(fn,
".x3z") > 0) ||
420 (strstr(fn,
".x3dv") > 0) ||
421 (strstr(fn,
".x3db") > 0) ||
422 (strstr(fn,
".X3DV") > 0) ||
423 (strstr(fn,
".X3DB") > 0) ||
424 (strstr(fn,
".X3D") > 0)) {
444 bool Anchor_ReplaceWorld(
const char *name)
446 gglobal()->Mainloop.replaceWorldRequest = STRDUP(name);
465 char tohex (
int mychar) {
466 if (mychar <10)
return (mychar +
'0');
467 else return (mychar - 10 +
'A');
471 int URLmustEncode(
int ch) {
487 || (ch == 0x60))
return TRUE;
496 void URLprint (
const char *m,
const char *p) {
500 tty = fopen(
"/home/luigi/logURLencod",
"w");
503 fprintf (tty,
"\nplugin restarted\n");
506 fprintf (tty,
"%f URLprint: ",TickTime());
514 void URLencod (
char *dest,
const char *src,
int maxlen) {
526 URLprint (
"going to start URLencod %s\n",
"on a string");
527 URLprint (
"start, src is %s\n",src);
532 mylen = (int) strlen(src);
539 for (sctr = 0; sctr < mylen; sctr ++) {
540 curchar = (int) *src; src++;
543 if (URLmustEncode(curchar)) {
544 *dest =
'%'; dest ++;
545 *dest = tohex ((curchar >> 4) & 0x0f); dest++;
546 *dest = tohex (curchar & 0x0f); dest++;
549 *dest = (char) curchar; destctr++; dest++;
555 if (destctr > (maxlen - 5)) {
562 URLprint (
"encoded string is %s\n",orig);
569 #if !defined(_MSC_VER) && !defined(_ANDROID) && !defined(ANDROIDNDK) && !defined(GLES2)
571 void sendXwinToPlugin()
573 int writeSizeThrowAway ;
574 UNUSED(writeSizeThrowAway);
577 DEBUG_MSG(
"Executing sendXwinToPlugin...\n");
580 XWindowAttributes mywin;
582 XGetWindowAttributes(Xdpy,Xwin, &mywin);
583 DEBUG_MSG(
"sendXwinToPlugin: sendXwin starting, mapped_state %d, IsUnmapped %d, isUnviewable %d isViewable %d\n",mywin.map_state, IsUnmapped, IsUnviewable, IsViewable);
585 DEBUG_MSG(
"sendXwinToPlugin: sending Xwin ID back to plugin - %lu bytes\n",
sizeof (Xwin));
587 writeSizeThrowAway = write (_fw_pipe,&Xwin,
sizeof(Xwin));
591 XGetWindowAttributes(Xdpy,Xwin, &mywin);
593 while (mywin.map_state == IsUnmapped) {
595 XGetWindowAttributes(Xdpy,Xwin, &mywin);
597 printf (
"sendXwin in sleep loope, mapped_state %d, IsUnmapped %d, isUnviewable %d isViewable %d\n",mywin.map_state, IsUnmapped, IsUnviewable, IsViewable);
603 XGetWindowAttributes(Xdpy,Xwin, &mywin);
604 printf (
"sendXwin at end, mapped_state %d, IsUnmapped %d, isUnviewable %d isViewable %d\n",mywin.map_state, IsUnmapped, IsUnviewable, IsViewable);
605 printf (
"x %d y %d wid %d height %d\n",mywin.x,mywin.y,mywin.width,mywin.height);