annotate util.h @ 627:493c08d452d9

API changes in th_network.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 21 Jun 2014 05:11:14 +0300
parents 97a49a6cc959
children 68994cb1f1a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * NNChat - Custom chat client for NewbieNudes.com chatrooms
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Written by Matti 'ccr' Hämäläinen
581
97a49a6cc959 Bump copyright year.
Matti Hamalainen <ccr@tnsp.org>
parents: 541
diff changeset
4 * (C) Copyright 2008-2013 Tecnic Software productions (TNSP)
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 */
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #ifndef LIBNNUTIL_H
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #define LIBNNUTIL_H
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include <stdio.h>
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include <unistd.h>
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include "th_types.h"
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #include "th_string.h"
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #define NN_TMPBUF_SIZE (4096)
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 #define NN_ALLOC_SIZE (128)
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #define NN_NUM_BUCKETS (256)
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 typedef struct _nn_user_t
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 {
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 char *name;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 time_t lastspoke, joined;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 struct _nn_user_t *next;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 } nn_user_t;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 typedef struct
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 {
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 nn_user_t *buckets[NN_NUM_BUCKETS];
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 } nn_userhash_t;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 nn_userhash_t *nn_userhash_new(void);
485
ad7ddce47878 Improve nn_userhash_foreach() by adding user data parameter.
Matti Hamalainen <ccr@tnsp.org>
parents: 466
diff changeset
35 nn_user_t * nn_userhash_foreach(const nn_userhash_t *, int (*func)(const nn_user_t *, void *userdata), void *data);
446
3396acd40147 Rename and remove some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
36 nn_user_t * nn_userhash_match(const nn_userhash_t *list, const char *str, const char *current, BOOL again);
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 int nn_userhash_insert(nn_userhash_t *, const char *name);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 int nn_userhash_delete(nn_userhash_t *, const char *name);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 void nn_userhash_free(nn_userhash_t *);
446
3396acd40147 Rename and remove some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
40 nn_user_t * nn_userhash_find(const nn_userhash_t *list, const char *name);
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 char * nn_encode_str1(const char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 char * nn_decode_str1(const char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 char * nn_encode_str2(const char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 char * nn_decode_str2(const char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 char * nn_strip_tags(const char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 char * nn_dbldecode_str(const char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 char * nn_dblencode_str(const char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 char * nn_username_encode(char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 char * nn_username_decode(char *str);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 typedef struct
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 {
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 size_t pos, len, size;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 char *data;
492
73f8df0ecffe Add dirty flag to editbuf struct and handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 485
diff changeset
59 BOOL dirty;
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 } nn_editbuf_t;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 int nn_editbuf_write(nn_editbuf_t *buf, size_t pos, char ch);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 int nn_editbuf_insert(nn_editbuf_t *buf, size_t pos, char ch);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 int nn_editbuf_delete(nn_editbuf_t *buf, size_t pos);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 void nn_editbuf_clear(nn_editbuf_t *buf);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 nn_editbuf_t * nn_editbuf_new(size_t n);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 void nn_editbuf_free(nn_editbuf_t *buf);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 nn_editbuf_t * nn_editbuf_copy(nn_editbuf_t *src);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 void nn_editbuf_setpos(nn_editbuf_t *buf, size_t pos);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 char * nn_editbuf_get_string(nn_editbuf_t *buf, size_t start, size_t end);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 typedef struct
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 {
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 size_t len;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 char *str;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 } nn_strtuple_t;
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 nn_strtuple_t *nn_strtuple_new(size_t, char *);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 void nn_strtuple_free(nn_strtuple_t *);
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
464
35d67bd0613b Move str_*() functions to util.c
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
83
35d67bd0613b Move str_*() functions to util.c
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
84 BOOL str_get_timestamp(char *str, size_t len, const char *fmt);
35d67bd0613b Move str_*() functions to util.c
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
85 char * str_trim_left(char *buf);
498
b6f6c989deab Add str_trim_right().
Matti Hamalainen <ccr@tnsp.org>
parents: 492
diff changeset
86 char * str_trim_right(char *buf);
464
35d67bd0613b Move str_*() functions to util.c
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
87 int str_compare(const void *s1, const void *s2);
35d67bd0613b Move str_*() functions to util.c
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
88
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 #endif