File: ucontact.h

package info (click to toggle)
openser 1.1.0-9etch1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 9,828 kB
  • ctags: 11,809
  • sloc: ansic: 120,528; sh: 5,249; yacc: 1,716; makefile: 1,261; php: 656; perl: 205; sql: 190
file content (203 lines) | stat: -rw-r--r-- 5,638 bytes parent folder | download
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* 
 * $Id: ucontact.h,v 1.9 2006/05/19 11:58:11 bogdan_iancu Exp $ 
 *
 * Usrloc contact structure
 *
 * 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
 *
 * History:
 * ---------
 * 2003-03-12 added replication mark and three zombie states (nils)
 * 2005-07-11 added FL_NAT_SIPPING for nat pinging with SIP method
 *             instead of UDP package (bogdan)
 */


#ifndef UCONTACT_H
#define UCONTACT_H


#include <stdio.h>
#include <time.h>
#include "../../qvalue.h"
#include "../../str.h"



typedef enum cstate {
	CS_NEW,        /* New contact - not flushed yet */
	CS_SYNC,       /* Synchronized contact with the database */
	CS_DIRTY       /* Update contact - not flushed yet */
} cstate_t;


/*
 * Flags that can be associated with a Contact
 */
typedef enum flags {
	FL_NONE        = 0,          /* No flags set */
	FL_NAT         = 1 << 0,     /* Contact is behind NAT */
	FL_INVITE      = 1 << 1,     /* Contact supports INVITE and related methods */
	FL_N_INVITE    = 1 << 2,     /* Contact doesn't support INVITE and related methods */
	FL_MESSAGE     = 1 << 3,     /* Contact supports MESSAGE */
	FL_N_MESSAGE   = 1 << 4,     /* Contact doesn't support MESSAGE */
	FL_SUBSCRIBE   = 1 << 5,     /* Contact supports SUBSCRIBE and NOTIFY */
	FL_N_SUBSCRIBE = 1 << 6,     /* Contact doesn't support SUBSCRIBE and NOTIFY */
	FL_PERMANENT   = 1 << 7,     /* Permanent contact (does not expire) */
	FL_MEM         = 1 << 8,     /* Update memory only -- used for REGISTER replication */
	FL_NAT_SIPPING = 1 << 9,     /* Use SIP ping if nated */
	FL_ALL         = 0xFFFFFFFF  /* All flags set */
} flags_t;


typedef struct ucontact {
	str* domain;            /* Pointer to domain name (NULL terminated) */
	str* aor;               /* Pointer to the AOR string in record structure*/
	str c;                  /* Contact address */
	str received;           /* IP+port+protocol we recved the REGISTER from */
	str path;               /* Path header */
	time_t expires;         /* expires parameter */
	qvalue_t q;             /* q parameter */
	str callid;             /* Call-ID header field */
	int cseq;               /* CSeq value */
	cstate_t state;         /* State of the contact */
	unsigned int flags;     /* Various flags (NAT, supported methods etc) */
	str user_agent;         /* User-Agent header field */
	struct socket_info *sock; /* received soket */
	time_t last_modified;   /* when the record was last modified */
	unsigned int methods;   /* Supported methods */
	struct ucontact* next;  /* Next contact in the linked list */
	struct ucontact* prev;  /* Previous contact in the linked list */
} ucontact_t;

typedef struct ucontact_info {
	str received;
	str* path;
	time_t expires;
	qvalue_t q;
	str* callid;
	int cseq;
	unsigned int flags1;
	unsigned int flags2;
	str *user_agent;
	struct socket_info *sock;
	unsigned int methods;
	time_t last_modified;
} ucontact_info_t;

/*
 * Valid contact is a contact that either didn't expire yet or is permanent
 */
#define VALID_CONTACT(c, t) \
	(((c->expires > t) || (c->flags & FL_PERMANENT)))


/*
 * Create a new contact structure
 */
ucontact_t* new_ucontact(str* _dom, str* _aor, str* _contact,
		ucontact_info_t* _ci);


/*
 * Free all memory associated with given contact structure
 */
void free_ucontact(ucontact_t* _c);


/*
 * Print contact, for debugging purposes only
 */
void print_ucontact(FILE* _f, ucontact_t* _c);


/*
 * Update existing contact in memory with new values
 */
int mem_update_ucontact(ucontact_t* _c, ucontact_info_t *_ci);


/* ===== State transition functions - for write back cache scheme ======== */


/*
 * Update state of the contact if we
 * are using write-back scheme
 */
void st_update_ucontact(ucontact_t* _c);


/*
 * Update state of the contact if we
 * are using write-back scheme
 * Returns 1 if the contact should be
 * deleted from memory immediately,
 * 0 otherwise
 */
int st_delete_ucontact(ucontact_t* _c);


/*
 * Called when the timer is about to delete
 * an expired contact, this routine returns
 * 1 if the contact should be removed from
 * the database and 0 otherwise
 */
int st_expired_ucontact(ucontact_t* _c);


/*
 * Called when the timer is about flushing the contact,
 * updates contact state and returns 1 if the contact
 * should be inserted, 2 if updated and 0 otherwise
 */
int st_flush_ucontact(ucontact_t* _c);


/* ==== Database related functions ====== */


/*
 * Insert contact into the database
 */
int db_insert_ucontact(ucontact_t* _c);


/*
 * Update contact in the database
 */
int db_update_ucontact(ucontact_t* _c);


/*
 * Delete contact from the database
 */
int db_delete_ucontact(ucontact_t* _c);


/* ====== Module interface ====== */


/*
 * Update ucontact with new values
 */
typedef int (*update_ucontact_t)(ucontact_t* _c, ucontact_info_t* _ci);
int update_ucontact(ucontact_t* _c, ucontact_info_t* _ci);

#endif /* UCONTACT_H */