2001-09-07 06:32:54 +08:00
|
|
|
// natCore -- C++ side of Core
|
|
|
|
|
2002-04-25 07:05:17 +08:00
|
|
|
/* Copyright (C) 2001, 2002 Free Software Foundation
|
2001-09-07 06:32:54 +08: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>
|
|
|
|
|
|
|
|
typedef struct core_chain_struct
|
|
|
|
{
|
|
|
|
int name_length;
|
|
|
|
const char *name;
|
|
|
|
int data_length;
|
|
|
|
const void *data;
|
|
|
|
|
|
|
|
struct core_chain_struct *next;
|
|
|
|
} core_chain;
|
|
|
|
|
|
|
|
static core_chain *root;
|
|
|
|
|
|
|
|
void _Jv_RegisterResource (void *vptr)
|
|
|
|
{
|
|
|
|
char *rptr = (char *)vptr;
|
|
|
|
|
|
|
|
// These are permanent data structures for now. This routine is
|
|
|
|
// called from a static constructor, so we shouldn't depend on too
|
|
|
|
// much existing infrastructure.
|
2002-04-25 07:05:17 +08:00
|
|
|
core_chain *cc = (core_chain *) _Jv_Malloc (sizeof (core_chain));
|
2001-09-07 06:32:54 +08:00
|
|
|
|
|
|
|
cc->name_length = ((int *)rptr)[0];
|
|
|
|
cc->data_length = ((int *)rptr)[1];
|
|
|
|
cc->name = rptr + 2*sizeof(int);
|
|
|
|
cc->data = cc->name + cc->name_length;
|
|
|
|
|
|
|
|
// Add this new item to the chain...
|
|
|
|
core_chain *old_root = root;
|
|
|
|
cc->next = old_root;
|
|
|
|
root = cc;
|
|
|
|
}
|
|
|
|
|
|
|
|
gnu::gcj::Core *
|
|
|
|
gnu::gcj::Core::create (jstring name)
|
|
|
|
{
|
2002-04-25 07:05:17 +08:00
|
|
|
char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (name) + 1);
|
2001-09-07 06:32:54 +08:00
|
|
|
jsize total = JvGetStringUTFRegion (name, 0, name->length(), buf);
|
|
|
|
buf[total] = '\0';
|
|
|
|
|
2002-04-25 07:05:17 +08:00
|
|
|
// Usually requests here end up as an absolute URL. We strip the
|
|
|
|
// initial `/'.
|
|
|
|
if (buf[0] == '/')
|
|
|
|
{
|
|
|
|
++buf;
|
|
|
|
--total;
|
|
|
|
}
|
|
|
|
|
2001-09-07 06:32:54 +08:00
|
|
|
core_chain *node = root;
|
|
|
|
|
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
if (total == node->name_length
|
|
|
|
&& strncmp (buf, node->name, total) == 0)
|
|
|
|
{
|
|
|
|
gnu::gcj::Core *core =
|
|
|
|
(gnu::gcj::Core *) _Jv_AllocObject(&gnu::gcj::Core::class$,
|
|
|
|
sizeof (gnu::gcj::Core));
|
|
|
|
core->ptr = (gnu::gcj::RawData *) node->data;
|
|
|
|
core->length = node->data_length;
|
|
|
|
return core;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new java::io::IOException (JvNewStringLatin1 ("can't open core"));
|
|
|
|
}
|