Merge branch 'master' into session_lock
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 8 Jul 2013 12:25:14 +0000 (14:25 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 8 Jul 2013 12:25:14 +0000 (14:25 +0200)
Conflicts:
src/session.c
src/session.h

1  2 
src/client.c
src/connection.c
src/http_command.c
src/session.c
src/session.h
test/test_http.urls

diff --cc src/client.c
Simple merge
Simple merge
Simple merge
diff --cc src/session.c
@@@ -148,58 -135,23 +135,57 @@@ static void log_xml_doc(xmlDoc *doc
      xmlFree(result);
  }
  
 -static void session_enter(struct session *s, const char *caller)
 +void session_enter_ro(struct session *s, const char *caller)
  {
 +    assert(s);
 +    if (caller)
 +        session_log(s, YLOG_LOG, "Session read lock by %s", caller);
 +    pazpar2_lock_rdwr_rlock(&s->lock);
 +}
 +
 +void session_enter_rw(struct session *s, const char *caller)
 +{
 +    assert(s);
 +    if (caller)
 +        session_log(s, YLOG_LOG, "Session write lock by %s", caller);
 +    pazpar2_lock_rdwr_wlock(&s->lock);
 +}
 +
 +void session_upgrade(struct session *s, const char *caller)
 +{
 +    assert(s);
 +    if (caller)
 +        session_log(s, YLOG_LOG, "Session upgrade lock by %s", caller);
 +    pazpar2_lock_rdwr_upgrade(&s->lock);
 +}
 +
 +void session_leave_ro(struct session *s, const char *caller)
 +{
 +    assert(s);
 +    if (caller)
 +        session_log(s, YLOG_LOG, "Session read unlock by %s", caller);
 +    pazpar2_lock_rdwr_runlock(&s->lock);
 +}
 +
 +void session_leave_rw(struct session *s, const char *caller)
 +{
 +    assert(s);
      if (caller)
 -        session_log(s, YLOG_DEBUG, "Session lock by %s", caller);
 -    yaz_mutex_enter(s->session_mutex);
 +        session_log(s, YLOG_LOG, "Session write unlock by %s", caller);
 +    pazpar2_lock_rdwr_wunlock(&s->lock);
  }
  
 -static void session_leave(struct session *s, const char *caller)
 +void session_downgrade(struct session *s, const char *caller)
  {
 -    yaz_mutex_leave(s->session_mutex);
 +    assert(s);
      if (caller)
 -        session_log(s, YLOG_DEBUG, "Session unlock by %s", caller);
 +        session_log(s, YLOG_LOG, "Session write unlock by %s", caller);
 +    pazpar2_lock_rdwr_downgrade(&s->lock);
  }
  
- static void session_normalize_facet(struct session *s, const char *type,
-                                     const char *value,
-                                     WRBUF display_wrbuf,
-                                     WRBUF facet_wrbuf)
+ static void session_normalize_facet(struct session *s,
+                                     const char *type, const char *value,
+                                     WRBUF display_wrbuf, WRBUF facet_wrbuf)
  {
      struct conf_service *service = s->service;
      pp2_charset_token_t prt;
@@@ -737,23 -732,25 +752,25 @@@ static void session_sort_unlocked(struc
      }
  }
  
- void session_sort(struct session *se, struct reclist_sortparms *sp)
+ void session_sort(struct session *se, struct reclist_sortparms *sp,
+                   const char *mergekey, const char *rank)
  {
 -    //session_enter(se, "session_sort");
 +    session_enter_rw(se, "session_sort");
-     session_sort_unlocked(se, sp);
+     session_sort_unlocked(se, sp, mergekey, rank);
 -    //session_leave(se, "session_sort");
 +    session_leave_rw(se, "session_sort");
  }
  
 -
 -enum pazpar2_error_code session_search(struct session *se,
 -                                       const char *query,
 -                                       const char *startrecs,
 -                                       const char *maxrecs,
 -                                       const char *filter,
 -                                       const char *limit,
 -                                       const char **addinfo,
 -                                       struct reclist_sortparms *sp,
 -                                       const char *mergekey,
 -                                       const char *rank)
 +static
 +enum pazpar2_error_code session_search_unlocked(struct session *se,
 +                                                const char *query,
 +                                                const char *startrecs,
 +                                                const char *maxrecs,
 +                                                const char *filter,
 +                                                const char *limit,
 +                                                const char **addinfo,
-                                                 struct reclist_sortparms *sp)
++                                                struct reclist_sortparms *sp,
++                                                const char *mergekey,
++                                                const char *rank)
  {
      int live_channels = 0;
      int no_working = 0;
      else
          session_reset_active_clients(se, 0);
  
 -    session_enter(se, "session_search");
      se->settings_modified = 0;
  
+     if (mergekey)
+     {
+         xfree(se->mergekey);
+         se->mergekey = *mergekey ? xstrdup(mergekey) : 0;
+     }
+     if (rank)
+     {
+         xfree(se->rank);
+         se->rank = *rank ? xstrdup(rank) : 0;
+     }
      session_clear_set(se, sp);
      relevance_destroy(&se->relevance);
  
      return PAZPAR2_NO_ERROR;
  }
  
 +enum pazpar2_error_code session_search(struct session *se,
 +                                       const char *query,
 +                                       const char *startrecs,
 +                                       const char *maxrecs,
 +                                       const char *filter,
 +                                       const char *limit,
 +                                       const char **addinfo,
-                                        struct reclist_sortparms *sp)
++                                       struct reclist_sortparms *sp,
++                                       const char *mergekey,
++                                       const char *rank)
 +{
 +    enum pazpar2_error_code c;
 +    session_enter_rw(se, "session_search");
 +    c = session_search_unlocked(se, query, startrecs, maxrecs, filter,
-                                 limit, addinfo, sp);
++                                limit, addinfo, sp, mergekey, rank);
 +    session_leave_rw(se, "session_search");
 +    return c;
 +}
 +
  // Creates a new session_database object for a database
  static void session_init_databases_fun(void *context, struct database *db)
  {
diff --cc src/session.h
@@@ -154,8 -155,9 +156,10 @@@ struct hitsbytarget 
  };
  
  struct hitsbytarget *get_hitsbytarget(struct session *s, int *count, NMEM nmem);
 -struct session *new_session(NMEM nmem, struct conf_service *service,
 -                            unsigned session_id);
 +struct session *session_create(NMEM nmem, struct conf_service *service,
 +                               unsigned session_id);
+ int sessions_count(void);
++
  void session_destroy(struct session *s);
  void session_init_databases(struct session *s);
  void statistics(struct session *s, struct statistics *stat);
Simple merge