/[Apache-SVN]/httpd/httpd/trunk/modules/session/mod_session_dbd.c
ViewVC logotype

Diff of /httpd/httpd/trunk/modules/session/mod_session_dbd.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1409170 by fuankg, Wed Nov 14 11:43:49 2012 UTC revision 1488158 by minfrin, Fri May 31 11:13:25 2013 UTC
# Line 230  static apr_status_t session_dbd_load(req Line 230  static apr_status_t session_dbd_load(req
230      zz = (session_rec *) apr_pcalloc(r->pool, sizeof(session_rec));      zz = (session_rec *) apr_pcalloc(r->pool, sizeof(session_rec));
231      zz->pool = r->pool;      zz->pool = r->pool;
232      zz->entries = apr_table_make(zz->pool, 10);      zz->entries = apr_table_make(zz->pool, 10);
233      zz->uuid = (apr_uuid_t *) apr_pcalloc(zz->pool, sizeof(apr_uuid_t));      if (key && val) {
234      if (key) {          apr_uuid_t *uuid = apr_pcalloc(zz->pool, sizeof(apr_uuid_t));
235          apr_uuid_parse(zz->uuid, key);          if (APR_SUCCESS == apr_uuid_parse(uuid, key)) {
236                zz->uuid = uuid;
237      }      }
     else {  
         apr_uuid_get(zz->uuid);  
238      }      }
239      zz->encoded = val;      zz->encoded = val;
240      *z = zz;      *z = zz;
# Line 250  static apr_status_t session_dbd_load(req Line 249  static apr_status_t session_dbd_load(req
249  /**  /**
250   * Save the session by the key specified.   * Save the session by the key specified.
251   */   */
252  static apr_status_t dbd_save(request_rec * r, const char *key, const char *val,  static apr_status_t dbd_save(request_rec * r, const char *oldkey,
253                               apr_int64_t expiry)          const char *newkey, const char *val, apr_int64_t expiry)
254  {  {
255    
256      apr_status_t rv;      apr_status_t rv;
# Line 272  static apr_status_t dbd_save(request_rec Line 271  static apr_status_t dbd_save(request_rec
271      if (rv) {      if (rv) {
272          return rv;          return rv;
273      }      }
274      rv = apr_dbd_pvbquery(dbd->driver, r->pool, dbd->handle, &rows, statement,  
275                            val, &expiry, key, NULL);      if (oldkey) {
276            rv = apr_dbd_pvbquery(dbd->driver, r->pool, dbd->handle, &rows,
277                    statement, val, &expiry, newkey, oldkey, NULL);
278      if (rv) {      if (rv) {
279          ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01857)              ap_log_rerror(
280                        "query execution error updating session '%s' "                      APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01857) "query execution error updating session '%s' "
281                        "using database query '%s': %s", key, conf->updatelabel,                      "using database query '%s': %s/%s", oldkey, newkey, conf->updatelabel, apr_dbd_error(dbd->driver, dbd->handle, rv));
                       apr_dbd_error(dbd->driver, dbd->handle, rv));  
282          return APR_EGENERAL;          return APR_EGENERAL;
283      }      }
284    
# Line 289  static apr_status_t dbd_save(request_rec Line 289  static apr_status_t dbd_save(request_rec
289      if (rows != 0) {      if (rows != 0) {
290          return APR_SUCCESS;          return APR_SUCCESS;
291      }      }
292        }
293    
294      if (conf->insertlabel == NULL) {      if (conf->insertlabel == NULL) {
295          ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01858)          ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01858)
# Line 301  static apr_status_t dbd_save(request_rec Line 302  static apr_status_t dbd_save(request_rec
302          return rv;          return rv;
303      }      }
304      rv = apr_dbd_pvbquery(dbd->driver, r->pool, dbd->handle, &rows, statement,      rv = apr_dbd_pvbquery(dbd->driver, r->pool, dbd->handle, &rows, statement,
305                            val, &expiry, key, NULL);                            val, &expiry, newkey, NULL);
306      if (rv) {      if (rv) {
307          ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01859)          ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01859)
308                        "query execution error inserting session '%s' "                        "query execution error inserting session '%s' "
309                        "in database with '%s': %s", key, conf->insertlabel,                        "in database with '%s': %s", newkey, conf->insertlabel,
310                        apr_dbd_error(dbd->driver, dbd->handle, rv));                        apr_dbd_error(dbd->driver, dbd->handle, rv));
311          return APR_EGENERAL;          return APR_EGENERAL;
312      }      }
# Line 320  static apr_status_t dbd_save(request_rec Line 321  static apr_status_t dbd_save(request_rec
321    
322      ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01860)      ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01860)
323                    "the session insert query did not cause any rows to be added "                    "the session insert query did not cause any rows to be added "
324                    "to the database for session '%s', session not inserted", key);                    "to the database for session '%s', session not inserted", newkey);
325    
326      return APR_EGENERAL;      return APR_EGENERAL;
327    
# Line 397  static apr_status_t dbd_clean(apr_pool_t Line 398  static apr_status_t dbd_clean(apr_pool_t
398  static apr_status_t session_dbd_save(request_rec * r, session_rec * z)  static apr_status_t session_dbd_save(request_rec * r, session_rec * z)
399  {  {
400    
     char *buffer;  
401      apr_status_t ret = APR_SUCCESS;      apr_status_t ret = APR_SUCCESS;
402      session_dbd_dir_conf *conf = ap_get_module_config(r->per_dir_config,      session_dbd_dir_conf *conf = ap_get_module_config(r->per_dir_config,
403                                                        &session_dbd_module);                                                        &session_dbd_module);
404    
405      /* support anonymous sessions */      /* support anonymous sessions */
406      if (conf->name_set || conf->name2_set) {      if (conf->name_set || conf->name2_set) {
407            char *oldkey = NULL, *newkey = NULL;
408    
409          /* don't cache pages with a session */          /* don't cache pages with a session */
410          apr_table_addn(r->headers_out, "Cache-Control", "no-cache");          apr_table_addn(r->headers_out, "Cache-Control", "no-cache");
411    
412          /* must we create a uuid? */          /* if the session is new or changed, make a new session ID */
413          buffer = apr_pcalloc(r->pool, APR_UUID_FORMATTED_LENGTH + 1);          if (z->uuid) {
414          apr_uuid_format(buffer, z->uuid);              oldkey = apr_pcalloc(r->pool, APR_UUID_FORMATTED_LENGTH + 1);
415                apr_uuid_format(oldkey, z->uuid);
416            }
417            if (z->dirty || !oldkey) {
418                z->uuid = apr_pcalloc(z->pool, sizeof(apr_uuid_t));
419                apr_uuid_get(z->uuid);
420                newkey = apr_pcalloc(r->pool, APR_UUID_FORMATTED_LENGTH + 1);
421                apr_uuid_format(newkey, z->uuid);
422            }
423            else {
424                newkey = oldkey;
425            }
426    
427          /* save the session with the uuid as key */          /* save the session with the uuid as key */
428          if (z->encoded && z->encoded[0]) {          if (z->encoded && z->encoded[0]) {
429              ret = dbd_save(r, buffer, z->encoded, z->expiry);              ret = dbd_save(r, oldkey, newkey, z->encoded, z->expiry);
430          }          }
431          else {          else {
432              ret = dbd_remove(r, buffer);              ret = dbd_remove(r, oldkey);
433          }          }
434          if (ret != APR_SUCCESS) {          if (ret != APR_SUCCESS) {
435              return ret;              return ret;
# Line 425  static apr_status_t session_dbd_save(req Line 437  static apr_status_t session_dbd_save(req
437    
438          /* create RFC2109 compliant cookie */          /* create RFC2109 compliant cookie */
439          if (conf->name_set) {          if (conf->name_set) {
440              ap_cookie_write(r, conf->name, buffer, conf->name_attrs, z->maxage,              ap_cookie_write(r, conf->name, newkey, conf->name_attrs, z->maxage,
441                              r->headers_out, r->err_headers_out, NULL);                              r->headers_out, r->err_headers_out, NULL);
442          }          }
443    
444          /* create RFC2965 compliant cookie */          /* create RFC2965 compliant cookie */
445          if (conf->name2_set) {          if (conf->name2_set) {
446              ap_cookie_write2(r, conf->name2, buffer, conf->name2_attrs, z->maxage,              ap_cookie_write2(r, conf->name2, newkey, conf->name2_attrs, z->maxage,
447                               r->headers_out, r->err_headers_out, NULL);                               r->headers_out, r->err_headers_out, NULL);
448          }          }
449    
# Line 446  static apr_status_t session_dbd_save(req Line 458  static apr_status_t session_dbd_save(req
458          apr_table_addn(r->headers_out, "Cache-Control", "no-cache");          apr_table_addn(r->headers_out, "Cache-Control", "no-cache");
459    
460          if (r->user) {          if (r->user) {
461              ret = dbd_save(r, r->user, z->encoded, z->expiry);              ret = dbd_save(r, r->user, r->user, z->encoded, z->expiry);
462              if (ret != APR_SUCCESS) {              if (ret != APR_SUCCESS) {
463                  return ret;                  return ret;
464              }              }

Legend:
Removed from v.1409170  
changed lines
  Added in v.1488158

infrastructure at apache.org
ViewVC Help
Powered by ViewVC 1.1.26