Browse Source

message api

async_key_management
vb 8 years ago
parent
commit
563f78d763
9 changed files with 203 additions and 45 deletions
  1. +1
    -1
      Makefile
  2. +2
    -2
      Makefile.conf
  3. +2
    -0
      README.txt
  4. +106
    -0
      src/message_api.c
  5. +23
    -0
      src/message_api.h
  6. +18
    -0
      src/pEpEngine.c
  7. +15
    -0
      src/pEpEngine.h
  8. +30
    -39
      src/transport.c
  9. +6
    -3
      src/transport.h

+ 1
- 1
Makefile View File

@ -19,7 +19,7 @@ test: all
$(MAKE) -C test test
package: clean
cd .. ; COPYFILE_DISABLE=true tar cjf pEpEngine.tar.bz2 pEpEngine
cd .. ; COPYFILE_DISABLE=true tar cjf pEpEngine.tar.bz2 pEpEngine
windist:
ifneq ($(BUILD_FOR),Windoze)


+ 2
- 2
Makefile.conf View File

@ -1,7 +1,7 @@
BUILD_ON=$(shell uname)
BUILD_FOR=$(BUILD_ON)
OPTIMIZE=-g -O0
#OPTIMIZE=-O3 -DNDEBUG
#OPTIMIZE=-g -O0
OPTIMIZE=-O3 -DNDEBUG
# the next two lines are ignored on Windoze
SYSTEM_DB=/usr/local/share/pEp/system.db
PREFIX=$(HOME)

+ 2
- 0
README.txt View File

@ -7,6 +7,8 @@ pEp Engine
The pEp Engine encapsulates all real functionality of pEp.
It has an old style Makefile for building it.
The build is configured in Makefile.conf
It supports the common targets
$ make all


+ 106
- 0
src/message_api.c View File

@ -0,0 +1,106 @@
#include "message_api.h"
#include "keymanagement.h"
#include <libetpan/libetpan.h>
#include <assert.h>
#include <string.h>
PEP_STATUS encrypt_message(
PEP_SESSION session,
const message *src,
stringlist_t * extra,
message **dst
)
{
PEP_STATUS status = PEP_STATUS_OK;
assert(session);
assert(src);
assert(dst);
*dst = NULL;
message *msg = new_message(src->dir, src->from, src->to, NULL);
if (msg == NULL)
return PEP_OUT_OF_MEMORY;
src->from->me = true;
status = myself(session, src->from);
if (status != PEP_STATUS_OK) {
free_message(msg);
return status;
}
stringlist_t * keys = new_stringlist(src->from->fpr);
if (keys == NULL) {
free_message(msg);
return PEP_OUT_OF_MEMORY;
}
stringlist_t *_x;
for (_x = extra; _x && _x->value; _x = _x->next) {
if (stringlist_add(keys, _x->value) == NULL) {
free_message(msg);
free_stringlist(keys);
return PEP_OUT_OF_MEMORY;
}
}
identity_list * _il;
for (_il = src->to; _il && _il->ident; _il = _il->next) {
status = update_identity(session, _il->ident);
if (status != PEP_STATUS_OK) {
free_message(msg);
free_stringlist(keys);
return status;
}
if (_il->ident->fpr) {
if (stringlist_add(keys, _il->ident->fpr) == NULL) {
free_message(msg);
free_stringlist(keys);
return PEP_OUT_OF_MEMORY;
}
}
else
status = PEP_KEY_NOT_FOUND;
}
int _own_keys = 1;
if (extra)
_own_keys += stringlist_length(extra);
if (stringlist_length(keys) > _own_keys) {
char *ptext = NULL;
char *ctext = NULL;
size_t csize = 0;
// TODO: set ptext to MIME text
status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext, &csize);
if (ctext) {
msg->longmsg = ctext;
msg->longmsg_size = csize;
*dst = msg;
}
else
free_message(msg);
free(ptext);
}
else
free_message(msg);
free_stringlist(keys);
return status;
}
PEP_STATUS decrypt_message(
PEP_SESSION session,
const message *src,
message **dst
)
{
PEP_STATUS status = PEP_STATUS_OK;
return status;
}

+ 23
- 0
src/message_api.h View File

@ -0,0 +1,23 @@
#ifdef __cplusplus
extern "C" {
#endif
#include "transport.h"
PEP_STATUS encrypt_message(
PEP_SESSION session,
const message *src,
stringlist_t *extra,
message **dst
);
PEP_STATUS decrypt_message(
PEP_SESSION session,
const message *src,
message **dst
);
#ifdef __cplusplus
}
#endif

+ 18
- 0
src/pEpEngine.c View File

@ -534,6 +534,24 @@ pEp_identity *new_identity(
return result;
}
pEp_identity *identity_dup(const pEp_identity *src)
{
assert(src);
pEp_identity *dup = new_identity(src->address, src->fpr, src->user_id, src->username);
assert(dup);
if (dup == NULL)
return NULL;
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;
return dup;
}
void free_identity(pEp_identity *identity)
{
if (identity) {


+ 15
- 0
src/pEpEngine.h View File

@ -415,6 +415,21 @@ DYNAMIC_API pEp_identity *new_identity(
);
// identity_dup() - allocate memory and set the string and size fields
//
// parameters:
// src (in) identity to duplicate
//
// return value:
// pEp_identity struct with correct size values or NULL if out of memory
//
// caveat:
// the strings are copied; the original strings are still being owned by
// the caller
DYNAMIC_API pEp_identity *identity_dup(const pEp_identity *src);
// free_identity() - free all memory being occupied by a pEp_identity struct
//
// parameters:


+ 30
- 39
src/transport.c View File

@ -24,28 +24,6 @@ void release_transport_system(PEP_SESSION session)
// nothing yet
}
pEp_identity *identity_dup(const pEp_identity *src)
{
assert(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;
return dup;
}
identity_list *new_identity_list(const pEp_identity *ident)
{
identity_list *id_list = calloc(1, sizeof(identity_list));
@ -65,6 +43,26 @@ identity_list *new_identity_list(const pEp_identity *ident)
return id_list;
}
identity_list *identity_list_dup(const identity_list *src)
{
assert(src);
identity_list *id_list = new_identity_list(src->ident);
assert(id_list);
if (id_list == NULL)
return NULL;
if (src->next) {
id_list->next = identity_list_dup(src->next);
if (id_list->next == NULL) {
free_identity_list(id_list);
return NULL;
}
}
return id_list;
}
void free_identity_list(identity_list *id_list)
{
if (id_list) {
@ -100,7 +98,7 @@ identity_list *identity_list_add(identity_list *id_list, const pEp_identity *ide
message *new_message(
msg_direction dir,
const pEp_identity *from,
const pEp_identity *to,
const identity_list *to,
const char *shortmsg
)
{
@ -109,13 +107,15 @@ message *new_message(
if (msg == NULL)
return NULL;
msg->shortmsg = strdup(shortmsg);
assert(msg->shortmsg);
if (msg->shortmsg == NULL) {
free(msg);
return NULL;
if (msg->shortmsg) {
msg->shortmsg = strdup(shortmsg);
assert(msg->shortmsg);
if (msg->shortmsg == NULL) {
free(msg);
return NULL;
}
msg->shortmsg_size = strlen(msg->shortmsg);
}
msg->shortmsg_size = strlen(msg->shortmsg);
msg->dir = dir;
@ -126,16 +126,7 @@ message *new_message(
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);
msg->to = identity_list_dup(to);
assert(msg->to);
if (msg->to == NULL) {
free_message(msg);


+ 6
- 3
src/transport.h View File

@ -4,9 +4,12 @@
#include <time.h>
#include <stdlib.h>
// all functions are using POSIX struct tm
typedef struct tm timestamp;
typedef enum _PEP_transports {
// auto transport chooses transport per message automatically
PEP_trans_auto = 0,
// PEP_trans_email,
// PEP_trans_whatsapp,
@ -16,14 +19,13 @@ typedef enum _PEP_transports {
typedef struct _PEP_transport_t PEP_transport_t;
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);
identity_list *identity_list_dup(const identity_list *src);
void free_identity_list(identity_list *id_list);
identity_list *identity_list_add(identity_list *id_list, const pEp_identity *ident);
@ -73,7 +75,7 @@ typedef struct _message_ref_list {
message *new_message(
msg_direction dir,
const pEp_identity *from,
const pEp_identity *to,
const identity_list *to,
const char *shortmsg
);
@ -98,3 +100,4 @@ typedef uint64_t transports_mask;
PEP_STATUS init_transport_system(PEP_SESSION session);
void release_transport_system(PEP_SESSION session);

Loading…
Cancel
Save