Browse Source

message implementation

doc_update_sequoia
vb 8 years ago
parent
commit
b45370773a
2 changed files with 245 additions and 3 deletions
  1. +172
    -1
      src/transport.c
  2. +73
    -2
      src/transport.h

+ 172
- 1
src/transport.c View File

@ -1,6 +1,5 @@
#include "pEp_internal.h"
#include <stdlib.h>
#include <memory.h>
#include <assert.h>
@ -21,3 +20,175 @@ void release_transport_system(PEP_SESSION session)
{
// nothing yet
}
pEp_identity *identity_dup(const pEp_identity *src)
{
pEp_identity *dup = new_identity(src->address, src->fpr, src->user_id, src->username);
assert(dup);
if (dup == NULL)
return NULL;
dup->address_size = strlen(dup->address);
dup->fpr_size = strlen(dup->fpr);
dup->user_id_size = strlen(dup->user_id);
dup->username_size = strlen(dup->username);
dup->comm_type = src->comm_type;
dup->lang[0] = src->lang[0];
dup->lang[1] = src->lang[1];
dup->lang[2] = 0;
dup->me = src->me;
}
identity_list *new_identity_list(const pEp_identity *ident)
{
identity_list *id_list = calloc(1, sizeof(identity_list));
assert(id_list);
if (id_list == NULL)
return NULL;
if (ident) {
id_list->ident = identity_dup(ident);
assert(id_list->ident);
if (id_list->ident == NULL) {
free(id_list);
return NULL;
}
}
return id_list;
}
void free_identity_list(identity_list *id_list)
{
if (id_list) {
free_identity_list(id_list->next);
free_identity(id_list->ident);
free(id_list);
}
}
identity_list *identity_list_add(identity_list *id_list, const pEp_identity *ident)
{
assert(id_list);
assert(ident);
if (id_list->ident == NULL) {
id_list->ident = identity_dup(ident);
assert(id_list->ident);
if (id_list->ident == NULL)
return NULL;
else
return id_list;
}
else if (id_list->next == NULL) {
id_list->next = new_identity_list(ident);
assert(id_list->next);
return id_list->next;
}
else {
return identity_list_add(id_list->next, ident);
}
}
message *new_message(
msg_direction dir,
const pEp_identity *from,
const pEp_identity *to,
const char *shortmsg
)
{
message *msg = calloc(1, sizeof(message));
assert(msg);
if (msg == NULL)
return NULL;
msg->shortmsg = strdup(shortmsg);
assert(msg->shortmsg);
if (msg->shortmsg == NULL) {
free(msg);
return NULL;
}
msg->shortmsg_size = strlen(msg->shortmsg);
msg->dir = dir;
msg->from = identity_dup(from);
assert(msg->from);
if (msg->from == NULL) {
free_message(msg);
return NULL;
}
if (dir == dir_incoming) {
msg->recv_by = identity_dup(to);
assert(msg->recv_by);
if (msg->recv_by == NULL) {
free_message(msg);
return NULL;
}
}
msg->to = new_identity_list(to);
assert(msg->to);
if (msg->to == NULL) {
free_message(msg);
return NULL;
}
return msg;
}
void free_message(message *msg)
{
free(msg->id);
free(msg->shortmsg);
free(msg->longmsg);
free(msg->longmsg_formatted);
free(msg->rawmsg);
free_identity_list(msg->to);
free_identity_list(msg->cc);
free_identity_list(msg->bcc);
free(msg->refering_id);
free_message_ref_list(msg->refered_by);
free(msg);
}
message_ref_list *new_message_ref_list(message *msg)
{
message_ref_list *msg_list = calloc(1, sizeof(message_ref_list));
assert(msg_list);
if (msg_list == NULL)
return NULL;
msg_list->msg_ref = msg;
return msg_list;
}
void free_message_ref_list(message_ref_list *msg_list)
{
if (msg_list) {
free_message_ref_list(msg_list->next);
free(msg_list);
}
}
message_ref_list *message_ref_list_add(message_ref_list *msg_list, message *msg)
{
assert(msg_list);
assert(msg);
if (msg_list->msg_ref == NULL) {
msg_list->msg_ref = msg;
return msg_list;
}
else if (msg_list->next == NULL) {
msg_list->next = new_message_ref_list(msg);
assert(msg_list->next);
return msg_list->next;
}
else {
return message_ref_list_add(msg_list->next, msg);
}
}

+ 73
- 2
src/transport.h View File

@ -1,6 +1,10 @@
#pragma once
#include "pEpEngine.h"
#include <time.h>
#include <stdlib.h>
typedef struct tm timestamp;
typedef enum _PEP_transports {
PEP_trans_auto = 0,
@ -12,8 +16,75 @@ typedef enum _PEP_transports {
typedef struct _PEP_transport_t PEP_transport_t;
typedef PEP_STATUS (*sendto_t)(PEP_SESSION session, const pEp_identity *address, const char *shortmsg, const char *longmsg, const char *longmsg_formatted);
typedef PEP_STATUS (*readnext_t)(PEP_SESSION session, pEp_identity *from, pEp_identity *reached, char **shortmsg, size_t shortmsg_size, char ** longmsg, size_t longmsg_size, char ** longmsg_formatted, size_t longmsg_formatted_size, PEP_transport_t **via);
pEp_identity *identity_dup(const pEp_identity *src);
typedef struct _identity_list {
pEp_identity *ident;
struct _identity_list *next;
} identity_list;
identity_list *new_identity_list(const pEp_identity *ident);
void free_identity_list(identity_list *id_list);
identity_list *identity_list_add(identity_list *id_list, const pEp_identity *ident);
typedef enum _msg_format {
format_plain = 0,
format_html
} msg_format;
typedef enum _msg_direction {
dir_incoming = 0,
dir_outgoing
} msg_direction;
struct _message_ref_list;
typedef struct _message {
msg_direction dir;
char * id;
size_t id_size;
char * shortmsg;
size_t shortmsg_size;
char * longmsg;
size_t longmsg_size;
char * longmsg_formatted;
size_t longmsg_formatted_size;
msg_format format;
char * rawmsg;
size_t rawmsg_size;
timestamp sent;
timestamp recv;
pEp_identity *from;
identity_list *to;
pEp_identity *recv_by;
identity_list *cc;
identity_list *bcc;
char * refering_id;
size_t refering_id_size;
struct _message *refering_msg;
struct _message_ref_list *refered_by;
} message;
typedef struct _message_ref_list {
message *msg_ref;
struct _message_ref_list *next;
} message_ref_list;
message *new_message(
msg_direction dir,
const pEp_identity *from,
const pEp_identity *to,
const char *shortmsg
);
void free_message(message *msg);
message_ref_list *new_message_ref_list(message *msg);
void free_message_ref_list(message_ref_list *msg_list);
message_ref_list *message_ref_list_add(message_ref_list *msg_list, message *msg);
typedef PEP_STATUS (*sendto_t)(PEP_SESSION session, const message *msg);
typedef PEP_STATUS (*readnext_t)(PEP_SESSION session, message **msg, PEP_transport_t **via);
struct _PEP_transport_t {
uint8_t id;


Loading…
Cancel
Save