Code

Renamed the project to SysDB (System DataBase).
[sysdb.git] / src / include / utils / unixsock.h
1 /*
2  * SysDB - src/include/utils/unixsock.h
3  * Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
28 #ifndef SDB_UTILS_UNIXSOCK_H
29 #define SDB_UTILS_UNIXSOCK_H 1
31 #include "core/object.h"
32 #include "utils/data.h"
34 #include <sys/socket.h>
36 #include <stddef.h>
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
42 struct sdb_unixsock_client;
43 typedef struct sdb_unixsock_client sdb_unixsock_client_t;
45 typedef int (*sdb_unixsock_client_data_cb)(sdb_unixsock_client_t *,
46                 size_t, sdb_data_t *, sdb_object_t *);
48 sdb_unixsock_client_t *
49 sdb_unixsock_client_create(const char *path);
51 int
52 sdb_unixsock_client_connect(sdb_unixsock_client_t *client);
54 int
55 sdb_unixsock_client_send(sdb_unixsock_client_t *client,
56                 const char *msg);
58 char *
59 sdb_unixsock_client_recv(sdb_unixsock_client_t *client,
60                 char *buffer, size_t buflen);
62 /*
63  * sdb_unixsock_client_process_lines:
64  * Reads up to 'max_lines' lines from the socket, splits each line at the
65  * specified 'delim' and passes the data on to the specified 'callback'. If
66  * 'max_lines' is less than zero, the function will read until EOF or an error
67  * is encountered. If 'n_cols' is greater than zero, the function will expect
68  * that number of columns to appear in each line. Also, it will expect that
69  * number of further arguments, specifying the data-type to be returned for
70  * the respective column (see sdb_data_t). The content of each column will
71  * then be converted accordingly.
72  *
73  * Returns:
74  *  - 0 on success
75  *  - a negative value else
76  */
77 int
78 sdb_unixsock_client_process_lines(sdb_unixsock_client_t *client,
79                 sdb_unixsock_client_data_cb callback, sdb_object_t *user_data,
80                 long int max_lines, const char *delim, int n_cols, ...);
82 /*
83  * sdb_unixsock_client_shutdown:
84  * Shut down the client's send and/or receive operations. If appropriate, the
85  * client will automatically re-connect on the next send / receive operation
86  * after that.
87  *
88  * See shutdown(3) for details.
89  */
90 int
91 sdb_unixsock_client_shutdown(sdb_unixsock_client_t *client, int how);
93 /*
94  * sdb_unixsock_client_clearerr, sdb_unixsock_client_eof,
95  * sdb_unixsock_client_error:
96  * Check and reset the client status. See the clearerr(3), feof(3), and
97  * ferror(3) manpages for details.
98  */
99 void
100 sdb_unixsock_client_clearerr(sdb_unixsock_client_t *client);
101 int
102 sdb_unixsock_client_eof(sdb_unixsock_client_t *client);
103 int
104 sdb_unixsock_client_error(sdb_unixsock_client_t *client);
106 void
107 sdb_unixsock_client_destroy(sdb_unixsock_client_t *client);
109 const char *
110 sdb_unixsock_client_path(sdb_unixsock_client_t *client);
112 #ifdef __cplusplus
113 } /* extern "C" */
114 #endif
116 #endif /* ! SDB_UTILS_UNIXSOCK_H */
118 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */