/[LeafOK_CVS]/lbbs/src/common.c
ViewVC logotype

Diff of /lbbs/src/common.c

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

Revision 1.3 by sysadm, Wed Mar 2 16:33:49 2005 UTC Revision 1.19 by sysadm, Tue May 13 03:07:54 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2                            common.c  -  description                                                    common.c  -  description
3                               -------------------                                                           -------------------
4      begin                : Mon Oct 18 2004          Copyright            : (C) 2004-2025 by Leaflet
5      copyright            : (C) 2004 by Leaflet          Email                : leaflet@leafok.com
     email                : leaflet@leafok.com  
6   ***************************************************************************/   ***************************************************************************/
7    
8  /***************************************************************************  /***************************************************************************
9   *                                                                         *   *                                                                         *
10   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
11   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
12   *   the Free Software Foundation; either version 2 of the License, or     *   *   the Free Software Foundation; either version 3 of the License, or     *
13   *   (at your option) any later version.                                   *   *   (at your option) any later version.                                   *
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
17    #include "common.h"
18    #include "log.h"
19    #include "menu.h"
20    #include <string.h>
21  #include <time.h>  #include <time.h>
22    #include <sys/types.h>
23    
24  //Version information  // Version information
25  char app_version[256] = "LBBS-devel version 1.0";  char app_version[256] = "LBBS-devel version 1.0";
26    
27  //Global declaration for enviroment  // Global declaration for sockets
 char app_home_dir[256];  
   
 //Global declaration for sockets  
28  int socket_server;  int socket_server;
29  int socket_client;  int socket_client;
30  char hostaddr_server[50];  char hostaddr_server[50];
# Line 31  char hostaddr_client[50]; Line 32  char hostaddr_client[50];
32  int port_server;  int port_server;
33  int port_client;  int port_client;
34    
35  //Global declaration for database  // Global declaration for system
36  char DB_host[256];  volatile int SYS_server_exit = 0;
37  char DB_username[50];  volatile int SYS_child_process_count = 0;
38  char DB_password[50];  volatile int SYS_child_exit = 0;
39  char DB_database[50];  volatile int SYS_menu_reload = 0;
40    
41  //Common function  // Common function
42  const char*  const char *str_space(char *string, int length)
43  str_space (char *string, int length)  {
44  {          int i;
45    int i;          for (i = 0; i < length; i++)
46    for (i = 0; i < length; i++)          {
47    {                  string[i] = ' ';
48      string[i] = ' ';          }
49    }          string[length] = '\0';
50    string[length] = '\0';          return string;
51    return string;  }
52  }  
53    const char *get_time_str(char *s, size_t len)
54  const char*  {
55  get_time_str (char *string, size_t length)          time_t curtime = time(NULL);
56  {          struct tm *loctime;
57    char week[10],buffer[256];          loctime = localtime(&curtime);
58    time_t curtime;  
59    struct tm *loctime;          size_t j = strftime(s, len, "%Y年%m月%d日%H:%M:%S ", loctime);
60        
61    curtime = time (NULL);          if (j == 0)
62    loctime = localtime (&curtime);          {
63                    return NULL;
64    strftime (buffer, 256, "%Y年%m月%d日%H:%M:%S ", loctime);          }
65      
66    switch (loctime->tm_wday)          switch (loctime->tm_wday)
67    {          {
68      case 0:          case 0:
69        strcpy (week, "星期天");                  strncat(s, "星期天", len - j);
70        break;                  break;
71      case 1:          case 1:
72        strcpy (week, "星期一");                  strncat(s, "星期一", len - j);
73        break;                  break;
74      case 2:          case 2:
75        strcpy (week, "星期二");                  strncat(s, "星期二", len - j);
76        break;                  break;
77      case 3:          case 3:
78        strcpy (week, "星期三");                  strncat(s, "星期三", len - j);
79        break;                  break;
80      case 4:          case 4:
81        strcpy (week, "星期四");                  strncat(s, "星期四", len - j);
82        break;                  break;
83      case 5:          case 5:
84        strcpy (week, "星期五");                  strncat(s, "星期五", len - j);
85        break;                  break;
86      case 6:          case 6:
87        strcpy (week, "星期六");                  strncat(s, "星期六", len - j);
88        break;                  break;
89    }          }
90    strcat (buffer, week);  
91              return s;
92    strncpy (string, buffer, length);  }
93      
94    return string;  void sig_hup_handler(int i)
95    {
96            SYS_menu_reload = 1;
97    }
98    
99    void sig_term_handler(int i)
100    {
101            log_std("Debug: SIGTERM captured\n");
102            SYS_server_exit = 1;
103    }
104    
105    void sig_chld_handler(int i)
106    {
107            SYS_child_exit = 1;
108    }
109    
110    const char * ip_mask(char * s, int level, char mask)
111    {
112            char * p = s;
113    
114            if (level <= 0)
115            {
116                    return s;
117            }
118            if (level > 4)
119            {
120                    level = 4;
121            }
122    
123            for (int i = 0; i < 4 - level; i++)
124            {
125                    p = strchr(p, '.');
126                    if (p == NULL)
127                    {
128                            return s;
129                    }
130                    p++;
131            }
132    
133            for (int i = 0; i < level; i++)
134            {
135                    *p = mask;
136                    p++;
137                    if (i < level - 1)
138                    {
139                            *p = '.';
140                            p++;
141                    }
142            }
143            *p = '\0';
144    
145            return s;
146  }  }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1