JBoss Native SVN: r993 - in trunk/sight/native: os/linux and 1 other directories.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-09 05:20:58 -0400 (Sun, 09 Sep 2007)
New Revision: 993
Modified:
trunk/sight/native/include/sight_local.h
trunk/sight/native/os/linux/tcpstat.c
trunk/sight/native/share/jnu.c
Log:
Implement TCP lister
Modified: trunk/sight/native/include/sight_local.h
===================================================================
--- trunk/sight/native/include/sight_local.h 2007-09-08 16:45:38 UTC (rev 992)
+++ trunk/sight/native/include/sight_local.h 2007-09-09 09:20:58 UTC (rev 993)
@@ -426,8 +426,7 @@
const char *sight_inet_ntop4(const unsigned char *, char *, size_t);
const char *sight_inet_ntop6(const unsigned char *, char *, size_t);
-const unsigned char *sight_hex2bin(const unsigned char *, unsigned char *,
- size_t);
+int sight_hex2bin(const char *, unsigned char *, size_t);
jobject sight_new_netaddr_class(SIGHT_STDARGS);
jobjectArray sight_new_netaddr_array(SIGHT_STDARGS, jsize);
Modified: trunk/sight/native/os/linux/tcpstat.c
===================================================================
--- trunk/sight/native/os/linux/tcpstat.c 2007-09-08 16:45:38 UTC (rev 992)
+++ trunk/sight/native/os/linux/tcpstat.c 2007-09-09 09:20:58 UTC (rev 993)
@@ -153,8 +153,43 @@
sight_unload_class(_E, &_clazzn);
}
+#define PROC_NET_FS "/proc/net/"
static const char *eiftype = "Unsupported NetworkAddressFamily type";
+/* These enums are used by IPX too. :-( */
+typedef enum {
+ TCP_ESTABLISHED = 1,
+ TCP_SYN_SENT,
+ TCP_SYN_RECV,
+ TCP_FIN_WAIT1,
+ TCP_FIN_WAIT2,
+ TCP_TIME_WAIT,
+ TCP_CLOSE,
+ TCP_CLOSE_WAIT,
+ TCP_LAST_ACK,
+ TCP_LISTEN,
+ TCP_CLOSING /* now a valid state */
+} sight_tcp_state_e;
+
+static int tcp2sstate[] = {
+ 0,
+ SIGHT_TCP_ESTABLISHED,
+ SIGHT_TCP_SYN_SENT,
+ SIGHT_TCP_SYN_RCVD,
+ SIGHT_TCP_FIN_WAIT1,
+ SIGHT_TCP_FIN_WAIT2,
+ SIGHT_TCP_TIME_WAIT,
+ SIGHT_TCP_CLOSED,
+ SIGHT_TCP_CLOSE_WAIT,
+ SIGHT_TCP_LAST_ACK,
+ SIGHT_TCP_LISTENING,
+ SIGHT_TCP_CLOSING,
+ 0,
+ 0,
+ 0,
+ 0
+};
+
/* Initialize volume enumeration */
SIGHT_EXPORT_DECLARE(void, TcpStatistics, info0)(SIGHT_STDARGS,
jobject thiz,
@@ -162,21 +197,51 @@
jlong pool)
{
apr_status_t rc = APR_ENOTIMPL;
- sight_arr_t *tgrp;
+ sight_arr_t *tnet;
int i;
- int RtoAlgorithm, RtoMin, RtoMax, MaxConn, ActiveOpens, PassiveOpens, AttemptFails, EstabResets, CurrEstab, InSegs, OutSegs, RetransSegs, InErrs, OutRsts;
+ int RtoAlgorithm, RtoMin, RtoMax, MaxConn, ActiveOpens, PassiveOpens;
+ int AttemptFails, EstabResets, CurrEstab, InSegs, OutSegs, RetransSegs;
+ int InErrs, OutRsts;
+ int NumCons = 0;
UNREFERENCED_O;
+ if (iftype == 1) {
+ if (!(tnet = sight_arr_rload(PROC_NET_FS "sockstat"))) {
+ throwAprException(_E, apr_get_os_error());
+ }
+ for (i = 0; i < tnet->siz; i++) {
+ if (memcmp(tnet->arr.ca[i], "TCP: inuse ", 11) == 0) {
+ NumCons = atoi(tnet->arr.ca[i] + 11);
+ break;
+ }
+ }
+ }
+ else if (iftype == 2) {
+ if (!(tnet = sight_arr_rload(PROC_NET_FS "sockstat6"))) {
+ throwAprException(_E, apr_get_os_error());
+ }
+ for (i = 0; i < tnet->siz; i++) {
+ if (memcmp(tnet->arr.ca[i], "TCP6: inuse ", 12) == 0) {
+ NumCons = atoi(tnet->arr.ca[i] + 12);
+ break;
+ }
+ }
+ }
+ else {
+ throwOSException(_E, eiftype);
+ return;
+ }
+ sight_arr_free(tnet);
- if (!(tgrp = sight_arr_rload("/proc/net/snmp"))) {
+ if (!(tnet = sight_arr_rload(PROC_NET_FS "snmp"))) {
throwAprException(_E, apr_get_os_error());
}
/* Get the information corresponding to the second entry Tcp: */
- for (i = 0; i < tgrp->siz; i++) {
- if (memcmp(tgrp->arr.ca[i], "Tcp:", 4) == 0) {
- if (memcmp(tgrp->arr.ca[i], "Tcp: RtoAlgorithm", 17) != 0) {
- sscanf(tgrp->arr.ca[i], "Tcp: %d %d %d %d %d %d %d %d %d %d %d %d %d %d",
+ for (i = 0; i < tnet->siz; i++) {
+ if (memcmp(tnet->arr.ca[i], "Tcp:", 4) == 0) {
+ if (memcmp(tnet->arr.ca[i], "Tcp: RtoAlgorithm", 17) != 0) {
+ sscanf(tnet->arr.ca[i], "Tcp: %d %d %d %d %d %d %d %d %d %d %d %d %d %d",
&RtoAlgorithm, &RtoMin, &RtoMax, &MaxConn, &ActiveOpens,
&PassiveOpens, &AttemptFails, &EstabResets, &CurrEstab,
&InSegs, &OutSegs, &RetransSegs, &InErrs, &OutRsts);
@@ -184,7 +249,7 @@
}
}
}
- sight_arr_free(tgrp);
+ sight_arr_free(tnet);
/* Fill the info (RtoAlgorithm not used) */
SET_IFIELD_I(0000, thiz, RtoMin);
@@ -200,14 +265,51 @@
SET_IFIELD_I(0010, thiz, RetransSegs);
SET_IFIELD_I(0011, thiz, InErrs);
SET_IFIELD_I(0012, thiz, OutRsts);
- /* XXX: SET_IFIELD_I(0013, thiz, s.dwNumConns); */
+ SET_IFIELD_I(0013, thiz, NumCons);
}
+typedef struct tcpconn_enum_t {
+ int type;
+ int idx;
+ sight_arr_t *tnet;
+} tcpconn_enum_t;
+
+
/* Initialize TCP conn enumeration */
SIGHT_EXPORT_DECLARE(jlong, TcpStatistics, enum0)(SIGHT_STDARGS,
jint iftype,
jlong pool)
{
+ tcpconn_enum_t *e;
+
+ UNREFERENCED_O;
+ if (iftype < 1 || iftype > 2) {
+ throwOSException(_E, eiftype);
+ return 0;
+ }
+ if (!(e = (tcpconn_enum_t *)calloc(1, sizeof(tcpconn_enum_t)))) {
+ throwAprMemoryException(_E, THROW_FMARK,
+ apr_get_os_error());
+ return 0;
+ }
+ e->type = iftype;
+ if (iftype == 1) {
+ if (!(e->tnet = sight_arr_rload(PROC_NET_FS "tcp"))) {
+ throwAprException(_E, apr_get_os_error());
+ goto cleanup;
+ }
+ }
+ else {
+ if (!(e->tnet = sight_arr_rload(PROC_NET_FS "tcp6"))) {
+ throwAprException(_E, apr_get_os_error());
+ goto cleanup;
+ }
+ }
+
+ return P2J(e);
+cleanup:
+ sight_arr_free(e->tnet);
+ free(e);
return 0;
}
@@ -215,7 +317,15 @@
SIGHT_EXPORT_DECLARE(jint, TcpStatistics, enum1)(SIGHT_STDARGS,
jlong handle)
{
- return 0;
+ tcpconn_enum_t *e = J2P(handle, tcpconn_enum_t *);
+
+ UNREFERENCED_STDARGS;
+ if (e && e->tnet) {
+ e->idx = 1;
+ return e->tnet->siz - 1; /* Skip description field */
+ }
+ else
+ return 0;
}
SIGHT_EXPORT_DECLARE(void, TcpStatistics, enum2)(SIGHT_STDARGS,
@@ -223,12 +333,103 @@
jint index,
jlong handle)
{
+ jint pid = -1;
+ jint state = 0;
+ jint lp = 0, rp = 0;
+ jobject la, ra;
+ char las[128] = "";
+ char ras[128] = "";
+ char ssi[32] = "";
+ struct in_addr ial, iar;
+ jlong cts = 0;
+ unsigned long rxq, txq, timelen, retr, inode;
+ int num, d, uid, timer_run, timeout;
+ char more[512];
+
+ tcpconn_enum_t *e = J2P(handle, tcpconn_enum_t *);
+
+ if (!e || !e->tnet)
+ return;
+ if (e->idx > e->tnet->siz) {
+ /* TODO: Throw overflow */
+ return;
+ }
+ num = sscanf(e->tnet->arr.ca[e->idx],
+ "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s",
+ &d, las, &lp, ras, &rp, &state,
+ &txq, &rxq, &timer_run, &timelen, &retr,
+ &uid, &timeout, &inode, more);
+
+ if (e->type == 1) {
+ /* IPV4 entries */
+ int al;
+ struct in_addr in4;
+
+ al = sscanf(las, "%X", &in4.s_addr);
+ if (al == 1)
+ inet_ntop(AF_INET, &in4, las, 64);
+ else
+ las[0] = '\0';
+
+ al = sscanf(ras, "%X", &in4.s_addr);
+ if (al == 1)
+ inet_ntop(AF_INET, &in4, ras, 64);
+ else
+ ras[0] = '\0';
+ }
+ else {
+ /* IPV6 entries */
+ int al;
+ struct in6_addr in6;
+
+ al = sscanf(las, "%08X%08X%08X%08X",
+ &in6.s6_addr32[0], &in6.s6_addr32[1],
+ &in6.s6_addr32[2], &in6.s6_addr32[3]);
+
+ if (al == 4)
+ sight_inet_ntop6(in6.s6_addr, las, 64);
+ else
+ las[0] = '\0';
+ al = sscanf(ras, "%08X%08X%08X%08X",
+ &in6.s6_addr32[0], &in6.s6_addr32[1],
+ &in6.s6_addr32[2], &in6.s6_addr32[3]);
+
+ if (al == 4)
+ sight_inet_ntop6(in6.s6_addr, ras, 64);
+ else
+ ras[0] = '\0';
+ }
+ /* TODO: See what's the actual value of timelen */
+ cts = timelen;
+ sight_tcpconn_set_pid(_E, conn, pid);
+ sight_tcpconn_set_cts(_E, conn, cts);
+ sight_tcpconn_set_state(_E, conn, tcp2sstate[state & 0xFF]);
+
+ la = sight_new_netaddr_class(_E, _O);
+ sight_netaddr_set_addr(_E, la, las);
+ sight_netaddr_set_port(_E, la, lp);
+ sight_tcpconn_set_local(_E, conn, la);
+ (*_E)->DeleteLocalRef(_E, la);
+
+ ra = sight_new_netaddr_class(_E, _O);
+ sight_netaddr_set_addr(_E, ra, ras);
+ sight_netaddr_set_port(_E, ra, rp);
+ sight_tcpconn_set_remote(_E, conn, ra);
+ (*_E)->DeleteLocalRef(_E, ra);
+ /* Increment the index counter */
+ e->idx++;
}
/* Close TCP conn enumeration */
SIGHT_EXPORT_DECLARE(void, TcpStatistics, enum3)(SIGHT_STDARGS,
jlong handle)
{
+ tcpconn_enum_t *e = J2P(handle, tcpconn_enum_t *);
+ UNREFERENCED_STDARGS;
+ if (e) {
+ sight_arr_free(e->tnet);
+ free(e);
+ }
}
Modified: trunk/sight/native/share/jnu.c
===================================================================
--- trunk/sight/native/share/jnu.c 2007-09-08 16:45:38 UTC (rev 992)
+++ trunk/sight/native/share/jnu.c 2007-09-09 09:20:58 UTC (rev 993)
@@ -892,45 +892,42 @@
}
}
-static unsigned char uch4hex(unsigned char i)
+static int uch4hex(int i)
{
if (apr_isdigit(i))
return i - '0';
else if (apr_isupper(i))
- return i - 'A';
+ return i - 'A' + 10;
else
- return i - 'a';
+ return i - 'a' + 10;
}
/*
* Convert hex to array
*/
-const unsigned char *sight_hex2bin(const unsigned char *src, unsigned char *dst,
- size_t size)
+int sight_hex2bin(const char *src, unsigned char *dst,
+ size_t size)
{
- char tmp[64], *tp;
- int i;
- char *next = src;
+ unsigned char tmp[64], *tp;
+ int i, len = 0;
+ const char *next = src;
tp = tmp;
- for (i = 0; i < 62; i++) {
- unsigned char ch;
- if (!*next || !apr_isxdigit(*next))
- break;
- ch = (uch4hex(*next++) << 4);
- if (!*next || !apr_isxdigit(*next))
- break;
- ch |= uch4hex(*next++);
- *tp++ = ch;
+ for (i = 0; i < 62, *next; i++) {
+ int ch = uch4hex(*next++);
+ ch = (ch << 4) | uch4hex(*next++);
+ *tp++ = (unsigned char)ch;
}
- *tp = '\0';
/*
* Check for overflow, copy, and we're done.
*/
if ((size_t)(tp - tmp) > size) {
errno = ENOSPC;
- return NULL;
+ return -1;
}
- strcpy(dst, tmp);
- return dst;
+ else
+ len = (int)(tp - tmp);
+ if (len)
+ memcpy(dst, tmp, size);
+ return len;
}
16 years, 8 months
JBoss Native SVN: r992 - trunk/sight/native/include.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-08 12:45:38 -0400 (Sat, 08 Sep 2007)
New Revision: 992
Modified:
trunk/sight/native/include/sight_local.h
Log:
Bring back the proto.
Modified: trunk/sight/native/include/sight_local.h
===================================================================
--- trunk/sight/native/include/sight_local.h 2007-09-08 16:43:50 UTC (rev 991)
+++ trunk/sight/native/include/sight_local.h 2007-09-08 16:45:38 UTC (rev 992)
@@ -426,8 +426,9 @@
const char *sight_inet_ntop4(const unsigned char *, char *, size_t);
const char *sight_inet_ntop6(const unsigned char *, char *, size_t);
+const unsigned char *sight_hex2bin(const unsigned char *, unsigned char *,
+ size_t);
-
jobject sight_new_netaddr_class(SIGHT_STDARGS);
jobjectArray sight_new_netaddr_array(SIGHT_STDARGS, jsize);
void sight_netaddr_set_host(SIGHT_STDARGS, const char *);
16 years, 8 months
JBoss Native SVN: r991 - trunk/sight/native.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-08 12:43:50 -0400 (Sat, 08 Sep 2007)
New Revision: 991
Modified:
trunk/sight/native/NMAKEmakefile
Log:
Add cache.c for list based hash
Modified: trunk/sight/native/NMAKEmakefile
===================================================================
--- trunk/sight/native/NMAKEmakefile 2007-09-08 16:43:32 UTC (rev 990)
+++ trunk/sight/native/NMAKEmakefile 2007-09-08 16:43:50 UTC (rev 991)
@@ -1,4 +1,4 @@
-# Copyright 2001-2006 The Apache Software Foundation or its licensors, as
+# Copyright 2001-2007 The Apache Software Foundation or its licensors, as
# applicable.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -59,6 +59,7 @@
PDBFLAGS = -Fo$(WORKDIR)\ -Fd$(WORKDIR)\$(PROJECT)-src
OBJECTS = \
$(WORKDIR)\buildmark.obj \
+ $(WORKDIR)\cache.obj \
$(WORKDIR)\clazz.obj \
$(WORKDIR)\console.obj \
$(WORKDIR)\dir.obj \
16 years, 8 months
JBoss Native SVN: r990 - trunk/sight/native/include.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-08 12:43:32 -0400 (Sat, 08 Sep 2007)
New Revision: 990
Modified:
trunk/sight/native/include/sight_local.h
trunk/sight/native/include/sight_types.h
Log:
Add prototypes for list based hash
Modified: trunk/sight/native/include/sight_local.h
===================================================================
--- trunk/sight/native/include/sight_local.h 2007-09-08 16:43:04 UTC (rev 989)
+++ trunk/sight/native/include/sight_local.h 2007-09-08 16:43:32 UTC (rev 990)
@@ -398,6 +398,12 @@
#endif
+/* Prototypes from cache.c */
+cache_table_t *cache_new(size_t);
+cache_entry_t *cache_add(cache_table_t *, const char *);
+cache_entry_t *cache_find(cache_table_t *, const char *);
+void cache_free(cache_table_t *, void (*destroy)(const char *, void *));
+
/* Prototypes from finfo.c */
jobject sight_new_finfo_class(SIGHT_STDARGS);
void sight_finfo_fill(SIGHT_STDARGS, apr_finfo_t *);
Modified: trunk/sight/native/include/sight_types.h
===================================================================
--- trunk/sight/native/include/sight_types.h 2007-09-08 16:43:04 UTC (rev 989)
+++ trunk/sight/native/include/sight_types.h 2007-09-08 16:43:32 UTC (rev 990)
@@ -122,6 +122,30 @@
void (*clean)(int, sight_object_t *);
};
+#define CACHE_HASH_MASK 255
+#define CACHE_HASH_SIZE 256
+
+typedef struct cache_entry_t cache_entry_t;
+typedef struct cache_table_t cache_table_t;
+
+struct cache_entry_t {
+ cache_entry_t *next; /* Next cache entry in bucket */
+ char *key; /* cache id */
+ void *data;
+};
+
+struct cache_table_t {
+ /* Pointer to the linked list of cache entries */
+ cache_entry_t **list;
+ /* Table of hash buckets */
+ cache_entry_t *hash[CACHE_HASH_SIZE];
+ /* Number of cache buckets defined */
+ size_t siz;
+ /* Maximum number of cache buckets */
+ size_t len;
+};
+
+
#define SIGHT_FS_UNKNOWN 0
#define SIGHT_FS_MSDOS 1
#define SIGHT_FS_VFAT 2
@@ -178,6 +202,19 @@
#define SIGHT_DRIVE_RAMDISK 6
#define SIGHT_DRIVE_SWAP 7
+/* Socket TCP states */
+#define SIGHT_TCP_CLOSED 1
+#define SIGHT_TCP_LISTENING 2
+#define SIGHT_TCP_SYN_SENT 3
+#define SIGHT_TCP_SYN_RCVD 4
+#define SIGHT_TCP_ESTABLISHED 5
+#define SIGHT_TCP_FIN_WAIT1 6
+#define SIGHT_TCP_FIN_WAIT2 7
+#define SIGHT_TCP_CLOSE_WAIT 8
+#define SIGHT_TCP_CLOSING 9
+#define SIGHT_TCP_LAST_ACK 10
+#define SIGHT_TCP_TIME_WAIT 11
+#define SIGHT_TCP_DELETE_TCB 12
#ifdef __cplusplus
16 years, 8 months
JBoss Native SVN: r989 - trunk/sight/native/share.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-08 12:43:04 -0400 (Sat, 08 Sep 2007)
New Revision: 989
Added:
trunk/sight/native/share/cache.c
Log:
Add cache.c for list based hash
Added: trunk/sight/native/share/cache.c
===================================================================
--- trunk/sight/native/share/cache.c (rev 0)
+++ trunk/sight/native/share/cache.c 2007-09-08 16:43:04 UTC (rev 989)
@@ -0,0 +1,147 @@
+/*
+ * SIGHT - System information gathering hybrid tool
+ *
+ * Copyright(c) 2007 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Mladen Turk
+ *
+ */
+
+#include "sight.h"
+#include "sight_local.h"
+#include "sight_types.h"
+
+static unsigned int times33hash(const char *key)
+{
+ const char *p;
+ unsigned int hash = 0;
+ for (p = key; *p; p++) {
+ hash = hash * 33 + *p;
+ }
+ return hash & CACHE_HASH_MASK;
+}
+
+cache_table_t *cache_new(size_t init)
+{
+ cache_table_t *t = (cache_table_t *)malloc(sizeof(cache_table_t));
+ if (!t)
+ return NULL;
+ t->siz = 0;
+ t->len = init;
+ if (!(t->list = (cache_entry_t **)malloc(init * sizeof(cache_entry_t *)))) {
+ int saved = errno;
+ free(t);
+ t = NULL;
+ errno = saved;
+ }
+ return t;
+}
+
+cache_entry_t *cache_add(cache_table_t *t, const char *key)
+{
+ cache_entry_t *e;
+ unsigned int hash;
+
+ if (!key || !*key) {
+ errno = EINVAL;
+ return NULL; /* Skip empty and null strings */
+ }
+ hash = times33hash(key);
+
+ if (t->hash[hash]) {
+ /*
+ * This spot in the table is already in use. See if the current string
+ * has already been inserted, and if so, increment its count.
+ */
+ for (e = t->hash[hash]; e; e = e->next) {
+ if (!strcmp(key, e->key))
+ return e;
+ }
+ }
+ if (!(e = (cache_entry_t *)malloc(sizeof(cache_entry_t ))))
+ return NULL;
+ e->data = NULL;
+ /* Insert new bucket into the list */
+ if (t->siz < t->len) {
+ t->list[t->siz++] = e;
+ }
+ else {
+ cache_entry_t **nl;
+ size_t len = t->len << 2;
+ if (!(nl = (cache_entry_t **)malloc(len * sizeof(cache_entry_t *))))
+ return NULL;
+ memcpy(nl, t->list, t->siz * sizeof(cache_entry_t *));
+ free(t->list);
+ t->len = len;
+ t->list = nl;
+ t->list[t->siz++] = e;
+ }
+ if (!(e->key = strdup(key)))
+ return NULL;
+ e->next = t->hash[hash];
+ t->hash[hash] = e;
+ return e;
+}
+
+cache_entry_t *cache_find(cache_table_t *t, const char *key)
+{
+ cache_entry_t *e;
+ unsigned int hash;
+
+ if (!key || !*key) {
+ return NULL; /* Skip empty and null strings */
+ }
+ hash = times33hash(key);
+
+ if (t->hash[hash]) {
+ /*
+ * This spot in the table is already in use. See if the current string
+ * has already been inserted, and if so, return existing entry.
+ */
+ for (e = t->hash[hash]; e; e = e->next) {
+ if (!strcmp(key, e->key))
+ return e;
+ }
+ }
+ return NULL;
+}
+
+void cache_free(cache_table_t *t, void (*destroy)(const char *, void *))
+{
+ size_t i;
+
+ if (!t)
+ return;
+ for (i = 0; i < t->siz; i++) {
+ if (t->list[i]) {
+ if (t->list[i]->data) {
+ if (destroy)
+ (*destroy)(t->list[i]->key, t->list[i]->data);
+ else
+ free(t->list[i]->data);
+ }
+ if (t->list[i]->key)
+ free(t->list[i]->key);
+ }
+ }
+ free(t->list);
+ free(t);
+}
Property changes on: trunk/sight/native/share/cache.c
___________________________________________________________________
Name: svn:eol-style
+ native
16 years, 8 months
JBoss Native SVN: r988 - trunk/sight/native/share.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-08 12:42:14 -0400 (Sat, 08 Sep 2007)
New Revision: 988
Modified:
trunk/sight/native/share/jnu.c
Log:
Return errno on malloc fails
Modified: trunk/sight/native/share/jnu.c
===================================================================
--- trunk/sight/native/share/jnu.c 2007-09-07 08:04:14 UTC (rev 987)
+++ trunk/sight/native/share/jnu.c 2007-09-08 16:42:14 UTC (rev 988)
@@ -785,7 +785,11 @@
free(a->arr.ca);
a->len = len;
a->arr.ca = na;
- a->arr.ca[a->siz++] = strdup(str);
+ a->arr.ca[a->siz] = strdup(str);
+ if (!a->arr.ca[a->siz])
+ return errno;
+ else
+ a->siz++;
}
return 0;
}
@@ -834,12 +838,16 @@
FILE *file;
/* Filename and comment are mandatory */
- if (!fname || !cmnt)
+ if (!fname || !cmnt) {
+ errno = EINVAL;
return NULL;
+ }
if (!(file = fopen(fname, "r")))
return NULL;
if (!(array = sight_arr_new(16))) {
+ int saved_errno = errno;
fclose(file);
+ errno = saved_errno;
return NULL;
}
while (fgets(&buf[0], 8192, file)) {
16 years, 8 months
JBoss Native SVN: r987 - trunk/sight/native/share.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-07 04:04:14 -0400 (Fri, 07 Sep 2007)
New Revision: 987
Modified:
trunk/sight/native/share/jnu.c
Log:
Fix typo
Modified: trunk/sight/native/share/jnu.c
===================================================================
--- trunk/sight/native/share/jnu.c 2007-09-07 08:03:05 UTC (rev 986)
+++ trunk/sight/native/share/jnu.c 2007-09-07 08:04:14 UTC (rev 987)
@@ -907,10 +907,10 @@
tp = tmp;
for (i = 0; i < 62; i++) {
unsigned char ch;
- if (!*next || !apr_isxdigit(*next)
+ if (!*next || !apr_isxdigit(*next))
break;
ch = (uch4hex(*next++) << 4);
- if (!*next || !apr_isxdigit(*next)
+ if (!*next || !apr_isxdigit(*next))
break;
ch |= uch4hex(*next++);
*tp++ = ch;
16 years, 8 months
JBoss Native SVN: r986 - trunk/sight/native/share.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-07 04:03:05 -0400 (Fri, 07 Sep 2007)
New Revision: 986
Modified:
trunk/sight/native/share/jnu.c
Log:
Added hex to binary function for translating hex addreses
Modified: trunk/sight/native/share/jnu.c
===================================================================
--- trunk/sight/native/share/jnu.c 2007-09-07 07:01:55 UTC (rev 985)
+++ trunk/sight/native/share/jnu.c 2007-09-07 08:03:05 UTC (rev 986)
@@ -224,7 +224,7 @@
if ((b = malloc(rd))) {
rd = fread(b, 1, rd - 2, f);
- if (rd > 0) {
+ if (rd > 0) {
/* Remove all trailing zero and space characters */
for (i = rd - 1; i >= 0 && (apr_iscntrl(b[i]) ||
apr_isspace(b[i])); i--)
@@ -585,7 +585,7 @@
* to use pointer overlays. All the world's not a VAX.
*/
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
- struct { int base, len; }best = {-1, 0}, cur = {-1, 0};
+ struct { int base, len; } best = {-1, 0}, cur = {-1, 0};
unsigned int words[IN6ADDRSZ / INT16SZ];
int i;
const unsigned char *next_src, *src_end;
@@ -883,3 +883,46 @@
return *str ? str : NULL;
}
}
+
+static unsigned char uch4hex(unsigned char i)
+{
+ if (apr_isdigit(i))
+ return i - '0';
+ else if (apr_isupper(i))
+ return i - 'A';
+ else
+ return i - 'a';
+}
+
+/*
+ * Convert hex to array
+ */
+const unsigned char *sight_hex2bin(const unsigned char *src, unsigned char *dst,
+ size_t size)
+{
+ char tmp[64], *tp;
+ int i;
+ char *next = src;
+
+ tp = tmp;
+ for (i = 0; i < 62; i++) {
+ unsigned char ch;
+ if (!*next || !apr_isxdigit(*next)
+ break;
+ ch = (uch4hex(*next++) << 4);
+ if (!*next || !apr_isxdigit(*next)
+ break;
+ ch |= uch4hex(*next++);
+ *tp++ = ch;
+ }
+ *tp = '\0';
+ /*
+ * Check for overflow, copy, and we're done.
+ */
+ if ((size_t)(tp - tmp) > size) {
+ errno = ENOSPC;
+ return NULL;
+ }
+ strcpy(dst, tmp);
+ return dst;
+}
16 years, 8 months
JBoss Native SVN: r985 - trunk/sight/native/share.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-07 03:01:55 -0400 (Fri, 07 Sep 2007)
New Revision: 985
Modified:
trunk/sight/native/share/jnu.c
Log:
Init struct at declaration
Modified: trunk/sight/native/share/jnu.c
===================================================================
--- trunk/sight/native/share/jnu.c 2007-09-06 18:04:47 UTC (rev 984)
+++ trunk/sight/native/share/jnu.c 2007-09-07 07:01:55 UTC (rev 985)
@@ -585,7 +585,7 @@
* to use pointer overlays. All the world's not a VAX.
*/
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
- struct { int base, len; } best, cur;
+ struct { int base, len; }best = {-1, 0}, cur = {-1, 0};
unsigned int words[IN6ADDRSZ / INT16SZ];
int i;
const unsigned char *next_src, *src_end;
@@ -599,9 +599,6 @@
next_src = src;
src_end = src + IN6ADDRSZ;
next_dest = words;
- best.base = -1;
- cur.base = -1;
- cur.len = best.len = 0; /* silence gcc4 warning */
i = 0;
do {
unsigned int next_word = (unsigned int)*next_src++;
16 years, 8 months
JBoss Native SVN: r984 - trunk/sight/native/os/windows.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-06 14:04:47 -0400 (Thu, 06 Sep 2007)
New Revision: 984
Modified:
trunk/sight/native/os/windows/process.c
Log:
Bail out if alloc fails
Modified: trunk/sight/native/os/windows/process.c
===================================================================
--- trunk/sight/native/os/windows/process.c 2007-09-06 15:51:07 UTC (rev 983)
+++ trunk/sight/native/os/windows/process.c 2007-09-06 18:04:47 UTC (rev 984)
@@ -246,8 +246,10 @@
SIZE_T nrd, rdd;
for (i = 0; i < 2; i++) {
- pages[i].len = 0;
- pages[i].str.w = NULL;
+ pages[i].len = 0;
+ pages[i].str.w = NULL;
+ }
+ for (i = 0; i < 2; i++) {
if (!VirtualQueryEx(hProcess, PEB_ADDRESS(i), &mbi, sizeof(mbi)))
continue;
nrd = mbi.RegionSize;
@@ -255,9 +257,10 @@
if (nrd > 8192)
continue;
pages[i].str.w = apr_palloc(pool, nrd);
- if (!pages[i].str.w)
- continue;
-
+ if (!pages[i].str.w) {
+ /* If we cannot alloc memory what's the point? */
+ return;
+ }
if (!ReadProcessMemory(hProcess,
PEB_ADDRESS(i),
pages[i].str.w,
16 years, 8 months