File: load.C

package info (click to toggle)
peruser 4b33-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,952 kB
  • ctags: 1,064
  • sloc: cpp: 22,367; perl: 2,733; makefile: 345; sh: 335
file content (84 lines) | stat: -rw-r--r-- 2,225 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

#include "npfile.h"
#include "npstringarray.h"
#include "npauthentication.h"

int NP_Authentication::load()
{
   int result;
   if (( result = config_file.openr( config_path )))
      if ( errno != ENOENT )
      {
         snprintf( error_message, sizeof error_message, "NP_Authentication: "
                   "load(): %s", config_file.get_error() );
         return 1;
      }

   int i = 4;
   if ( !result )
      while( i-- )
         if ( config_file.get_string() == NULL )
         {
            snprintf( error_message, sizeof error_message,
                      "NP_Authentication: "
                      "load(): %s", config_file.get_error() );
            return 1;
         }

   if ( !result )
      while( config_file.get_string() != NULL )
      {
         char *line, user[ 1024 ], pass[ 1024 ];

         if (( line = config_file.get_string()) == NULL )
         {
            snprintf( error_message, sizeof error_message,
                      "NP_Authentication: "
                      "load(): %s", config_file.get_error() );
            return 1;
         }

         strcpy( user, line );
         
         if (( line = config_file.get_string()) == NULL )
         {
            snprintf( error_message, sizeof error_message,
                      "NP_Authentication: "
                      "load(): %s", config_file.get_error() );
            return 1;
         }

         strcpy( pass, line );
         
         if ( strtok( user, "\n" ) == NULL )
            *user = '\0';
      
         if ( user_list.add_item( user ))
         {
            snprintf( error_message, sizeof error_message,
                      "NP_Authentication: "
                      "load(): %s", user_list.get_error() );
            return 1;
         }

         if ( strtok( pass, "\n" ) == NULL )
            *pass = '\0';
      
         if ( pass_list.add_item( pass ))
         {
            snprintf( error_message, sizeof error_message,
                      "NP_Authentication: "
                      "load(): %s", pass_list.get_error() );
            return 1;
         }
      }
   
   config_file.close();

   return 0;
}