<depend>neon</depend>
<depend>ical</depend>
<depend>iksemel</depend>
+ <support_level>core</support_level>
***/
+
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <ne_uri.h>
#include <ne_request.h>
#include <ne_auth.h>
+#include <ne_redirect.h>
#include <iksemel.h>
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/config.h"
#include "asterisk/astobj2.h"
+#include "asterisk/uuid.h"
static void *exchangecal_load_calendar(void *data);
static void *unref_exchangecal(void *obj);
/* It is very important to use the return value of this function as a realloc could occur */
static struct ast_str *generate_exchange_uuid(struct ast_str *uid)
{
- unsigned short val[8];
- int x;
+ char buffer[AST_UUID_STR_LEN];
+ struct ast_uuid *uuid = ast_uuid_generate();
- for (x = 0; x < 8; x++) {
- val[x] = ast_random();
+ if (!uuid) {
+ return NULL;
}
- ast_str_set(&uid, 0, "%04x%04x-%04x-%04x-%04x-%04x%04x%04x", val[0], val[1], val[2], val[3], val[4], val[5], val[6], val[7]);
+
+ ast_str_set(&uid, 0, "%s", ast_uuid_to_str(uuid, buffer, AST_UUID_STR_LEN));
+
+ ast_free(uuid);
return uid;
}
static int is_valid_uuid(struct ast_str *uid)
{
- int i;
+ struct ast_uuid *uuid = ast_str_to_uuid(ast_str_buffer(uid));
- if (ast_str_strlen(uid) != 36) {
- return 0;
+ if (uuid) {
+ ast_free(uuid);
+ return 1;
}
- for (i = 0; i < ast_str_strlen(uid); i++) {
- if (i == 8 || i == 13 || i == 18 || i == 23) {
- if (ast_str_buffer(uid)[i] != '-') {
- return 0;
- }
- } else if (!((ast_str_buffer(uid)[i] > 47 && ast_str_buffer(uid)[i] < 58) || (ast_str_buffer(uid)[i] > 96 && ast_str_buffer(uid)[i] < 103))) {
- return 0;
- }
- }
-
- return 1;
+ return 0;
}
static struct ast_str *xml_encode_str(struct ast_str *dst, const char *src)
ne_add_request_header(req, "Content-type", "text/xml");
ret = ne_request_dispatch(req);
+ ne_request_destroy(req);
if (ret != NE_OK || !ast_str_strlen(response)) {
ast_log(LOG_WARNING, "Unknown response to CalDAV calendar %s, request %s to %s: %s\n", pvt->owner->name, method, pvt->url, ne_get_error(pvt->session));
return -1;
}
if (!(body = ast_str_create(512)) ||
- !(subdir = ast_str_create(32)) ||
- !(response = ast_str_create(512))) {
- ast_log(LOG_ERROR, "Could not allocate memory for request and response!\n");
+ !(subdir = ast_str_create(32))) {
+ ast_log(LOG_ERROR, "Could not allocate memory for request!\n");
goto write_cleanup;
}
ast_verb(0, "\n\n%s\n\n", ast_str_buffer(body));
ast_str_set(&subdir, 0, "/Calendar/%s.eml", ast_str_buffer(uid));
- response = exchangecal_request(event->owner->tech_pvt, "PROPPATCH", body, subdir);
+ if ((response = exchangecal_request(event->owner->tech_pvt, "PROPPATCH", body, subdir))) {
+ ret = 0;
+ }
- ret = 0;
write_cleanup:
if (uid) {
ast_free(uid);
}
pvt->session = ne_session_create(pvt->uri.scheme, pvt->uri.host, pvt->uri.port);
+ ne_redirect_register(pvt->session);
ne_set_server_auth(pvt->session, auth_credentials, pvt);
if (!strcasecmp(pvt->uri.scheme, "https")) {
ne_ssl_trust_default_ca(pvt->session);
return 0;
}
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Asterisk MS Exchange Calendar Integration",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Asterisk MS Exchange Calendar Integration",
.load = load_module,
.unload = unload_module,
+ .load_pri = AST_MODPRI_DEVSTATE_PLUGIN,
);