"Fossies" - the Fresh Open Source Software Archive

Member "gsa-9.0.0/gsad/src/gsad_credentials.c" (14 Oct 2019, 2182 Bytes) of package /linux/misc/openvas/gsa-9.0.0.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 "gsad_credentials.c" see the Fossies "Dox" file reference documentation.

    1 /* Copyright (C) 2018 Greenbone Networks GmbH
    2  *
    3  * SPDX-License-Identifier: GPL-2.0-or-later
    4  *
    5  * This program is free software; you can redistribute it and/or
    6  * modify it under the terms of the GNU General Public License
    7  * as published by the Free Software Foundation; either version 2
    8  * of the License, or (at your option) any later version.
    9  *
   10  * This program is distributed in the hope that it will be useful,
   11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  * GNU General Public License for more details.
   14  *
   15  * You should have received a copy of the GNU General Public License
   16  * along with this program; if not, write to the Free Software
   17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   18  */
   19 
   20 /**
   21  * @file gsad_credentials.c
   22  * @brief GSAD credentials handling
   23  */
   24 
   25 #include "gsad_credentials.h"
   26 
   27 #include "gsad_user.h"
   28 
   29 #include <glib.h>
   30 
   31 /**
   32  *  @brief Structure of credential related information.
   33  */
   34 struct credentials
   35 {
   36   struct timeval cmd_start; ///< Seconds since command page handler started.
   37   gchar *language;          ///< Language for this request
   38   user_t *user;             ///< Current user
   39 };
   40 
   41 credentials_t *
   42 credentials_new (user_t *user, const gchar *language)
   43 {
   44   credentials_t *credentials;
   45 
   46   credentials = g_malloc0 (sizeof (credentials_t));
   47   credentials->user = user_copy (user);
   48   credentials->language = g_strdup (language);
   49 
   50   return credentials;
   51 }
   52 
   53 void
   54 credentials_free (credentials_t *creds)
   55 {
   56   if (!creds)
   57     return;
   58 
   59   g_free (creds->language);
   60 
   61   user_free (creds->user);
   62 
   63   g_free (creds);
   64 }
   65 
   66 user_t *
   67 credentials_get_user (credentials_t *cred)
   68 {
   69   return cred->user;
   70 }
   71 
   72 const gchar *
   73 credentials_get_language (credentials_t *cred)
   74 {
   75   return cred->language;
   76 }
   77 
   78 void
   79 credentials_start_cmd (credentials_t *creds)
   80 {
   81   gettimeofday (&creds->cmd_start, NULL);
   82 }
   83 
   84 double
   85 credentials_get_cmd_duration (credentials_t *cred)
   86 {
   87   struct timeval tv;
   88   gettimeofday (&tv, NULL);
   89   return ((double) ((tv.tv_sec - cred->cmd_start.tv_sec) * 1000000L + tv.tv_usec
   90                     - cred->cmd_start.tv_usec)
   91           / 1000000.0);
   92 }