[srvx-commits] CVS: services/src tools.c,1.73.2.24,1.73.2.25 sockcheck.c,1.54.2.22,1.54.2.23 helpfil
Brought to you by:
entrope
From: Entrope <en...@us...> - 2001-08-14 15:31:41
|
Update of /cvsroot/srvx/services/src In directory usw-pr-cvs1:/tmp/cvs-serv20983/src Modified Files: Tag: rel-1_0 tools.c sockcheck.c helpfile.h helpfile.c gline.c Log Message: remove some extra #include's from common.h (and make vsend_message static to helpfile.c) provide mutex for gline database access (and make sockcheck.c use gline_*) only include each gline once in the gline heap Index: tools.c =================================================================== RCS file: /cvsroot/srvx/services/src/tools.c,v retrieving revision 1.73.2.24 retrieving revision 1.73.2.25 diff -C2 -r1.73.2.24 -r1.73.2.25 *** tools.c 2001/08/12 22:18:58 1.73.2.24 --- tools.c 2001/08/14 15:31:38 1.73.2.25 *************** *** 894,922 **** } - int - string_buffer_sprintf(struct string_buffer *buf, const char *format, va_list al) { - int ret; - /* Normally, I'd pass NULL as the first parameter to vsnprintf. - * But guess what? It makes FreeBSD's libc allocate a buffer that it - * never frees! Surprise! - * The kludge-around is to pass a non-NULL pointer instead. - */ - if ((ret = vsnprintf((char*)&ret, 0, format, al)) <= 0) { - /* non-C99 behavior */ - buf->size = strlen(format); - buf->list = malloc(buf->size); - while ((ret = vsnprintf(buf->list, buf->size, format, al)) == -1) { - buf->size <<= 1; - buf->list = realloc(buf->list, buf->size); - } - } else { - /* C99 is nice about how vsnprintf fails */ - buf->size = ret + 1; - buf->list = malloc(buf->size); - ret = vsnprintf(buf->list, buf->size, format, al); - } - return buf->used = ret; - } - void string_buffer_replace(struct string_buffer *buf, unsigned int from, unsigned int len, const char *repl) --- 894,897 ---- Index: sockcheck.c =================================================================== RCS file: /cvsroot/srvx/services/src/sockcheck.c,v retrieving revision 1.54.2.22 retrieving revision 1.54.2.23 diff -C2 -r1.54.2.22 -r1.54.2.23 *** sockcheck.c 2001/08/14 00:18:57 1.54.2.22 --- sockcheck.c 2001/08/14 15:31:38 1.54.2.23 *************** *** 57,60 **** --- 57,61 ---- #include "conf.h" #include "dict.h" + #include "gline.h" #include "log.h" #include "recdb.h" *************** *** 63,67 **** static int disable_sockcheck; ! #if defined(HAVE_POLL) && defined(HAVE_PTHREAD) && !defined(__CYGWIN__) #if !defined(SOCKCHECK_DEBUG) --- 64,68 ---- static int disable_sockcheck; ! #if SOCKCHECK_USABLE #if !defined(SOCKCHECK_DEBUG) *************** *** 221,225 **** strcpy(target+2, sci->hostname); log(PC_LOG, LOG_INFO, "Issuing gline for client at IP %08x hostname %s: %s\n", sci->addr, sci->hostname, sci->reason); ! irc_gline(target, 3600, sci->reason); } --- 222,226 ---- strcpy(target+2, sci->hostname); log(PC_LOG, LOG_INFO, "Issuing gline for client at IP %08x hostname %s: %s\n", sci->addr, sci->hostname, sci->reason); ! gline_add("ProxyCheck", target, 3600, sci->reason, 1); } *************** *** 1259,1263 **** } ! #endif /* defined(HAVE_POLL) && defined(HAVE_PTHREAD) */ --- 1260,1264 ---- } ! #endif Index: helpfile.h =================================================================== RCS file: /cvsroot/srvx/services/src/helpfile.h,v retrieving revision 1.13.2.4 retrieving revision 1.13.2.5 diff -C2 -r1.13.2.4 -r1.13.2.5 *** helpfile.h 2001/07/12 00:46:10 1.13.2.4 --- helpfile.h 2001/08/14 15:31:38 1.13.2.5 *************** *** 43,47 **** #endif - int vsend_message(const char *dest, struct userNode *src, struct handle_info *handle, int use_privmsg, expand_func_t expand, const char *format, va_list al); int send_message(struct userNode *dest, struct userNode *src, const char *message, ...) PRINTF_LIKE(3,4); int send_target_message(int use_privmsg, const char *dest, struct userNode *src, const char *format, ...) PRINTF_LIKE(4,5); --- 43,46 ---- Index: helpfile.c =================================================================== RCS file: /cvsroot/srvx/services/src/helpfile.c,v retrieving revision 1.34.2.11 retrieving revision 1.34.2.12 diff -C2 -r1.34.2.11 -r1.34.2.12 *** helpfile.c 2001/08/07 00:07:55 1.34.2.11 --- helpfile.c 2001/08/14 15:31:38 1.34.2.12 *************** *** 52,56 **** extern struct userNode *global, *chanserv, *opserv, *nickserv; ! int vsend_message(const char *dest, struct userNode *src, struct handle_info *handle, int use_privmsg, expand_func_t expand, const char *format, va_list al) { --- 52,56 ---- extern struct userNode *global, *chanserv, *opserv, *nickserv; ! static int vsend_message(const char *dest, struct userNode *src, struct handle_info *handle, int use_privmsg, expand_func_t expand, const char *format, va_list al) { *************** *** 260,265 **** int res; va_list ap; - - if (!format) return 0; va_start(ap, format); --- 260,263 ---- Index: gline.c =================================================================== RCS file: /cvsroot/srvx/services/src/gline.c,v retrieving revision 1.6.2.3 retrieving revision 1.6.2.4 diff -C2 -r1.6.2.3 -r1.6.2.4 *** gline.c 2001/07/14 19:59:37 1.6.2.3 --- gline.c 2001/08/14 15:31:38 1.6.2.4 *************** *** 23,26 **** --- 23,34 ---- #include <stdlib.h> + #if HAVE_PTHREAD_H && SOCKCHECK_USABLE /* we could have multiple threads setting glines */ + #include <pthread.h> + static pthread_mutex_t gline_mutex = PTHREAD_MUTEX_INITIALIZER; + #else + #define pthread_mutex_lock(M) /*noop*/ + #define pthread_mutex_unlock(M) /*noop*/ + #endif + #include "common.h" #include "heap.h" *************** *** 39,43 **** #define KEY_ISSUER "issuer" ! heap_t gline_heap; /* key: expiry time, data: struct gline_entry* */ static int --- 47,52 ---- #define KEY_ISSUER "issuer" ! static heap_t gline_heap; /* key: expiry time, data: struct gline_entry* */ ! static dict_t gline_dict; /* key: target, data: struct gline_entry* */ static int *************** *** 60,74 **** { struct gline *ge = data; - int res = !strcasecmp(ge->target, extra); (void)key; ! if (res) free_gline(ge); ! return res; } static void gline_expire(void *data) { void *argh, *wraa; (void)data; while (heap_size(gline_heap)) { heap_peek(gline_heap, &argh, &wraa); --- 69,97 ---- { struct gline *ge = data; (void)key; ! return !strcasecmp(ge->target, extra); } + static int + delete_gline_for_p(void *key, void *data, void *extra) + { + struct gline *ge = data; + + (void)key; + if (!strcasecmp(ge->target, extra)) { + free_gline(ge); + return 1; + } else { + return 0; + } + } + static void gline_expire(void *data) { void *argh, *wraa; + (void)data; + pthread_mutex_lock(&gline_mutex); while (heap_size(gline_heap)) { heap_peek(gline_heap, &argh, &wraa); *************** *** 82,85 **** --- 105,109 ---- timeq_add(TIME_T_CAST(argh), gline_expire, NULL); } + pthread_mutex_unlock(&gline_mutex); } *************** *** 87,91 **** gline_remove(const char *target, int announce) { ! if (heap_remove_pred(gline_heap, gline_for_p, (char*)target)) { void *argh; struct gline *new_first; --- 111,116 ---- gline_remove(const char *target, int announce) { ! pthread_mutex_lock(&gline_mutex); ! if (heap_remove_pred(gline_heap, delete_gline_for_p, (char*)target)) { void *argh; struct gline *new_first; *************** *** 98,105 **** } if (announce) irc_ungline(target); } ! void ! gline_add(const char *issuer, const char *target, unsigned long duration, const char *reason, int announce) { struct gline *ent; --- 123,131 ---- } if (announce) irc_ungline(target); + pthread_mutex_unlock(&gline_mutex); } ! static void ! gline_add_int(const char *issuer, const char *target, unsigned long duration, const char *reason, int announce) { struct gline *ent; *************** *** 107,117 **** void *argh; - ent = malloc(sizeof(*ent)); - ent->issuer = strdup(issuer); - ent->target = strdup(target); - ent->expires = now + duration; - ent->reason = strdup(reason); heap_peek(gline_heap, 0, &argh); prev_first = argh; heap_insert(gline_heap, ent, ent); if (!prev_first || (ent->expires < prev_first->expires)) { --- 133,150 ---- void *argh; heap_peek(gline_heap, 0, &argh); prev_first = argh; + ent = dict_find(gline_dict, target, NULL); + if (ent) { + heap_remove_pred(gline_heap, gline_for_p, (char*)target); + ent->expires = now + duration; + } else { + ent = malloc(sizeof(*ent)); + ent->issuer = strdup(issuer); + ent->target = strdup(target); + ent->expires = now + duration; + ent->reason = strdup(reason); + dict_insert(gline_dict, ent->target, ent); + } heap_insert(gline_heap, ent, ent); if (!prev_first || (ent->expires < prev_first->expires)) { *************** *** 122,125 **** --- 155,166 ---- } + void + gline_add(const char *issuer, const char *target, unsigned long duration, const char *reason, int announce) + { + pthread_mutex_lock(&gline_mutex); + gline_add_int(issuer, target, duration, reason, announce); + pthread_mutex_unlock(&gline_mutex); + } + static int gline_refresh_helper(void *key, void *data, void *extra) *************** *** 134,138 **** --- 175,181 ---- gline_refresh_all(void) { + pthread_mutex_lock(&gline_mutex); heap_remove_pred(gline_heap, gline_refresh_helper, 0); + pthread_mutex_unlock(&gline_mutex); } *************** *** 143,146 **** --- 186,190 ---- const char *issuer, *reason, *dstr; time_t expiration; + (void)extra; reason = database_get_data(rd->d.object, KEY_REASON, RECDB_QSTRING); *************** *** 158,162 **** if (!issuer) issuer = "<unknown>"; if (expiration > now) { ! gline_add(issuer, key, expiration - now, reason, 0); } return 0; --- 202,206 ---- if (!issuer) issuer = "<unknown>"; if (expiration > now) { ! gline_add_int(issuer, key, expiration - now, reason, 0); } return 0; *************** *** 168,172 **** dict_t db; if ((db = parse_database(GLINE_DB_NAME))) { ! dict_foreach(db, gline_add_record, gline_heap); } } --- 212,216 ---- dict_t db; if ((db = parse_database(GLINE_DB_NAME))) { ! dict_foreach(db, gline_add_record, 0); } } *************** *** 211,218 **** --- 255,265 ---- gline_init(void) { + pthread_mutex_lock(&gline_mutex); gline_heap = heap_new(gline_comparator); + gline_dict = dict_new(); gline_db_read(); reg_exit_func(gline_db_cleanup); reg_db_write_func(gline_db_write); + pthread_mutex_unlock(&gline_mutex); } *************** *** 299,303 **** --- 346,352 ---- search.data = data; search.hits = 0; + pthread_mutex_lock(&gline_mutex); heap_remove_pred(gline_heap, gline_search_helper, &search); + pthread_mutex_unlock(&gline_mutex); return search.hits; } |