Re: Reading post parameters from apache request
2009/11/21 Sorin Manolache : > On Fri, Nov 20, 2009 at 22:01, pranil dasika wrote: >> Hi, >> >> I am trying to write a custom module where I need to read post parameters >> from the request. I guess apreq library is relevant to this but could not >> find any substantial examples or documents. >> Is there any other way to read the params other than apreq. Any pseudocode/ >> examples will be appreciated. >> >> Thanks, >> Pranil >> > > Here you have an example. It is not optimal, you could, for example, > take the brigade creation out of the loop and clean the brigade at the > end of each iteration, after you extracted the data. > > apr_bucket_brigade *bb; > do { > bb = apr_brigade_create(req->pool, req->connection->bucket_alloc); > if (0 == bb) > // error > if (APR_SUCCESS != ap_get_brigade(req->input_filters, bb, > AP_MODE_READBYTES, APR_BLOCK_READ, 9216)) > // error > extract data from bb; > } while (EOS not yet encountered in bb); > > > S > Hi I have an another example. I read post parameters in the source code below: http://github.com/yokawasa/mod_akismet/blob/master/mod_akismet.c#L647 line: 647 - 705 hope this helps you. Yoichi -- Yoichi Kawasaki
Re: maintaining sessions among multiple processes
> > i find your book to be one of the most enlightening ones written in > recent years, but i haven't found the answers to my question in there. > the closest you get to touching the subject is perhaps the section on > "session management with SQL", which as jim jagielski also points out, > might be the way forward. it's just that my session objects contains > objects of unknown types so i don't know how to store them in a > traditional rdbms. maybe i can figure out a way to convert them to > blobs if you tell me that there is no way to do what i originally > suggested: interfere with the request dispatching in apache. > why don't you serizlie the session objects and store them in rdmbs, memcached, etc? I use the term "seralize" and "deserialize" to mean the deconstruction of "sessionObject" to a sequence of bytes, and reverse construction from a sequece of bytes to "sessionObject" respectively. for serialization, you can use any famouse libraries like "boost::serialization" or create a converter that can achive this kind of thing by yourself if the structure of "sessionObject" is simple enough. Yoichi -- Yoichi Kawasaki
Re: apr_global_mutex_lock() failing with "permission denied"
Hi Elison. 2009/3/21 Elison Smith : > I am using shared memory to share some data between my module instances in > Apache child processes, and apr_global_mutex_t to achieve > mutually-exclusive reads and writes. > > In a post_config_hook, I create the mutex using apr_global_mutex_create() > and then reopen it inside each child process by calling > apr_global_mutex_child_init() inside a child_init hook. > > However, when I try to grab the lock inside a child, the operation fails > with a "permission denied". For the lock file, I am using "/tmp/tmp" which > is a file writeable by all. > > Any clues? > the platform on which your module runs is unix? There should be such a permission problem if the parent process starts as root while child processes as user/group that you specify in apache configuration file. In that case, use unixd_set_global_mutex_perms in child_init hook, after apr_global_mutex_create just like this below: ** code snippet from mod_rewrite.c - #ifdef AP_NEED_SET_MUTEX_PERMS #include "unixd.h" #endif ... /* create the lockfile */ rc = apr_global_mutex_create(&rewrite_mapr_lock_acquire, lockname, APR_LOCK_DEFAULT, p); if (rc != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rc, s, "mod_rewrite: Parent could not create RewriteLock " "file %s", lockname); return rc; } #ifdef AP_NEED_SET_MUTEX_PERMS rc = unixd_set_global_mutex_perms(rewrite_mapr_lock_acquire); if (rc != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rc, s, "mod_rewrite: Parent could not set permissions " "on RewriteLock; check User and Group directives"); return rc; } #endif - you should also see unixd.h (/path-to-apache/include/unixd.h) - /** * One of the functions to set mutex permissions should be called in * the parent process on platforms that switch identity when the * server is started as root. * If the child init logic is performed before switching identity * (e.g., MPM setup for an accept mutex), it should only be called * for SysV semaphores. Otherwise, it is safe to call it for all * mutex types. */ AP_DECLARE(apr_status_t) unixd_set_proc_mutex_perms(apr_proc_mutex_t *pmutex); AP_DECLARE(apr_status_t) unixd_set_global_mutex_perms(apr_global_mutex_t *gmutex); AP_DECLARE(apr_status_t) unixd_accept(void **accepted, ap_listen_rec *lr, apr_pool_t *ptrans); - good luck! Yoichi -- -- Yoichi Kawasaki