2001-09-07 00:32:54 +02:00
|
|
|
// natCore -- C++ side of Core
|
|
|
|
|
2007-01-09 20:58:05 +01:00
|
|
|
/* Copyright (C) 2001, 2002, 2003, 2005, 2006 Free Software Foundation
|
2001-09-07 00:32:54 +02:00
|
|
|
|
|
|
|
This file is part of libgcj.
|
|
|
|
|
|
|
|
This software is copyrighted work licensed under the terms of the
|
|
|
|
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
/* Author: Anthony Green <green@redhat.com>. */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <gcj/cni.h>
|
|
|
|
#include <jvm.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <java/lang/NullPointerException.h>
|
|
|
|
#include <java/io/IOException.h>
|
|
|
|
#include <gnu/gcj/Core.h>
|
|
|
|
|
2003-08-29 00:17:37 +02:00
|
|
|
// List of global core values.
|
|
|
|
static _Jv_core_chain *root;
|
|
|
|
|
|
|
|
static void
|
|
|
|
default_register_resource (_Jv_core_chain *node)
|
2001-09-07 00:32:54 +02:00
|
|
|
{
|
2003-08-29 00:17:37 +02:00
|
|
|
node->next = root;
|
|
|
|
root = node;
|
|
|
|
}
|
2001-09-07 00:32:54 +02:00
|
|
|
|
2003-08-29 00:17:37 +02:00
|
|
|
// This is set only when a lock is held on java.lang.Class.
|
|
|
|
// This function is called to handle a new core node.
|
|
|
|
void (*_Jv_RegisterCoreHook) (_Jv_core_chain *) = default_register_resource;
|
2001-09-07 00:32:54 +02:00
|
|
|
|
2003-08-29 00:17:37 +02:00
|
|
|
void
|
|
|
|
_Jv_RegisterResource (void *vptr)
|
2001-09-07 00:32:54 +02:00
|
|
|
{
|
2003-08-29 00:17:37 +02:00
|
|
|
char *rptr = (char *) vptr;
|
2001-09-07 00:32:54 +02:00
|
|
|
|
2003-08-29 00:17:37 +02:00
|
|
|
_Jv_core_chain *cc = (_Jv_core_chain *) _Jv_Malloc (sizeof (_Jv_core_chain));
|
2001-09-07 00:32:54 +02:00
|
|
|
|
|
|
|
cc->name_length = ((int *)rptr)[0];
|
|
|
|
cc->data_length = ((int *)rptr)[1];
|
2003-08-29 00:17:37 +02:00
|
|
|
cc->name = rptr + 2 * sizeof (int);
|
2001-09-07 00:32:54 +02:00
|
|
|
cc->data = cc->name + cc->name_length;
|
2003-08-29 00:17:37 +02:00
|
|
|
cc->next = NULL;
|
2001-09-07 00:32:54 +02:00
|
|
|
|
2003-08-29 00:17:37 +02:00
|
|
|
(*_Jv_RegisterCoreHook) (cc);
|
2001-09-07 00:32:54 +02:00
|
|
|
}
|
|
|
|
|
2003-08-29 00:17:37 +02:00
|
|
|
void
|
|
|
|
_Jv_FreeCoreChain (_Jv_core_chain *chain)
|
|
|
|
{
|
|
|
|
while (chain != NULL)
|
|
|
|
{
|
|
|
|
_Jv_core_chain *next = chain->next;
|
|
|
|
_Jv_Free (chain);
|
|
|
|
chain = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_Jv_core_chain *
|
|
|
|
_Jv_FindCore (_Jv_core_chain *node, jstring name)
|
2001-09-07 00:32:54 +02:00
|
|
|
{
|
2002-04-25 01:05:17 +02:00
|
|
|
char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (name) + 1);
|
2001-09-07 00:32:54 +02:00
|
|
|
jsize total = JvGetStringUTFRegion (name, 0, name->length(), buf);
|
|
|
|
buf[total] = '\0';
|
|
|
|
|
2002-04-25 01:05:17 +02:00
|
|
|
// Usually requests here end up as an absolute URL. We strip the
|
|
|
|
// initial `/'.
|
|
|
|
if (buf[0] == '/')
|
|
|
|
{
|
|
|
|
++buf;
|
|
|
|
--total;
|
|
|
|
}
|
|
|
|
|
2001-09-07 00:32:54 +02:00
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
if (total == node->name_length
|
|
|
|
&& strncmp (buf, node->name, total) == 0)
|
2003-08-29 00:17:37 +02:00
|
|
|
return node;
|
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gnu::gcj::Core *
|
|
|
|
_Jv_create_core (_Jv_core_chain *node, jstring name)
|
|
|
|
{
|
|
|
|
node = _Jv_FindCore (node, name);
|
|
|
|
|
|
|
|
gnu::gcj::Core *core = NULL;
|
|
|
|
if (node)
|
|
|
|
{
|
2004-04-16 18:27:19 +02:00
|
|
|
core = new gnu::gcj::Core ();
|
2003-08-29 00:17:37 +02:00
|
|
|
core->ptr = (gnu::gcj::RawData *) node->data;
|
|
|
|
core->length = node->data_length;
|
2001-09-07 00:32:54 +02:00
|
|
|
}
|
2003-08-29 00:17:37 +02:00
|
|
|
return core;
|
|
|
|
}
|
2001-09-07 00:32:54 +02:00
|
|
|
|
2005-06-04 13:23:29 +02:00
|
|
|
gnu::gcj::Core *
|
|
|
|
gnu::gcj::Core::find (jstring name)
|
|
|
|
{
|
|
|
|
gnu::gcj::Core *core = _Jv_create_core (root, name);
|
|
|
|
return core;
|
|
|
|
}
|
|
|
|
|
2003-08-29 00:17:37 +02:00
|
|
|
gnu::gcj::Core *
|
|
|
|
gnu::gcj::Core::create (jstring name)
|
|
|
|
{
|
|
|
|
gnu::gcj::Core *core = _Jv_create_core (root, name);
|
|
|
|
if (core == NULL)
|
2007-01-09 20:58:05 +01:00
|
|
|
throw new ::java::io::IOException (JvNewStringLatin1 ("can't open core"));
|
2003-08-29 00:17:37 +02:00
|
|
|
return core;
|
2001-09-07 00:32:54 +02:00
|
|
|
}
|