]>
Commit | Line | Data |
---|---|---|
48864d28 FM |
1 | /*! \file util.c |
2 | \brief Various useful functions. | |
3 | */ | |
4 | ||
5 | ||
6 | ||
7 | ||
8 | ||
9 | /*! \var static char mtab1[12][4]; | |
10 | The list of the months. | |
11 | */ | |
12 | ||
13 | ||
14 | ||
15 | ||
e5b2c6f0 | 16 | /*! \fn void getword_start(struct getwordstruct *gwarea, char *line) |
9c7c6346 | 17 | Initialize the getword buffer with the given text line. |
48864d28 | 18 | |
9c7c6346 FM |
19 | \param gwarea The getword buffer to initialize. |
20 | \param line The text line to use in the getword buffer. | |
21 | */ | |
22 | ||
23 | ||
24 | ||
25 | ||
26 | ||
27 | /*! \fn void getword_restart(struct getwordstruct *gwarea) | |
28 | Restart the getword buffer from the beginning. | |
29 | ||
30 | \param gwarea The getword buffer to reset. | |
31 | */ | |
32 | ||
33 | ||
34 | ||
35 | ||
36 | ||
06b39c87 | 37 | /*! \fn int getword(char *word, int limit, struct getwordstruct *gwarea, char stop) |
48864d28 FM |
38 | |
39 | Extract one "word" from the text line and remove it from the text line. The word's boundary is defined | |
40 | by the \a stop character. If multiple stop characters are found after the word, only the first one is | |
41 | removed. Therfore, passing the line buffer again to the function will remove the next word in a column | |
42 | like manner. | |
43 | ||
44 | \param word The buffer to store the extracted word. | |
45 | \param limit The size of the buffer. If the stop character isn't found before that limit is reached, | |
46 | the function displays an error message and returns an error code. | |
9c7c6346 | 47 | \param gwarea The getword buffer initialized by getword_start(). |
48864d28 FM |
48 | \param stop The character indicating the end of the word. |
49 | ||
50 | \retval 0 The word is extracted. | |
076cbab8 | 51 | \retval -1 The stop character was not found before the limit is reached. |
48864d28 FM |
52 | |
53 | */ | |
54 | ||
55 | ||
56 | ||
57 | ||
58 | ||
06b39c87 | 59 | /*! \fn int getword_limit(char *word, int limit, struct getwordstruct *gwarea, char stop) |
e5b2c6f0 FM |
60 | Extract one word with a maximum size and skip any supernumerary bytes until the stop bytes is |
61 | found. | |
62 | ||
63 | \param word The buffer to store the extracted word. | |
64 | \param limit The size of the buffer. | |
65 | \param gwarea The getword buffer initialized by getword_start(). | |
66 | \param stop The character indicating the end of the word. | |
67 | ||
68 | \retval 0 The word is extracted. | |
69 | */ | |
70 | ||
71 | ||
72 | ||
73 | ||
74 | ||
06b39c87 | 75 | /*! \fn int getword_multisep(char *word, int limit, struct getwordstruct *gwarea, char stop) |
48864d28 FM |
76 | |
77 | Extract one "word" from the text line and remove it from the text line. The word's boundary is defined | |
78 | by the \a stop character. All the stop characters following the word are removed too. Therefore, passing | |
79 | the line buffer again to the function will remove words even if they are separated by multiple stop | |
80 | characters. | |
81 | ||
82 | \param word The buffer to store the extracted word. | |
83 | \param limit The size of the buffer. If the stop character isn't found before that limit is reached, | |
84 | the function displays an error message and returns an error code. | |
9c7c6346 | 85 | \param gwarea The getword buffer initialized by getword_start(). |
48864d28 FM |
86 | \param stop The character indicating the end of the word. |
87 | ||
88 | \retval 0 The word is extracted. | |
076cbab8 | 89 | \retval -1 The stop character was not found before the limit is reached. |
48864d28 FM |
90 | |
91 | */ | |
92 | ||
93 | ||
94 | ||
95 | ||
06b39c87 | 96 | /*! \fn int getword_skip(int limit, struct getwordstruct *gwarea, char stop) |
076cbab8 FM |
97 | Skip one "word" from the text line and remove it from the text line. The word's boundary is defined |
98 | by the \a stop character. | |
48864d28 | 99 | |
076cbab8 | 100 | \param limit The maximum number of characters to skip. If the stop character isn't found before that limit is reached, |
48864d28 | 101 | the function displays an error message and returns an error code. |
9c7c6346 | 102 | \param gwarea The getword buffer initialized by getword_start(). |
48864d28 FM |
103 | \param stop The character indicating the end of the word. |
104 | ||
076cbab8 FM |
105 | \retval 0 The word is skipped. |
106 | \retval -1 The stop character was not found before the limit is reached. | |
48864d28 FM |
107 | */ |
108 | ||
109 | ||
110 | ||
111 | ||
0a4e18e1 | 112 | |
06b39c87 | 113 | /*! \fn int getword_atoll(long long int *number, struct getwordstruct *gwarea, char stop) |
0a4e18e1 FM |
114 | Extract one number from the text line. |
115 | ||
116 | \param number Where the store the extracted number. | |
117 | \param gwarea The getword buffer initialized by getword_start(). | |
118 | \param stop The character indicating the end of the word. | |
119 | ||
e5b2c6f0 | 120 | \retval 0 The number is extracted. |
0a4e18e1 FM |
121 | \retval -1 The stop character was not found after the number. |
122 | */ | |
123 | ||
124 | ||
125 | ||
126 | ||
06b39c87 | 127 | /*! \fn int getword_ptr(char *orig_line,char **word, struct getwordstruct *gwarea, char stop) |
e5b2c6f0 FM |
128 | Return a pointer to a null terminated string starting at the current position and ending |
129 | and the stop character. | |
130 | ||
131 | \param orig_line The line that is being parsed. | |
132 | \param word A pointer to set to the beginning of the string. | |
133 | \param gwarea The getword buffer initialized by getword_start(). | |
134 | \param stop The character indicating the end of the word. | |
135 | ||
136 | \retval 0 The word is skipped. | |
137 | \retval -1 Invalid \a orig_line passed to the function. | |
138 | */ | |
139 | ||
140 | ||
141 | ||
142 | ||
48864d28 FM |
143 | /*! \fn long long int my_atoll (const char *nptr) |
144 | ||
145 | Convert a string into a long long. | |
146 | ||
147 | \param nptr The string containing the number to convert. | |
148 | ||
149 | \return The number found in the string or zero if no number was found. | |
150 | ||
151 | */ | |
152 | ||
153 | ||
154 | ||
155 | ||
156 | ||
6798f0a7 FM |
157 | /*! \fn static int is_absolute(const char *path) |
158 | ||
159 | Tell if the path is absolute. On Unix, a path is absolute if it starts with a /. | |
160 | ||
161 | On Windows, we also check if the path starts with "x:" where x can be any letter. | |
162 | ||
163 | \param path The path to check. | |
164 | ||
165 | \retval 1 The path is absolute. | |
166 | \retval 0 The path is relative. | |
167 | */ | |
168 | ||
169 | ||
170 | ||
171 | ||
172 | ||
48864d28 FM |
173 | /*! \fn void my_mkdir(const char *name) |
174 | ||
175 | Create the directory and all the non existing parent directories. | |
176 | ||
177 | \param name The absolute directory to create. | |
178 | ||
179 | */ | |
180 | ||
181 | ||
182 | ||
183 | ||
184 | ||
e5b2c6f0 | 185 | /*! \fn void my_lltoa(unsigned long long int n, char *s, int ssize, int len) |
48864d28 FM |
186 | |
187 | Format a long long into a string. | |
188 | ||
189 | \param n The number to format. | |
190 | \param s The buffer to write the number. | |
e5b2c6f0 | 191 | \param ssize The size of the output buffer. |
48864d28 FM |
192 | \param len The minimum number of digits to format in the output. If the formatted |
193 | number is less than this length, it is padded with zeros. | |
194 | ||
195 | */ | |
196 | ||
197 | ||
198 | ||
199 | ||
200 | ||
fa6552b0 | 201 | /*! \fn int builddia(int day, int month, int year) |
48864d28 | 202 | |
fa6552b0 | 203 | Return a numerical value made of the date. |
48864d28 | 204 | |
fa6552b0 FM |
205 | \param day The day of the date. |
206 | \param month The number of the month starting from 1. | |
207 | \param year The year. | |
48864d28 | 208 | |
fa6552b0 | 209 | \return The date in an integer format computed as year*10000+month*100+day. |
48864d28 FM |
210 | */ |
211 | ||
212 | ||
213 | ||
214 | ||
215 | ||
216 | /*! \fn void buildymd(const char *dia, const char *mes, const char *ano, char *wdata) | |
217 | Convert the date into a machine format YYYYMMDD. | |
218 | ||
219 | \param dia The day. | |
220 | \param mes The name of the month as spelled in ::mtab1. If the month is invalid, the output date | |
221 | is set to month 13. | |
222 | \param ano The year. | |
223 | \param wdata The buffer to format the date. | |
224 | */ | |
225 | ||
226 | ||
227 | ||
228 | ||
229 | ||
fa6552b0 | 230 | /*! \fn int conv_month(int char *month) |
48864d28 FM |
231 | Convert the month's name into its two digits numerical equivalent. |
232 | ||
fa6552b0 FM |
233 | \param month The name of the month as spelled in ::mtab1. |
234 | ||
235 | \return The month number on starting from one. If the month name is not in ::mtab1, | |
236 | 13 is returned. | |
48864d28 FM |
237 | */ |
238 | ||
239 | ||
240 | ||
241 | ||
242 | ||
fa6552b0 | 243 | /*! \fn const char *conv_month_name(int month) |
48864d28 FM |
244 | Convert a month number into a name. |
245 | ||
fa6552b0 FM |
246 | \param month The number of the month in the range 1 to 12. |
247 | ||
248 | \return The name of the month from ::mtab1 unless the month number is not between 1 and 12 | |
249 | in which case, the number is returned encoded on 3 characters. If the number is | |
250 | invalid, the returned string is static and will be reused by any subsequent call to this | |
251 | function with an invalid month number. | |
48864d28 FM |
252 | */ |
253 | ||
254 | ||
255 | ||
256 | ||
257 | ||
258 | /*! \fn void name_month(char *month,int month_len) | |
259 | Get the name of the month according to the language file selected by the user. | |
260 | ||
261 | \param month The number of the month. It is replaced by the month's name if the number is between | |
262 | 1 and 12 or by the name of December if the number is invalid. | |
263 | \param month_len The size of the \a month buffer. | |
264 | ||
265 | */ | |
266 | ||
267 | ||
268 | ||
269 | ||
270 | ||
48864d28 FM |
271 | /*! \fn void debuga(const char *msg,...) |
272 | Write a debug message to stderr. The message is prefixed by "SARG:" to identify its origin. | |
273 | ||
274 | \param msg The printf like message to format. | |
275 | \param ... The arguments to format in the message. | |
276 | ||
277 | */ | |
278 | ||
279 | ||
280 | ||
281 | ||
282 | ||
283 | /*! \fn void debugaz(const char *head, const char *msg) | |
284 | Write a debug message to stderr with the value of a parameter. The message is prefixed by "SARG: (util)". | |
285 | ||
286 | \param head The name of the parameter. | |
287 | \param msg The value of the parameter. | |
288 | */ | |
289 | ||
290 | ||
291 | ||
292 | ||
293 | ||
48864d28 FM |
294 | /*! \fn char *fixnum(long long int value, int n) |
295 | Rewrite a number to make it more readable. The number may be written | |
296 | with the suffix K, M, G or T depending on its magnitude or the digits | |
297 | are grouped by three and separated by a dot or a comma. | |
298 | ||
299 | \param value The number to format. | |
300 | \param n If the number is abreviated and this parameter is true then append | |
301 | the suffix K, M, G or T if necessary. If it is zero, the number is shortened | |
302 | but no suffix is written. | |
303 | ||
304 | \return A static buffer containing the formatted number. It is overwritten on the next | |
305 | call of this function. | |
306 | ||
307 | */ | |
308 | ||
309 | ||
310 | ||
311 | ||
312 | ||
313 | /*! \def MAXLEN_FIXNUM | |
314 | The size of the buffer to format a number in fixnum(). | |
315 | */ | |
316 | ||
317 | ||
318 | ||
319 | ||
320 | ||
321 | /*! \fn char *fixnum2(long long int value, int n) | |
322 | Format a number by grouping the digits by three and separating the groups by | |
323 | a dot or a comma. | |
324 | */ | |
325 | ||
326 | ||
327 | ||
328 | ||
329 | /*! \def MAXLEN_FIXNUM2 | |
330 | The size of the buffer to format a number in fixnum2(). | |
331 | */ | |
332 | ||
333 | ||
334 | ||
335 | ||
336 | ||
337 | /*! \fn void buildhref(char * href) | |
338 | Replace the path given as argument by the first part of a HTML tag to link to the given | |
339 | directory (the A tag). More precisely, the argument is replaced by <a href=" followed by the given \a href. | |
340 | ||
341 | \param href The directory to replace by a HTML A tag with the open HREF to it. | |
342 | ||
343 | */ | |
344 | ||
345 | ||
346 | ||
347 | ||
348 | ||
349 | /*! \fn char *buildtime(long long int elap) | |
350 | Write the elapsed time given in milliseconds as a string in the format HH:MM:SS. | |
351 | ||
352 | \param elap The elapsed time in milliseconds. | |
353 | ||
354 | \return A static buffer with the formatted time. It is valid until the function is called again. | |
355 | */ | |
356 | ||
357 | ||
358 | ||
359 | ||
360 | ||
361 | /*! \fn void obtdate(const char *dirname, const char *name, char *data) | |
362 | Get the date stored in the <tt>sarg-date</tt> file of a directory with the connection data. | |
363 | ||
364 | \param dirname The directory to look for the connection directory. | |
365 | \param name The name of the directory whose <tt>sarg-date</tt> file must be read. | |
366 | \param data The buffer to store the content of the file. It must be more than 80 | |
367 | bytes long. | |
368 | */ | |
369 | ||
370 | ||
371 | ||
372 | ||
373 | ||
a1de61fe | 374 | /*! \fn void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second,int dst) |
9e41ca7e FM |
375 | Format a date to display it in the report. |
376 | ||
377 | \param date The buffer to write the formatted date into. | |
378 | \param date_size The size of the buffer. | |
379 | \param year The absolute year to format. It must be greater than 1900. | |
380 | \param month The month to format. It must be between 1 and 12. | |
381 | \param day The day to format starting from 1. | |
382 | \param hour The hour to format. | |
383 | \param minute The minute to format. | |
384 | \param second The second to format. | |
a1de61fe | 385 | \param dst A positive number if the daylight saving is active, zero if it is not active and a negative number if it is unknown. |
9e41ca7e FM |
386 | */ |
387 | ||
388 | ||
389 | ||
390 | ||
391 | ||
fa6552b0 FM |
392 | /*! \fn void computedate(int year,int month,int day,struct tm *t); |
393 | Fill a tm structure with the data of the date. | |
9426efec FM |
394 | |
395 | \param year The full year with century. | |
fa6552b0 | 396 | \param month The number of the month starting from one. |
9426efec | 397 | \param day The day of the date. |
fa6552b0 | 398 | \param t The buffer to fill with the date. |
9426efec FM |
399 | */ |
400 | ||
401 | ||
402 | ||
403 | ||
404 | ||
d25d4e6a FM |
405 | /*! \fn int obtuser(const char *dirname, const char *name) |
406 | Get the number of entries stored in a report data directory. The number is read from | |
407 | the <tt>sarg-users</tt> file of the report data's directory. | |
48864d28 | 408 | |
d25d4e6a FM |
409 | \param dirname The directory containing the reports. |
410 | \param name The name of the report directory whose <tt>sarg-users</tt> file must be read. | |
411 | ||
412 | \return The number of entries in the report or zero if the file doesn't exists. | |
48864d28 FM |
413 | */ |
414 | ||
415 | ||
416 | ||
417 | ||
418 | ||
d25d4e6a FM |
419 | /*! \fn void obttotal(const char *dirname, const char *name, char *tbytes, int nuser, char *media) |
420 | Count the total size transfered in a report directory and compute the average number of bytes | |
48864d28 FM |
421 | per entry. |
422 | ||
d25d4e6a FM |
423 | \param dirname The directory containing the reports. |
424 | \param name The name of the report directory whose <tt>sarg-general</tt> file must be read. | |
425 | \param tbytes A buffer to store the total number of bytes from this report. | |
426 | \param nuser The number of entries in the report directory. | |
48864d28 FM |
427 | \param media A buffer to store the average number of bytes per entry. |
428 | */ | |
429 | ||
430 | ||
431 | ||
432 | ||
42b117e3 FM |
433 | |
434 | /*! \fn int getperiod_fromsarglog(const char *arqtt,struct periodstruct *period) | |
435 | Initialize the period with the content of the first line of a sarg log. | |
436 | ||
437 | \param arqtt The text at the first line of a sarg log file. | |
438 | \param period The period to initialize. | |
439 | */ | |
440 | ||
441 | ||
442 | ||
443 | ||
444 | ||
445 | /*! \fn void getperiod_fromrange(struct periodstruct *period,int dfrom,int duntil) | |
446 | Fill the period with the specified range. | |
447 | ||
448 | \param period The period to change. | |
449 | \param dfrom The start date in the form year*10000+month*100+day. | |
450 | \param duntil The end date in the form year*10000+month*100+day. | |
451 | */ | |
452 | ||
453 | ||
454 | ||
455 | ||
456 | ||
fa6552b0 FM |
457 | /*! \fn int getperiod_buildtext(struct periodstruct *period) |
458 | Build the text to display as the date range of the report. | |
48864d28 | 459 | |
fa6552b0 | 460 | \param period The object whose text must be contructed. |
48864d28 | 461 | |
fa6552b0 FM |
462 | \retval 0 No error. |
463 | \retval -1 Resulting text too long for buffer. | |
48864d28 FM |
464 | */ |
465 | ||
466 | ||
467 | ||
468 | ||
fa6552b0 | 469 | |
06ced858 FM |
470 | /*! \fn static void copy_images(void) |
471 | Copy the images (in fact all the files) from the directory ::IMAGEDIR into the output directory | |
472 | whose name is in ::outdir. | |
473 | */ | |
474 | ||
475 | ||
476 | ||
477 | ||
478 | ||
e6414a9d | 479 | /*! \fn void vrfydir(const char *per1, const char *addr, const char *site, const char *us, const char *form) |
48864d28 FM |
480 | Create a directory to generate a report for the specified connection data and populate it with the a <tt>sarg-date</tt> file |
481 | containing the current date. | |
482 | ||
483 | The function also create an <tt>images</tt> directory in \a dir and copy all the files from the <tt>SYSCONFDIR/images</tt> into | |
484 | that directory. | |
485 | ||
48864d28 | 486 | \param per1 The date range in the form: YYYYMMMDD-YYYYMMMDD or DDMMMYYYY-DDMMMYYYY depending on the value of |
e6414a9d | 487 | ::DateFormat. |
48864d28 FM |
488 | \param addr The ip address or host name to which the report is limited. If the string is empty, all the addresses are accepted. |
489 | \param site The destination site to which the report is limited. If the string is empty, all the sites are accepted. | |
490 | \param us The user to whom the report is limited. It is an empty string if all the users are accepted. | |
491 | \param form The email address to which the report is sent. It is currently unused. | |
492 | ||
493 | */ | |
494 | ||
495 | ||
496 | ||
497 | ||
498 | ||
499 | /*! \fn void strip_latin(char *line) | |
500 | Remove any HTML entity from the line. A HTML entity starts with an ampersand and end at the next | |
501 | semicolon. | |
502 | ||
503 | \param line The text whose html entities are to be removed. | |
504 | */ | |
505 | ||
506 | ||
507 | ||
508 | ||
509 | ||
120d768c | 510 | /*! \fn void zdate(char *ftime,int ftimesize, const char *DateFormat) |
48864d28 FM |
511 | Format the current date and time according to the date format. |
512 | ||
120d768c FM |
513 | \param ftime The buffer to format the date. |
514 | \param ftimesize The size of the buffer to store the date | |
48864d28 FM |
515 | \param DateFormat The format of the date. It can be: |
516 | \arg u to format as mmm/dd/YYYY HH:MM | |
517 | \arg e to format as dd/mmm/YYYY HH:MM | |
518 | \arg w to format as WW-HH-MM where WW is the week number in the range 00 to 53. | |
519 | */ | |
520 | ||
521 | ||
522 | ||
523 | ||
524 | ||
525 | /*! \fn char *fixtime(long int elap) | |
526 | Format a "time" into a size or a time formatted as HH:MM:SS. | |
527 | ||
528 | \param elap The "time" to format in milliseconds if it is a time and into bytes if it is a size. | |
529 | ||
530 | \return The formatted time. | |
531 | ||
532 | \bug If the elapsed time is less than 1000ms, the time is formated with the milliseconds as the seconds. | |
533 | ||
534 | \todo Review this function and documentation based on the calls made to it and the arguments passed by the callers. | |
535 | */ | |
536 | ||
537 | ||
538 | ||
539 | ||
540 | ||
42b117e3 | 541 | /*! \fn void date_from(char *date, int *dfrom, int *duntil) |
48864d28 FM |
542 | Split a date range into a date from and a date until. If the date range |
543 | is not a range but just a single date, it is duplicated to make a range out | |
544 | of it. | |
545 | ||
546 | \param date The date range to split in the form <tt>from-until</tt>. If it is a single date, | |
547 | it is transformed into a range like <tt>date-date</tt>. Each date is in the form DD/MM/YYYY. | |
42b117e3 FM |
548 | \param dfrom A variable to write the start date in the form YYYY*10000+MM*100+DD. |
549 | \param duntil A variable to write the end date in the form YYYY*10000+MM*100+DD. | |
48864d28 FM |
550 | */ |
551 | ||
552 | ||
553 | ||
554 | ||
555 | ||
556 | /*! \fn char *strlow(char *string) | |
557 | Convert a string to all lowercases. | |
558 | ||
559 | \param string The string to convert. | |
560 | ||
561 | \return A pointer to the string passed as argument. | |
562 | */ | |
563 | ||
564 | ||
565 | ||
566 | ||
567 | ||
568 | /*! \fn char *strup(char *string) | |
569 | Convert a string to all uppercases. | |
570 | ||
571 | \param string The string to convert. | |
572 | ||
573 | \return A pointer to the string passed as argument. | |
574 | */ | |
575 | ||
576 | ||
577 | ||
578 | ||
579 | ||
48864d28 | 580 | /*! \fn void removetmp(const char *outdir) |
fa6552b0 | 581 | Purge the file <tt>sarg-general</tt> from all the lines but the total. |
48864d28 FM |
582 | |
583 | \param outdir The output directory to purge. | |
584 | */ | |
585 | ||
586 | ||
587 | ||
588 | ||
589 | ||
590 | /*! \fn void load_excludecodes(const char *ExcludeCodes) | |
591 | Load the list of the HTTP codes to exclude from the report. There must be one code per line. | |
592 | Any trailing space is removed and there is no provision for comments. | |
593 | ||
594 | \param ExcludeCodes The name of the file to load. | |
595 | ||
120d768c | 596 | This function allocate the memory to store the codes and it must be freed by a call to |
48864d28 FM |
597 | free_excludecodes(). |
598 | */ | |
599 | ||
600 | ||
601 | ||
602 | ||
603 | ||
604 | /*! \fn void free_excludecodes(void) | |
605 | Free the memory allocated by load_excludecodes(). | |
606 | */ | |
607 | ||
608 | ||
609 | ||
610 | ||
611 | /*! \fn int vercode(const char *code) | |
612 | Check if the code is contained in the exclusion list loaded by load_excludecodes(). | |
613 | ||
614 | \param code The HTTP code to test. | |
615 | ||
616 | \retval 1 The code is excluded. | |
617 | \retval 0 The code is not excluded. | |
618 | */ | |
619 | ||
620 | ||
621 | ||
622 | ||
623 | ||
624 | /*! \fn void fixnone(char *str) | |
625 | Find if the string is the word none and clear the string if it matches. The function | |
626 | tolerates the trailing spaces and tabulations. | |
627 | ||
628 | \param str The text to test for the word "none". | |
629 | */ | |
630 | ||
631 | ||
632 | ||
633 | ||
634 | ||
2357ef77 FM |
635 | /*! \fn void fixendofline(char *str) |
636 | Remove the control codes and spaces at the end of the line. That is, it remove any ASCII | |
637 | code less than or equal to 0x20. | |
638 | ||
639 | \param str The string to truncate. | |
640 | */ | |
641 | ||
642 | ||
643 | ||
644 | ||
48864d28 FM |
645 | /*! \fn int testvaliduserchar(const char *user) |
646 | Tell if the user string contains any invalid character in a user name. The list | |
647 | of the invalid characters is defined by ::UserInvalidChar. | |
648 | ||
649 | \param user The user name to test. | |
650 | ||
651 | \retval 1 The string contains at least one invalid character. | |
652 | \retval 0 The string is valid. | |
653 | */ | |
654 | ||
655 | ||
656 | ||
657 | ||
658 | ||
659 | /*! \fn int compar( const void *a, const void *b ) | |
660 | Compare two integers for bsearch. | |
661 | ||
662 | \param a A pointer to the first integer. | |
663 | \param b A pointer to the second integer. | |
664 | ||
665 | \retval 1 If a > b. | |
666 | \retval 0 If a == b. | |
667 | \retval -1 If a < b. | |
668 | */ | |
669 | ||
670 | ||
671 | ||
672 | ||
673 | ||
674 | /*! \fn int getnumlist( char *buf, numlist *list, const int len, const int maxvalue ) | |
675 | Get a comma separated list of numbers and split them into separate values taking into account | |
676 | that no value may be greater than a maximum. If a value is in fact a range, it is expended. | |
677 | ||
678 | Any duplicate value is removed. | |
679 | ||
680 | \param buf The string with the list of numbers. | |
681 | \param list Where to store the numbers. | |
682 | \param len The size of the list. | |
683 | \param maxvalue The maximum value allowed in the list. | |
684 | ||
685 | \retval 0 No error. | |
686 | \retval -1 Error detected. | |
687 | */ | |
688 | ||
689 | ||
690 | ||
691 | ||
692 | ||
693 | /*! \fn void show_info(FILE *fp_ou) | |
694 | Write the HTML formatted message to indicate the version of sarg that produced | |
695 | the report and when the report was generated. | |
696 | ||
697 | \param fp_ou The HTML file to which the identification block must be appended. | |
698 | */ | |
699 | ||
700 | ||
701 | ||
702 | ||
703 | ||
c0ec9cc7 | 704 | /*! \fn void show_sarg(FILE *fp_ou, int depth) |
48864d28 FM |
705 | Write the header of the report to tell that it was generated by sarg. |
706 | ||
707 | \param fp_ou The handle of the HTML file. | |
c0ec9cc7 FM |
708 | \param depth How deep is the page in the directory tree. It is used to prepend the images directory name |
709 | with as many .. as necessary. If the page is at the same level as the image directory, the depth is zero. | |
48864d28 FM |
710 | */ |
711 | ||
712 | ||
713 | ||
714 | ||
715 | ||
716 | /*! \fn char *get_size(const char *path, const char *file) | |
717 | Get the size, in human readable form and kibibytes, of the content of a directory. | |
718 | ||
719 | \param path The path containing the directory to scan. | |
720 | \param file The last part of the path to the directory to scan. | |
721 | ||
722 | \return The size of the path. | |
723 | */ | |
724 | ||
725 | ||
726 | ||
727 | ||
728 | ||
c0ec9cc7 | 729 | /*! \fn void write_html_header(FILE *fp_ou, int depth, const char *title) |
48864d28 FM |
730 | Write the HTML header of a HTML report file. The DTD correspond to a |
731 | transitional HTML version 4.01. The title of the document is taken from | |
732 | the global variable ::Title. | |
733 | ||
734 | \param fp_ou The file to which the HTML header is written. | |
c0ec9cc7 FM |
735 | \param depth How deep is the page in the directory tree. The depth is passed to show_sarg(). |
736 | \param title The title of the page. | |
737 | */ | |
738 | ||
739 | ||
740 | ||
741 | ||
742 | ||
743 | /*! \fn void close_html_header(FILE *fp_ou) | |
744 | Close the header opened by write_html_header(). | |
745 | ||
746 | \param fp_ou The file to which the HTML header is written. | |
48864d28 FM |
747 | */ |
748 | ||
749 | ||
750 | ||
751 | ||
752 | ||
753 | /*! \fn void baddata(void) | |
754 | Display an error message telling that sarg suspects an attempt to execute arbitrary code and terminate sarg. | |
755 | ||
756 | Any temporary file created by sarg is deleted. | |
757 | */ | |
758 | ||
759 | ||
760 | ||
761 | ||
762 | ||
f84a35a3 FM |
763 | /*! \fn void url_hostname(const char *url,char *hostname,int hostsize) |
764 | Extract the host name from the URL. | |
765 | ||
766 | \param url The url whose host name must be extracted. | |
767 | \param hostname The buffer to store the host name. | |
768 | \param hostsize The size of the host name buffer. | |
769 | ||
770 | \note The function is stupid at this time. It just searches for the first slash | |
771 | in the URL and truncates the URL there. It doesn't take the protocol into account | |
772 | nor the port number nor any user or password information. | |
773 | */ | |
774 | ||
775 | ||
776 | ||
777 | ||
778 | ||
48864d28 FM |
779 | /*! \fn void url_module(const char *url, char *w2) |
780 | Copy at most 254 bytes from the end of the URL or stops at the first /. | |
781 | ||
782 | \param url The URL to parse. | |
783 | \param w2 A buffer to store the copied portion of the URL. The buffer must | |
784 | be at least 255 characters long. | |
785 | */ | |
786 | ||
787 | ||
788 | ||
789 | ||
790 | ||
e5b2c6f0 FM |
791 | /*! \fn void url_to_file(const char *url,char *file,int filesize) |
792 | Mangle an URL to produce a part that can be included in a file. | |
793 | ||
794 | \param url The URL to mangle. | |
795 | \param file The buffer to write the mangled URL. | |
796 | \param filesize The size of the buffer. | |
797 | */ | |
798 | ||
799 | ||
800 | ||
801 | ||
802 | ||
fa6552b0 | 803 | /*! \fn int write_html_trailer(FILE *fp_ou) |
120d768c | 804 | End the HTML file by closing the centered table that was opened by write_html_header(), writting |
48864d28 FM |
805 | the informations of show_info() and closing the body and html tag. After this function returns, the |
806 | HTML file is complete and nothing should be written to it. | |
807 | ||
808 | \param fp_ou The HTML file to close. The file handle is not closed but you should not write anything | |
809 | to the file after this function returns. | |
810 | ||
fa6552b0 FM |
811 | \retval 0 No error. |
812 | \retval -1 Write error. | |
48864d28 FM |
813 | */ |
814 | ||
815 | ||
816 | ||
817 | ||
818 | ||
819 | /*! \fn void version(void) | |
820 | Display the current version of sarg and terminate the program. | |
821 | */ | |
822 | ||
823 | ||
824 | ||
825 | ||
826 | ||
827 | /*! \fn char *get_param_value(const char *param,char *line) | |
828 | Get the value of a parameter formatted in the string as "param value" | |
829 | without the quotes. | |
830 | ||
831 | If the parameter name matches \a param, then the value following the parameter | |
832 | is returned. If it doesn't match, the function return NULL. | |
833 | ||
834 | The function is suitable to parse configuration files because it will ignore | |
835 | comments (anything but spaces and tabulations put before the parameter will make | |
836 | it unrecognized by this function) | |
837 | ||
838 | \param param The parameter name that must be found at the beginning of the line | |
839 | with possible spaces or tabulations before. | |
840 | \param line The text line to search for the parameter and it's value. | |
841 | ||
842 | \return The beginning of the value after the equal sign and with the possible | |
843 | spaces or tabulations removed. If the line doesn't start with the parameter name, | |
844 | the function returns NULL. | |
845 | ||
846 | */ | |
847 | ||
848 | ||
849 | ||
850 | ||
851 | ||
dfb337be FM |
852 | /*! \fn void write_logo_image(FILE *fp_ou) |
853 | Write a link of the logo of the organisation that generate the report in the HTML file. The logo | |
854 | is written in a centered table. | |
855 | ||
856 | \param fp_ou The handle of the HTML file being written. | |
857 | */ | |
858 | ||
859 | ||
860 | ||
861 | ||
ac422f9b FM |
862 | |
863 | /*! \fn void output_html_string(FILE *fp_ou,const char *str,int maxlen) | |
dfb337be FM |
864 | Write a string in a file and replace the problematic ASCII characters by their equivalent HTML entities. |
865 | ||
866 | \param fp_ou The handle of the output file. | |
867 | \param str The string to output. | |
ac422f9b FM |
868 | \param maxlen The maximum number of bytes to write from the string. Set to zero to have no limit. |
869 | ||
870 | If the string is longer than the requested length, only the requested number of bytes are output and | |
871 | the string is truncated and ended by …. | |
872 | */ | |
873 | ||
874 | ||
875 | ||
876 | ||
877 | ||
878 | /*! \fn void output_html_url(FILE *fp_ou,const char *url) | |
879 | Write an URL into the file and replace any & by &. | |
880 | ||
881 | \param fp_ou The handle of the output file. | |
882 | \param url The URL to output. | |
dfb337be | 883 | */ |
51465d08 FM |
884 | |
885 | ||
886 | ||
887 | ||
888 | ||
889 | /*! \fn void unlinkdir(const char *dir,int contentonly) | |
890 | Delete a directory and its content. | |
891 | ||
892 | \param dir The name of the directory to delete. | |
893 | \param contentonly \c True to delete only the content of the directory and leave the directory | |
894 | itself in place. If set to \c zero, the directory is removed too. | |
895 | */ | |
ac422f9b | 896 |