/[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.7 by sysadm, Sat May 7 12:08:28 2005 UTC Revision 1.18 by sysadm, Sun May 11 01:54:00 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"  #include "menu.h"
20    #include <string.h>
21  #include <time.h>  #include <time.h>
22  #include <sys/types.h>  #include <sys/types.h>
 #include <sys/wait.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];  
 char app_temp_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 35  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  //Global declaration for system  // Common function
42  int SYS_exit;  const char *str_space(char *string, int length)
43  int SYS_child_process_count;  {
44            int i;
45  //Common function          for (i = 0; i < length; i++)
46  const char *          {
47  str_space (char *string, int length)                  string[i] = ' ';
48  {          }
49    int i;          string[length] = '\0';
50    for (i = 0; i < length; i++)          return string;
51      {  }
52        string[i] = ' ';  
53      }  const char *get_time_str(char *s, size_t len)
54    string[length] = '\0';  {
55    return string;          time_t curtime = time(NULL);
56  }          struct tm *loctime;
57            loctime = localtime(&curtime);
58  const char *  
59  get_time_str (char *string, size_t length)          size_t j = strftime(s, len, "%Y年%m月%d日%H:%M:%S ", loctime);
60  {  
61    char week[10], buffer[256];          if (j == 0)
62    time_t curtime;          {
63    struct tm *loctime;                  return NULL;
64            }
65    curtime = time (NULL);  
66    loctime = localtime (&curtime);          switch (loctime->tm_wday)
67            {
68    strftime (buffer, 256, "%Y年%m月%d日%H:%M:%S ", loctime);          case 0:
69                    strncat(s, "星期天", len - j);
70    switch (loctime->tm_wday)                  break;
71      {          case 1:
72      case 0:                  strncat(s, "星期一", len - j);
73        strcpy (week, "星期天");                  break;
74        break;          case 2:
75      case 1:                  strncat(s, "星期二", len - j);
76        strcpy (week, "星期一");                  break;
77        break;          case 3:
78      case 2:                  strncat(s, "星期三", len - j);
79        strcpy (week, "星期二");                  break;
80        break;          case 4:
81      case 3:                  strncat(s, "星期四", len - j);
82        strcpy (week, "星期三");                  break;
83        break;          case 5:
84      case 4:                  strncat(s, "星期五", len - j);
85        strcpy (week, "星期四");                  break;
86        break;          case 6:
87      case 5:                  strncat(s, "星期六", len - j);
88        strcpy (week, "星期五");                  break;
89        break;          }
90      case 6:  
91        strcpy (week, "星期六");          return s;
92        break;  }
93      }  
94    strcat (buffer, week);  void sig_hup_handler(int i)
95    {
96    strncpy (string, buffer, length);          SYS_menu_reload = 1;
97    }
98    return string;  
99  }  void sig_term_handler(int i)
100    {
101  void          SYS_server_exit = 1;
102  reload_bbs_menu (int i)  }
103  {  
104    if (reload_menu (&bbs_menu) < 0)  void sig_chld_handler(int i)
105      log_error ("Reload menu failed\n");  {
106    else          SYS_child_exit = 1;
107      log_std ("Reload menu successfully\n");  }
108    
109  }  const char * ip_mask(char * s, int level, char mask)
110    {
111  void          char * p = s;
112  system_exit (int i)  
113  {          if (level <= 0)
114    SYS_exit = 1;          {
115    log_std ("Get SIG_BBS_EXIT signal successfully\n");                  return s;
116  }          }
117            if (level > 4)
118  void          {
119  child_exit (int i)                  level = 4;
120  {          }
121    int pid;  
122              for (int i = 0; i < 4 - level; i++)
123    pid = wait (0);          {
124                    p = strchr(p, '.');
125    if (pid > 0)                  if (p == NULL)
126      {                  {
127        SYS_child_process_count --;                          return s;
128        log_std ("Child process (%d) exited\n", pid);                  }
129      }                  p++;
130            }
131    
132            for (int i = 0; i < level; i++)
133            {
134                    *p = mask;
135                    p++;
136                    if (i < level - 1)
137                    {
138                            *p = '.';
139                            p++;
140                    }
141            }
142            *p = '\0';
143    
144            return s;
145  }  }


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

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