"Fossies" - the Fresh Open Source Software Archive

Member "imapfilter-2.8.2/src/session.c" (26 Dec 2023, 936 Bytes) of package /linux/privat/imapfilter-2.8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "session.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.8.1_vs_2.8.2.

    1 #include <stdio.h>
    2 #include <string.h>
    3 
    4 #include "imapfilter.h"
    5 #include "session.h"
    6 #include "list.h"
    7 
    8 
    9 extern list *sessions;
   10 
   11 
   12 void session_init(session *ssn);
   13 
   14 
   15 /*
   16  * Allocate memory for a new session and add it to the sessions linked list.
   17  */
   18 session *
   19 session_new(void)
   20 {
   21     session *s = (session *)xmalloc(sizeof(session));
   22 
   23     session_init(s);
   24 
   25     sessions = list_append(sessions, s);
   26 
   27     return s;
   28 }
   29 
   30 
   31 /*
   32  * Set session variables to safe values.
   33  */
   34 void
   35 session_init(session *ssn)
   36 {
   37 
   38     ssn->socket = -1;
   39     ssn->sslconn = NULL;
   40     ssn->protocol = PROTOCOL_NONE;
   41     ssn->capabilities = CAPABILITY_NONE;
   42     ssn->ns.prefix = NULL;
   43     ssn->ns.delim = '\0';
   44     ssn->utf8 = 0;
   45 }
   46 
   47 
   48 /*
   49  * Remove session from sessions linked list and free allocated memory.
   50  */
   51 void
   52 session_destroy(session *ssn)
   53 {
   54     
   55     if (!ssn)
   56         return;
   57 
   58     sessions = list_remove(sessions, ssn);
   59 
   60     if (ssn->ns.prefix) {
   61         xfree(ssn->ns.prefix);
   62         ssn->ns.prefix = NULL;
   63     }
   64     xfree(ssn);
   65 }