Subversion Repositories wimsdev

Rev

Rev 16133 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
  2.  *
  3.  *  This program is free software; you can redistribute it and/or modify
  4.  *  it under the terms of the GNU General Public License as published by
  5.  *  the Free Software Foundation; either version 2 of the License, or
  6.  *  (at your option) any later version.
  7.  *
  8.  *  This program is distributed in the hope that it will be useful,
  9.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.  *  GNU General Public License for more details.
  12.  *
  13.  *  You should have received a copy of the GNU General Public License
  14.  *  along with this program; if not, write to the Free Software
  15.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17.  
  18. /* student score management, definitions */
  19.  
  20. #include <utime.h>
  21. #include <sys/socket.h>
  22. #include <sys/un.h>
  23. #include "../Lib/libwims.h"
  24.  
  25. /* how many seconds in a minute? */
  26. #define MINLENGTH 47
  27. /* maximal running minutes, in order to avoid leaking */
  28. #define MAX_MIN 300
  29. /* queue of socket requests */
  30. #define SOCKET_QUEUE 32
  31. /* socket buffer length */
  32. #define BUFFERLEN (MAX_LINELEN+sizeof(scoreresult)*MAX_CLASSEXOS)
  33. /* number of log lines */
  34. #define MAX_LOGLINES (102400)
  35. /* cuttime buffer, for all exams in a class */
  36. #define CTBUFLEN 4096
  37. /* text buffer length in a sheet cache */
  38. #define SHEETBUFLEN 8192
  39. /* number of cached classes */
  40. /* Storage requirement: about MAX_CLASSCACHE*(MAX_CLASSEXOS*10+CTBUFLEN) bytes. */
  41. #define MAX_CLASSCACHE 20
  42. /* number of cached sheets */
  43. /* Storage requirement: about MAX_SHEETCACHE*SHEETBUFLEN bytes. */
  44. #define MAX_SHEETCACHE 32
  45. /* Refreshment rate for class caches, in seconds */
  46. #define CLASSCACHE_DELAY 100
  47. /* Refreshment rate for sheet caches, in seconds */
  48. #define SHEETCACHE_DELAY 50
  49. /* Maximal debug file length. Debug will be activated once the debug file exists. */
  50. #define MAX_DEBUGLENGTH 1000000
  51. /* delay before ins files are erased. In seconds */
  52. #define INS_DELAY 500
  53.  
  54. #define evalue strevalue
  55. #define tmpd "tmp/log"
  56. #define classd "log/classes"
  57. #define sesd "sessions"
  58. #define modd "public_html/modules"
  59. #define logd "log"
  60. #define pidfile "tmp/log/wimslogd.pid"
  61. #define sockfile "tmp/log/.wimslogd"
  62. #define debugfile "tmp/log/wimslogd.debug"
  63.  
  64. /* from cache.c */
  65. typedef struct exodata {
  66.     int active;
  67.     float weight, require;
  68. } exodata; /* General information of an exercise. Size: 10 bytes. */
  69.  
  70. typedef struct sheetdata {
  71.     unsigned short int start, indstart, exocnt, techcnt, techval, techoffset;
  72. } sheetdata; /* General information of a sheet. Size: xx bytes. */
  73.  
  74. extern struct classdata {
  75.     char name[MAX_CLASSLEN+1];
  76.     char sclass[MAX_CLASSLEN+1];
  77.     char techs[MAX_LINELEN];
  78.     time_t start, last, modif;
  79.     int sheetcnt, exocnt, examcnt, examstart, access;
  80.     struct exodata exos[MAX_CLASSEXOS];
  81.     char ctbuf[CTBUFLEN];
  82.     short int ctptr[MAX_EXOS];
  83.     struct sheetdata exam, sheets[MAX_SHEETS+1];
  84. } classdata[MAX_CLASSCACHE];
  85. int search_data(void *list, int items, size_t item_size, unsigned short int t);
  86. struct classdata *getclasscache(char *cl);
  87. extern char opt_class[MAX_CLASSLEN+1];
  88. extern char **environ;
  89. extern int classcaches, sheetcaches;
  90. void cleancache(void);
  91.  
  92. /* from cleaning.c */
  93. void cleaning(int withmain); /* Clean obsolete session directories. */
  94.  
  95. /* from cmd.c */
  96. extern struct cmdlist {
  97.     char *name;
  98.     void (*routine) (char *p);
  99. } cmdlist[];
  100. extern int cmdcnt;
  101.  
  102. /* from homedir.c */
  103. void homedir(void);
  104.  
  105. /* from housekeep.c */
  106. void backup(void);
  107. void housekeep(void);
  108. void modupdate(void); /* module update */
  109.  
  110. /* from options.c */
  111. extern int options(void);
  112. extern char opt_user[MAX_FNAME+1];
  113. void cmd(void);
  114.  
  115. /* from wimslogdscore.c */
  116. void cmd_getscore(char *p);
  117. void cmd_scorelog(char *p);
  118.  
  119. /* from socket.c */
  120. void sockerror(int type, char *p,...);
  121. void opensock(void);
  122. void answer(int fh);
  123.  
  124. /* from wimslogd.c */
  125. extern char cwd[MAX_FNAME+1];
  126. extern int cwdtype;
  127. enum {dir_home, dir_class, dir_session, dir_module};
  128. extern char qbuf[MAX_LINELEN+1]; /* quota buffer */
  129. extern char ipbuf[64];
  130. extern char loadavg[MAX_LINELEN+1]; /* dans wims.h extern char loadavg[64];*/
  131. extern time_t nowtime, lastcleantime;
  132. extern int idle_time, idle_time2, idle_time3, anti_time;
  133. extern char keepdate[32];
  134. extern char nowstr[64];
  135. extern char mupdate[32], backdate[32];
  136. extern int GEN_LOG_LIMIT, MODULE_LOG_LIMIT, OLD_LOG_FILES, LOG_DELETE;
  137.  
  138. /* from fork.c */
  139. extern int forkcnt;
  140. void addfork(pid_t pid, int type);
  141. void forkman(int kz);
  142. void wait_children(void);
  143. void dispatch_log(void);
  144.  
  145. /*from files.c */
  146. void readfile(char *fname, char buf[], long int buflen); /* read the content of a file */
  147. /* datafile structure: number of records.
  148.  * tag=1 if direct access
  149.  */
  150. unsigned int datafile_recordnum(char *p);
  151. char *datafile_fnd_record(char *p, int n, char bf[]); /* datafile structure: find record n, starting from 1 */
  152. int ftest(char *fname);
  153. enum{is_file, is_dir, is_exec, is_fifo, is_socket, is_unknown};
  154.  
  155. /* from wimslogdlines.c */
  156. void wimslogd_error(char *msg);
  157. extern int commsock, answerlen, debugging;
  158. extern char commbuf[BUFFERLEN+1];
  159. #define textbuf (commbuf+sizeof(int))
  160. void debug(char *p,...);
  161. void my_debug(char *p,...);
  162. extern char *textptr;
  163. void wlogdaccessfile(char *content, char *type, char *s,...);
  164. int call_ssh(int wait,char *s,...);
  165. int call_sh(int wait,char *s,...);
  166. extern int exec_wait;
  167. void getdef(char *fname, char *name, char value[]);
  168.