GNUnet 0.22.2
gnunet-service-messenger_list_messages.h File Reference
#include "gnunet_common.h"
Include dependency graph for gnunet-service-messenger_list_messages.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_ListMessage
 
struct  GNUNET_MESSENGER_ListMessages
 

Functions

void init_list_messages (struct GNUNET_MESSENGER_ListMessages *messages)
 Initializes list of message hashes as empty list. More...
 
void clear_list_messages (struct GNUNET_MESSENGER_ListMessages *messages)
 Clears the list of message hashes. More...
 
void add_to_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash)
 Adds a specific hash from a message to the end of the list. More...
 
void copy_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_MESSENGER_ListMessages *origin)
 Copies all message hashes from an origin to another list. More...
 
void remove_from_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash)
 Removes the first entry with a matching hash from the list. More...
 
void load_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const char *path)
 Loads the list of message hashes from a file under a given path. More...
 
void save_list_messages (const struct GNUNET_MESSENGER_ListMessages *messages, const char *path)
 Saves the list of message hashes to a file under a given path. More...
 

Function Documentation

◆ init_list_messages()

void init_list_messages ( struct GNUNET_MESSENGER_ListMessages messages)

Initializes list of message hashes as empty list.

Parameters
[out]messagesList of hashes

Definition at line 31 of file gnunet-service-messenger_list_messages.c.

32{
33 GNUNET_assert (messages);
34
35 messages->head = NULL;
36 messages->tail = NULL;
37}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_ListMessage * head
struct GNUNET_MESSENGER_ListMessage * tail

References GNUNET_assert, GNUNET_MESSENGER_ListMessages::head, and GNUNET_MESSENGER_ListMessages::tail.

Referenced by check_member_session_completion(), cleanup_store_discourse_messages_before(), create_member_session(), create_srv_room(), init_message_state(), and switch_member_session().

Here is the caller graph for this function:

◆ clear_list_messages()

void clear_list_messages ( struct GNUNET_MESSENGER_ListMessages messages)

Clears the list of message hashes.

Parameters
[in,out]messagesList of hashes

Definition at line 41 of file gnunet-service-messenger_list_messages.c.

42{
43 GNUNET_assert (messages);
44
45 while (messages->head)
46 {
47 struct GNUNET_MESSENGER_ListMessage *element = messages->head;
48
49 GNUNET_CONTAINER_DLL_remove (messages->head, messages->tail, element);
50 GNUNET_free (element);
51 }
52
53 messages->head = NULL;
54 messages->tail = NULL;
55}
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MESSENGER_ListMessages::head, and GNUNET_MESSENGER_ListMessages::tail.

Referenced by check_member_session_completion(), cleanup_store_discourse_messages_before(), clear_message_state(), destroy_member_session(), and reset_member_session().

Here is the caller graph for this function:

◆ add_to_list_messages()

void add_to_list_messages ( struct GNUNET_MESSENGER_ListMessages messages,
const struct GNUNET_HashCode hash 
)

Adds a specific hash from a message to the end of the list.

Parameters
[in,out]messagesList of hashes
[in]hashHash of message

Definition at line 59 of file gnunet-service-messenger_list_messages.c.

61{
62 struct GNUNET_MESSENGER_ListMessage *element;
63
64 GNUNET_assert ((messages) && (hash));
65
67
68 GNUNET_memcpy (&(element->hash), hash, sizeof(struct GNUNET_HashCode));
69
70 GNUNET_CONTAINER_DLL_insert_tail (messages->head, messages->tail, element);
71}
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
A 512-bit hashcode.

References GNUNET_assert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_memcpy, GNUNET_new, GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, and GNUNET_MESSENGER_ListMessages::tail.

Referenced by callback_room_handle_message(), check_member_session_completion(), copy_list_messages(), iterate_flag_for_cleanup_discourse_message(), load_list_messages(), reset_member_session(), update_member_session_history(), and update_message_state().

Here is the caller graph for this function:

◆ copy_list_messages()

void copy_list_messages ( struct GNUNET_MESSENGER_ListMessages messages,
const struct GNUNET_MESSENGER_ListMessages origin 
)

Copies all message hashes from an origin to another list.

Parameters
[in,out]messagesDestination list of hashes
[in]originSource list of hashes

Definition at line 75 of file gnunet-service-messenger_list_messages.c.

77{
78 struct GNUNET_MESSENGER_ListMessage *element;
79
80 GNUNET_assert ((messages) && (origin));
81
82 for (element = origin->head; element; element = element->next)
83 add_to_list_messages (messages, &(element->hash));
84}
static char origin[GNUNET_DNSPARSER_MAX_NAME_LENGTH]
Current origin.
void add_to_list_messages(struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash)
Adds a specific hash from a message to the end of the list.
struct GNUNET_MESSENGER_ListMessage * next

References add_to_list_messages(), GNUNET_assert, GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessage::next, and origin.

Referenced by check_member_session_completion(), and switch_member_session().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_from_list_messages()

void remove_from_list_messages ( struct GNUNET_MESSENGER_ListMessages messages,
const struct GNUNET_HashCode hash 
)

Removes the first entry with a matching hash from the list.

Parameters
[in,out]messagesList of hashes
[in]hashHash of message

Definition at line 88 of file gnunet-service-messenger_list_messages.c.

90{
91 struct GNUNET_MESSENGER_ListMessage *element;
92
93 GNUNET_assert ((messages) && (hash));
94
95 for (element = messages->head; element; element = element->next)
96 if (0 == GNUNET_CRYPTO_hash_cmp (&(element->hash), hash))
97 {
98 GNUNET_CONTAINER_DLL_remove (messages->head, messages->tail, element);
99 GNUNET_free (element);
100 break;
101 }
102}
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
Definition: crypto_hash.c:218

References GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CRYPTO_hash_cmp(), GNUNET_free, GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, GNUNET_MESSENGER_ListMessage::next, and GNUNET_MESSENGER_ListMessages::tail.

Referenced by update_message_state().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_list_messages()

void load_list_messages ( struct GNUNET_MESSENGER_ListMessages messages,
const char *  path 
)

Loads the list of message hashes from a file under a given path.

Parameters
[out]messagesList of hashes
[in]pathPath of file

Definition at line 106 of file gnunet-service-messenger_list_messages.c.

108{
110 struct GNUNET_HashCode hash;
111 ssize_t len;
112
113 GNUNET_assert ((messages) && (path));
114
115 if (GNUNET_YES != GNUNET_DISK_file_test (path))
116 return;
117
118 {
119 enum GNUNET_DISK_AccessPermissions permission;
120
122
124 }
125
126 if (! handle)
127 return;
128
130
131 do {
132 len = GNUNET_DISK_file_read (handle, &hash, sizeof(hash));
133
134 if (len != sizeof(hash))
135 break;
136
137 add_to_list_messages (messages, &hash);
138 } while (len == sizeof(hash));
139
141}
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1215
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:506
off_t GNUNET_DISK_file_seek(const struct GNUNET_DISK_FileHandle *h, off_t offset, enum GNUNET_DISK_Seek whence)
Move the read/write pointer in a file.
Definition: disk.c:206
GNUNET_DISK_AccessPermissions
File access permissions, UNIX-style.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1289
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:646
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
@ GNUNET_DISK_SEEK_SET
Seek an absolute position (from the start of the file).
@ GNUNET_YES
Handle used to access files (and pipes).

References add_to_list_messages(), GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_file_seek(), GNUNET_DISK_file_test(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_DISK_SEEK_SET, GNUNET_YES, and handle.

Referenced by load_member_session(), and load_message_state().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_list_messages()

void save_list_messages ( const struct GNUNET_MESSENGER_ListMessages messages,
const char *  path 
)

Saves the list of message hashes to a file under a given path.

Parameters
[in]messagesList of hashes
[in]pathPath of file

Definition at line 145 of file gnunet-service-messenger_list_messages.c.

147{
149
150 GNUNET_assert ((messages) && (path));
151
152 {
153 enum GNUNET_DISK_AccessPermissions permission;
154
156
159 }
160
161 if (! handle)
162 return;
163
165
166 {
167 struct GNUNET_MESSENGER_ListMessage *element;
168
169 for (element = messages->head; element; element = element->next)
170 GNUNET_DISK_file_write (handle, &(element->hash), sizeof(element->hash));
171 }
172
175}
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:682
enum GNUNET_GenericReturnValue GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h)
Write file changes to disk.
Definition: disk.c:1408
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.

References GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_seek(), GNUNET_DISK_file_sync(), GNUNET_DISK_file_write(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_DISK_SEEK_SET, handle, GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, and GNUNET_MESSENGER_ListMessage::next.

Referenced by save_member_session(), and save_message_state().

Here is the call graph for this function:
Here is the caller graph for this function: