/*
- * $Id: SimpleServer.xs,v 1.55 2006-12-22 12:27:19 sondberg Exp $
+ * $Id: SimpleServer.xs,v 1.60 2007-04-17 20:26:58 adam Exp $
* ----------------------------------------------------------------------
*
* Copyright (c) 2000-2004, Index Data.
#include <yaz/wrbuf.h>
#include <yaz/querytowrbuf.h>
#include <stdio.h>
+#include <yaz/mutex.h>
#ifdef WIN32
#else
#include <unistd.h>
#define sv_undef PL_sv_undef
#endif
-NMEM_MUTEX simpleserver_mutex;
+YAZ_MUTEX simpleserver_mutex;
typedef struct {
SV *handle;
PerlInterpreter *root_perl_context;
int MAX_OID = 15;
-#define GRS_BUF_SIZE 512
+#define GRS_BUF_SIZE 8192
CV * simpleserver_sv2cv(SV *handler) {
STRLEN len;
int simpleserver_clone(void) {
#ifdef USE_ITHREADS
- nmem_mutex_enter(simpleserver_mutex);
+ yaz_mutex_enter(simpleserver_mutex);
if (1)
{
PerlInterpreter *current = PERL_GET_CONTEXT;
PERL_SET_CONTEXT( perl_interp );
}
}
- nmem_mutex_leave(simpleserver_mutex);
+ yaz_mutex_leave(simpleserver_mutex);
#endif
return 0;
}
void simpleserver_free(void) {
- nmem_mutex_enter(simpleserver_mutex);
+ yaz_mutex_enter(simpleserver_mutex);
if (1)
{
PerlInterpreter *current_interp = PERL_GET_CONTEXT;
perl_free(current_interp);
}
}
- nmem_mutex_leave(simpleserver_mutex);
+ yaz_mutex_leave(simpleserver_mutex);
}
-
static void oid2str(Odr_oid *o, WRBUF buf)
{
for (; *o >= 0; o++) {
}
}
+WRBUF oid2dotted(int *oid)
+{
+ WRBUF buf = wrbuf_alloc();
+ oid2str(oid, buf);
+ return buf;
+}
+
WRBUF zquery2pquery(Z_Query *q)
{
oid2str(sattr->id, attrset_wr);
hv_store(sort_spec, "ATTRSET", 7,
newSVpv(attrset_wr->buf, attrset_wr->pos), 0);
- wrbuf_free(attrset_wr, 1);
+ wrbuf_destroy(attrset_wr);
hv_store(sort_spec, "SORT_ATTR", 9, newRV( sv_2mortal( (SV*) list ) ), 0);
oid2str(zspec->schema.oid, elementSpec);
hv_store(sort_spec, "ELEMENTSPEC_VALUE", 17,
newSVpv(elementSpec->buf, elementSpec->pos), 0);
- wrbuf_free(elementSpec, 1);
+ wrbuf_destroy(elementSpec);
}
else if (zspec->which == Z_Schema_uri)
{
sv_free( (SV*) aref);
sv_free( (SV*) href);
if (query)
- wrbuf_free(query, 1);
+ wrbuf_destroy(query);
PUTBACK;
FREETMPS;
LEAVE;
}
-/* ### this is worryingly similar to oid2str() */
-WRBUF oid2dotted(int *oid)
-{
-
- WRBUF buf = wrbuf_alloc();
- int dot = 0;
-
- for (; *oid != -1 ; oid++)
- {
- char ibuf[16];
- if (dot)
- {
- wrbuf_putc(buf, '.');
- }
- else
- {
- dot = 1;
- }
- sprintf(ibuf, "%d", *oid);
- wrbuf_puts(buf, ibuf);
- }
- return buf;
-}
-
-
-int dotted2oid(char *dotted, int *buffer)
-{
- int *oid;
- char ibuf[16];
- char *ptr;
- int n = 0;
-
- ptr = ibuf;
- oid = buffer;
- while (*dotted)
- {
- if (*dotted == '.')
- {
- n++;
- if (n == MAX_OID) /* Terminate if more than MAX_OID entries */
- {
- *oid = -1;
- return -1;
- }
- *ptr = 0;
- sscanf(ibuf, "%d", oid++);
- ptr = ibuf;
- dotted++;
-
- }
- else
- {
- *ptr++ = *dotted++;
- }
- }
- if (n < MAX_OID)
- {
- *ptr = 0;
- sscanf(ibuf, "%d", oid++);
- }
- *oid = -1;
- return 0;
-}
-
-
int bend_fetch(void *handle, bend_fetch_rr *rr)
{
HV *href;
char *ODR_basename;
char *ODR_errstr;
int *ODR_oid_buf;
- oident *oid;
WRBUF oid_dotted;
Zfront_handle *zhandle = (Zfront_handle *)handle;
CV* handler_cv = 0;
if (rr->schema)
hv_store(href, "SCHEMA", 6, newSVpv(rr->schema, 0), 0);
temp = hv_store(href, "OFFSET", 6, newSViv(rr->number), 0);
- if (rr->request_format_raw != 0) {
- oid_dotted = oid2dotted(rr->request_format_raw);
+ if (rr->request_format != 0) {
+ oid_dotted = oid2dotted(rr->request_format);
} else {
/* Probably an SRU request: assume XML is required */
oid_dotted = wrbuf_alloc();
rr->basename = ODR_basename;
ptr = SvPV(rep_form, length);
+
ODR_oid_buf = (int *)odr_malloc(rr->stream, (MAX_OID + 1) * sizeof(int));
- if (dotted2oid(ptr, ODR_oid_buf) == -1) /* Maximum number of OID elements exceeded */
+ if (oid_dotstring_to_oid(ptr, ODR_oid_buf))
{
printf("Net::Z3950::SimpleServer: WARNING: OID structure too long, max length is %d\n", MAX_OID);
}
- rr->output_format_raw = ODR_oid_buf;
+ rr->output_format = ODR_oid_buf;
ptr = SvPV(record, length);
- oid = oid_getentbyoid(ODR_oid_buf);
- if (oid->value == VAL_GRS1) /* Treat GRS-1 records separately */
+ /* Treat GRS-1 records separately */
+ if (!oid_oidcmp(ODR_oid_buf, yaz_oid_recsyn_grs_1))
{
rr->record = (char *) read_grs1(ptr, rr->stream);
rr->len = -1;
}
rr->surrogate_flag = SvIV(sur_flag);
- wrbuf_free(oid_dotted, 1);
+ wrbuf_destroy(oid_dotted);
sv_free((SV*) href);
sv_free(basename);
sv_free(record);
}
*argv_buf = NULL;
root_perl_context = PERL_GET_CONTEXT;
- nmem_mutex_create(&simpleserver_mutex);
+ yaz_mutex_create(&simpleserver_mutex);
#if 0
/* only for debugging perl_clone .. */
tst_clones();