Thread: [Mod-auth-commit] mod_authn_cache/src mod_authn_cache.c,1.6,1.7
Brought to you by:
firechipmunk,
honx
From: <fir...@us...> - 2004-01-06 01:31:06
|
Update of /cvsroot/mod-auth/mod_authn_cache/src In directory sc8-pr-cvs1:/tmp/cvs-serv5290/src Modified Files: mod_authn_cache.c Log Message: using buckets now Index: mod_authn_cache.c =================================================================== RCS file: /cvsroot/mod-auth/mod_authn_cache/src/mod_authn_cache.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** mod_authn_cache.c 2 Jan 2004 23:51:02 -0000 1.6 --- mod_authn_cache.c 6 Jan 2004 01:31:01 -0000 1.7 *************** *** 87,92 **** #define DFLT_HOSTNAME "localhost" #define DFLT_PORT (8008) ! #define DFLT_CONN_MIN (1) ! #define DFLT_CONN_SOFT (5) #define DFLT_CONN_MAX (25) #define DFLT_CONN_TTL (600) --- 87,92 ---- #define DFLT_HOSTNAME "localhost" #define DFLT_PORT (8008) ! #define DFLT_CONN_MIN (10) ! #define DFLT_CONN_SOFT (15) #define DFLT_CONN_MAX (25) #define DFLT_CONN_TTL (600) *************** *** 103,108 **** apr_sockaddr_t *sockaddr; apr_socket_t *sock; ! char* line_buff; ! apr_size_t line_buff_size; } mcd_res_t; --- 103,110 ---- apr_sockaddr_t *sockaddr; apr_socket_t *sock; ! apr_bucket_alloc_t *bb_l; ! apr_bucket_brigade *bb; ! apr_pool_t* pool; ! } mcd_res_t; *************** *** 112,121 **** apr_status_t rv = APR_SUCCESS; mcd_res_t *mcdres; ! mcdres = apr_palloc(pool, sizeof(*mcdres)); ! ! mcdres->line_buff = NULL; ! mcdres->line_buff_size = 0; ! rv = apr_sockaddr_info_get(&mcdres->sockaddr, DFLT_HOSTNAME, APR_UNSPEC, DFLT_PORT, 0, pool); if (rv != APR_SUCCESS) { --- 114,121 ---- apr_status_t rv = APR_SUCCESS; mcd_res_t *mcdres; ! apr_bucket *e; ! mcdres = apr_palloc(pool, sizeof(*mcdres)); ! rv = apr_sockaddr_info_get(&mcdres->sockaddr, DFLT_HOSTNAME, APR_UNSPEC, DFLT_PORT, 0, pool); if (rv != APR_SUCCESS) { *************** *** 141,144 **** --- 141,149 ---- } + mcdres->bb_l = apr_bucket_alloc_create(pool); + mcdres->bb = apr_brigade_create(pool, mcdres->bb_l); + e = apr_bucket_socket_create(mcdres->sock, mcdres->bb_l); + APR_BRIGADE_INSERT_TAIL(mcdres->bb, e); + mcdres->pool = pool; *resource = mcdres; return rv; *************** *** 150,153 **** --- 155,160 ---- mcd_res_t *mcd = resource; + apr_brigade_destroy(mcd->bb); + apr_bucket_alloc_destroy(mcd->bb_l); rv = apr_socket_close(mcd->sock); *************** *** 155,273 **** } ! #define RECVLEN 512 ! ! static apr_status_t getLine(request_rec * r, mcd_res_t* mcd, char **str, apr_size_t count) { ! apr_status_t rv = APR_SUCCESS; ! apr_size_t recvlen; ! char *recv = NULL; ! char *s; ! apr_size_t recv_total = 0; ! ! recvlen = RECVLEN; ! recv = apr_palloc(r->pool, RECVLEN); ! memset(recv, 0, RECVLEN); ! ! if(mcd->line_buff_size == 0) { ! mcd->line_buff = apr_palloc(r->pool, count); ! memset(mcd->line_buff, 0, count); ! } ! else { // existing line buffer ! ! } ! ! while(1){ ! rv = apr_socket_recv(mcd->sock, recv, &recvlen); ! if (rv != APR_SUCCESS) { ! ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "getLine: apr_socket_recv"); ! if(mcd->line_buff_size > 0) { ! *str = apr_pstrcat(r->pool, mcd->line_buff, NULL); ! } ! else { ! *str = NULL; ! } ! return rv; ! } ! recv[recvlen] = 0; ! ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "getline: read-> '%s'", recv); ! if(recvlen+recv_total > count) { ! // line is too big. ! recv[(recvlen+recv_total) - count] = 0; ! *str = apr_pstrcat(r->pool, mcd->line_buff, recv, NULL); ! ! break; ! } ! // find newline! ! s = strstr(recv, "\r\n"); ! if (!s) { ! // newline not found. lets append to the buffer and try again. ! mcd->line_buff = apr_pstrcat(r->pool, mcd->line_buff, recv, NULL); ! mcd->line_buff_size += recvlen; ! continue; ! } ! else { ! // newline was found. stop at it. ! *s = 0; // terminate on the \r ! *s++; // \r ! *s = 0; // terminate on the \n ! *str = apr_pstrcat(r->pool, mcd->line_buff, recv, NULL); ! // do we have an extra string left over? ! if( (recvlen-2) > strlen(recv) ) { ! *s++; // everything after the newline ! mcd->line_buff = apr_pstrcat(r->pool, recv, NULL); ! mcd->line_buff_size = strlen(recv); ! } ! else { ! // hmm ended on a newline? ! mcd->line_buff_size = 0; ! } ! break; ! } ! } ! // free buffers! ! return APR_SUCCESS; } static apr_status_t mcd_get(request_rec * r, mcd_res_t* mcd, const char* key, char** value) { ! apr_status_t rv = APR_SUCCESS; ! apr_size_t sendlen; ! apr_size_t recvlen; ! char *command; ! char *s = NULL; ! command = apr_psprintf(r->pool, "get %s\r\n", key); ! sendlen = strlen(command); ! rv = apr_socket_send(mcd->sock, command, &sendlen); ! if (rv != APR_SUCCESS) { ! ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mcd_get: apr_socket_send"); ! return rv; ! } ! getLine(r, mcd, &command, 5000); ! s = strstr("VALUE", command); ! if (*s != NULL) { ! // VALUE foo 0 5 ! char *pstr; ! char *tok_cntx; ! pstr = command; ! pstr = apr_strtok(pstr, " ", &tok_cntx); // value ! pstr = apr_strtok(pstr, " ", &tok_cntx); // key ! pstr = apr_strtok(pstr, " ", &tok_cntx); // flags ! pstr = apr_strtok(pstr, " ", &tok_cntx); // len ! // recvlen = ! } ! else { ! s = strstr("END", command); ! if (*s != NULL) { ! *value = NULL; ! } ! } ! ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mcd_get: got line: '%s'", command); ! return rv; } --- 162,330 ---- } ! #define MIN_LINE_ALLOC 80 ! static apr_status_t ap_mcd_getline(char **s, apr_size_t n, ! apr_size_t *read, apr_pool_t* pool, ! mcd_res_t *mcd) ! { ! apr_status_t rv; ! apr_bucket *e; ! apr_size_t bytes_handled = 0, current_alloc = 0; ! char *pos, *last_char = *s; ! int do_alloc = (*s == NULL), saw_eos = 0; ! apr_bucket_alloc_t *bb_l; ! apr_bucket_brigade *b; ! bb_l = apr_bucket_alloc_create(mcd->pool); ! b = apr_brigade_create(mcd->pool, bb_l); ! rv = apr_brigade_split_line(b, mcd->bb, APR_NONBLOCK_READ, n); ! /* Something horribly wrong happened. Someone didn't block! */ ! if (APR_BRIGADE_EMPTY(b)) { ! return APR_EGENERAL; ! } ! ! for (;;) { ! ! APR_BRIGADE_FOREACH(e, b) { ! const char *str; ! apr_size_t len; ! /* If we see an EOS, don't bother doing anything more. */ ! if (APR_BUCKET_IS_EOS(e)) { ! saw_eos = 1; ! break; ! } ! ! rv = apr_bucket_read(e, &str, &len, APR_NONBLOCK_READ); ! ! if (rv != APR_SUCCESS) { ! return rv; ! } ! if (len == 0) { ! /* no use attempting a zero-byte alloc (hurts when ! * using --with-efence --enable-pool-debug) or ! * doing any of the other logic either ! */ ! continue; ! } ! ! /* Would this overrun our buffer? If so, we'll die. */ ! if (n < bytes_handled + len) { ! *read = bytes_handled; ! return APR_ENOSPC; ! } ! /* Just copy the rest of the data to the end of the old buffer. */ ! pos = *s + bytes_handled; ! memcpy(pos, str, len); ! last_char = pos + len - 1; ! ! /* We've now processed that new data - update accordingly. */ ! bytes_handled += len; ! } ! ! /* If we got a full line of input, stop reading */ ! if (last_char && (*last_char == APR_ASCII_LF)) { ! break; ! } ! } ! ! /* We now go backwards over any CR (if present) or white spaces. ! * ! * Trim any extra trailing spaces or tabs except for the first ! * space or tab at the beginning of a blank string. This makes ! * it much easier to check field values for exact matches, and ! * saves memory as well. Terminate string at end of line. ! */ ! pos = last_char; ! if (pos > *s && *(pos - 1) == APR_ASCII_CR) { ! --pos; ! } ! ! /* Trim any extra trailing spaces or tabs except for the first ! * space or tab at the beginning of a blank string. This makes ! * it much easier to check field values for exact matches, and ! * saves memory as well. ! */ ! while (pos > ((*s) + 1) ! && (*(pos - 1) == APR_ASCII_BLANK || *(pos - 1) == APR_ASCII_TAB)) { ! --pos; ! } ! ! /* Since we want to remove the LF from the line, we'll go ahead ! * and set this last character to be the term NULL and reset ! * bytes_handled accordingly. ! */ ! *pos = '\0'; ! last_char = pos; ! bytes_handled = pos - *s; ! *read = bytes_handled; ! apr_brigade_destroy(b); ! apr_bucket_alloc_destroy(bb_l); ! return APR_SUCCESS; } + #define LINELEN 512 static apr_status_t mcd_get(request_rec * r, mcd_res_t* mcd, const char* key, char** value) { ! apr_status_t rv = APR_SUCCESS; ! apr_size_t sendlen; ! apr_size_t recvlen; ! apr_bucket *e; ! char *command = NULL; ! char *cmd; ! char *vlen; ! int i; ! ! command = apr_psprintf(mcd->pool, "get %s\r\n", key); ! sendlen = strlen(command); ! ! ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mcd_get: send line: '%s'", command); ! rv = apr_socket_send(mcd->sock, command, &sendlen); ! if (rv != APR_SUCCESS) { ! ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mcd_get: apr_socket_send"); ! return rv; ! } ! ! command = apr_palloc(r->pool, LINELEN); ! for(i=0;i<10;) { // prevent runways ! memset(command, 0, LINELEN); ! ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mcd_get: watiing for line'"); ! ap_mcd_getline(&command, LINELEN, &recvlen, r->pool, mcd); ! ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mcd_get: got line: '%s'", command); ! if(strcmp("END", command) == 0) { ! ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mcd_get: got END."); ! break; ! } ! if(strlen(command) == 0) { ! i++; ! } ! cmd = ap_getword_white_nc(r->pool, &command); ! if(strcmp("VALUE", cmd) == 0) { ! //foo 600 5 ! cmd = ap_getword_white_nc(r->pool, &command); ! cmd = ap_getword_white_nc(r->pool, &command); ! vlen = ap_getword_white_nc(r->pool, &command); ! recvlen = apr_strtoi64(vlen, NULL, 10); ! ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mcd_get: Looking for Value of Len: '%d'", recvlen); ! /* for (;;) { ! const char *str; ! apr_size_t len; ! APR_BRIGADE_FOREACH(e, mcd->bb) { ! rv = apr_bucket_read(e, &str, &len, APR_BLOCK_READ); ! if (rv != APR_SUCCESS) { ! return rv; ! } ! } ! } ! */ ! //break; ! } ! } ! ! return rv; } *************** *** 286,290 **** return rv; } ! getLine(r, mcd, &command, 5000); return rv; --- 343,347 ---- return rv; } ! //getLine(r, mcd, &command, 5000); return rv; *************** *** 386,392 **** current_provider = conf->providers; ! apr_reslist_acquire(reslist_pool, (void **) &mcd); ! mcd_get(r, mcd, "foo", &foo); ! do { const authn_provider *provider; --- 443,450 ---- current_provider = conf->providers; ! // apr_reslist_acquire(reslist_pool, (void **) &mcd); ! mcd_new_conn((void**)&mcd, NULL, r->pool); ! mcd_get(r, mcd, "foo", &foo); ! mcd_kill_conn((void*) mcd, NULL, r->pool); do { const authn_provider *provider; *************** *** 433,438 **** } ! mcd->line_buff_size = 0; ! apr_reslist_release(reslist_pool, (void **) mcd); return auth_result; --- 491,495 ---- } ! // apr_reslist_release(reslist_pool, (void **) mcd); return auth_result; *************** *** 468,480 **** } ! apr_reslist_create(&reslist_pool, DFLT_CONN_MIN, /* hard minimum */ ! DFLT_CONN_SOFT, /* soft maximum */ ! DFLT_CONN_MAX, /* hard maximum */ ! DFLT_CONN_TTL, /* Time to live -- mcd server might override/disconnect! */ ! mcd_new_conn, /* Make a New Connection */ ! mcd_kill_conn, /* Kill Old Connection */ ! (void *) NULL, p); ! apr_pool_cleanup_register(p, p, kill_mcd, apr_pool_cleanup_null); ap_add_version_component(p, "mod_authn_cache_mcd/0.1"); --- 525,537 ---- } ! // apr_reslist_create(&reslist_pool, DFLT_CONN_MIN, /* hard minimum */ ! // DFLT_CONN_SOFT, /* soft maximum */ ! // DFLT_CONN_MAX, /* hard maximum */ ! // DFLT_CONN_TTL, /* Time to live -- mcd server might override/disconnect! */ ! // mcd_new_conn, /* Make a New Connection */ ! // mcd_kill_conn, /* Kill Old Connection */ ! // (void *) NULL, p); ! // apr_pool_cleanup_register(p, p, kill_mcd, apr_pool_cleanup_null); ap_add_version_component(p, "mod_authn_cache_mcd/0.1"); |