1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
/*
* $Id: lpidf.c,v 1.2 2005/12/08 10:58:55 bogdan_iancu Exp $
*
* Presence Agent, LPIDF document support
*
* Copyright (C) 2001-2003 FhG Fokus
*
* This file is part of openser, a free SIP server.
*
* openser is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* openser is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <string.h>
#include "lpidf.h"
#include "common.h"
#include "paerrno.h"
#include "../../dprint.h"
#define TO_START "To: <"
#define TO_START_L (sizeof(TO_START) - 1)
#define TO_END ">"
#define TO_END_L (sizeof(TO_END) - 1)
#define CONTACT_START "Contact: <"
#define CONTACT_START_L (sizeof(CONTACT_START) - 1)
#define CONTACT_MIDDLE ">;q="
#define CONTACT_MIDDLE_L (sizeof(CONTACT_MIDDLE) - 1)
#define Q_OPEN "1"
#define Q_OPEN_L (sizeof(Q_OPEN) - 1)
#define Q_CLOSED "0"
#define Q_CLOSED_L (sizeof(Q_CLOSED) - 1)
#define CRLF "\r\n"
#define CRLF_L (sizeof(CRLF) - 1)
/*
* Add a presentity information
*/
int lpidf_add_presentity(str* _b, int _l, str* _uri)
{
if (_l < (TO_START_L + _uri->len + TO_END_L + CRLF_L)) {
paerrno = PA_SMALL_BUFFER;
LOG(L_ERR, "lpidf_add_presentity(): Buffer too small\n");
return -1;
}
str_append(_b, TO_START, TO_START_L);
str_append(_b, _uri->s, _uri->len);
str_append(_b, TO_END CRLF, TO_END_L + CRLF_L);
return 0;
}
/*
* Add a contact address with given status
*/
int lpidf_add_address(str* _b, int _l, str* _addr, lpidf_status_t _st)
{
str s;
switch(_st) {
case LPIDF_ST_OPEN: s.s = Q_OPEN; s.len = Q_OPEN_L; break;
case LPIDF_ST_CLOSED: s.s = Q_CLOSED; s.len = Q_CLOSED_L; break;
default: return -1;
}
if (_l < (CONTACT_START_L + _addr->len + CONTACT_MIDDLE_L + s.len + 2)) {
paerrno = PA_SMALL_BUFFER;
LOG(L_ERR, "lpidf_add_address(): Buffer too small\n");
return -1;
}
str_append(_b, CONTACT_START, CONTACT_START_L);
str_append(_b, _addr->s, _addr->len);
str_append(_b, CONTACT_MIDDLE, CONTACT_MIDDLE_L);
str_append(_b, s.s, s.len);
str_append(_b, CRLF, CRLF_L);
return 0;
}
|