GNUnet  0.11.x
Functions
messenger_api_contact.c File Reference

messenger api: client implementation of GNUnet MESSENGER service More...

#include "messenger_api_contact.h"
Include dependency graph for messenger_api_contact.c:

Go to the source code of this file.

Functions

struct GNUNET_MESSENGER_Contactcreate_contact (const struct GNUNET_IDENTITY_PublicKey *key)
 Creates and allocates a new contact with a given public key from an EGO. More...
 
void destroy_contact (struct GNUNET_MESSENGER_Contact *contact)
 Destroys a contact and frees its memory fully. More...
 
const char * get_contact_name (const struct GNUNET_MESSENGER_Contact *contact)
 Returns the current name of a given contact or NULL if no valid name was assigned yet. More...
 
void set_contact_name (struct GNUNET_MESSENGER_Contact *contact, const char *name)
 Changes the current name of a given contact by copying it from the parameter name. More...
 
const struct GNUNET_IDENTITY_PublicKeyget_contact_key (const struct GNUNET_MESSENGER_Contact *contact)
 Returns the public key of a given contact. More...
 
const struct GNUNET_HashCodeget_contact_id_from_key (const struct GNUNET_MESSENGER_Contact *contact)
 Returns the resulting hashcode of the public key from a given contact. More...
 

Detailed Description

messenger api: client implementation of GNUnet MESSENGER service

Author
Tobias Frisch

Definition in file messenger_api_contact.c.

Function Documentation

◆ create_contact()

struct GNUNET_MESSENGER_Contact* create_contact ( const struct GNUNET_IDENTITY_PublicKey key)

Creates and allocates a new contact with a given public key from an EGO.

Parameters
keyPublic key
Returns
New contact

Definition at line 29 of file messenger_api_contact.c.

References GNUNET_memcpy, GNUNET_new, GNUNET_MESSENGER_SrvContact::name, GNUNET_MESSENGER_Contact::name, GNUNET_MESSENGER_Contact::public_key, GNUNET_MESSENGER_SrvContact::public_key, and GNUNET_MESSENGER_SrvContact::rc.

30 {
32 
33  contact->name = NULL;
34 
35  GNUNET_memcpy(&(contact->public_key), key, sizeof(contact->public_key));
36 
37  return contact;
38 }
struct GNUNET_IDENTITY_PublicKey public_key
#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.

◆ destroy_contact()

void destroy_contact ( struct GNUNET_MESSENGER_Contact contact)

Destroys a contact and frees its memory fully.

Parameters
contactContact

Definition at line 41 of file messenger_api_contact.c.

References GNUNET_free, and GNUNET_MESSENGER_Contact::name.

42 {
43  if (contact->name)
44  GNUNET_free(contact->name);
45 
46  GNUNET_free(contact);
47 }
#define GNUNET_free(ptr)
Wrapper around free.

◆ get_contact_name()

const char* get_contact_name ( const struct GNUNET_MESSENGER_Contact contact)

Returns the current name of a given contact or NULL if no valid name was assigned yet.

Parameters
contactContact
Returns
Name of the contact or NULL

Definition at line 50 of file messenger_api_contact.c.

References GNUNET_MESSENGER_Contact::name.

51 {
52  return contact->name;
53 }

◆ set_contact_name()

void set_contact_name ( struct GNUNET_MESSENGER_Contact contact,
const char *  name 
)

Changes the current name of a given contact by copying it from the parameter name.

Parameters
contactContact
nameValid name (may not be NULL!)

Definition at line 56 of file messenger_api_contact.c.

References GNUNET_free, GNUNET_strdup, and GNUNET_MESSENGER_Contact::name.

57 {
58  if (contact->name)
59  GNUNET_free(contact->name);
60 
61  contact->name = name? GNUNET_strdup(name) : NULL;
62 }
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
const char * name
#define GNUNET_free(ptr)
Wrapper around free.

◆ get_contact_key()

const struct GNUNET_IDENTITY_PublicKey* get_contact_key ( const struct GNUNET_MESSENGER_Contact contact)

Returns the public key of a given contact.

Parameters
contactContact
Returns
Public key of the contact

Definition at line 65 of file messenger_api_contact.c.

References GNUNET_MESSENGER_Contact::public_key.

66 {
67  return &(contact->public_key);
68 }
struct GNUNET_IDENTITY_PublicKey public_key

◆ get_contact_id_from_key()

const struct GNUNET_HashCode* get_contact_id_from_key ( const struct GNUNET_MESSENGER_Contact contact)

Returns the resulting hashcode of the public key from a given contact.

Parameters
contactContact
Returns
Hash of the contacts public key

Definition at line 71 of file messenger_api_contact.c.

References GNUNET_CRYPTO_hash(), id, and GNUNET_MESSENGER_Contact::public_key.

72 {
73  static struct GNUNET_HashCode id;
74 
75  GNUNET_CRYPTO_hash (&(contact->public_key), sizeof(contact->public_key), &id);
76 
77  return &id;
78 }
struct GNUNET_IDENTITY_PublicKey public_key
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
A 512-bit hashcode.
Here is the call graph for this function: