#include "config.h"
#include <sofia-sip/sip.h>
#include <sofia-sip/sip_header.h>
#include <sofia-sip/sip_util.h>
#include <sofia-sip/sip_status.h>
#include <sofia-sip/su_tagarg.h>
#include "nea_debug.h"
#include <sofia-sip/nea.h>
#include <sofia-sip/htable.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>
#include <limits.h>
Include dependency graph for nea_server.c:
Data Structures | |
struct | nea_server_s |
Server object, created for every notifier. More... | |
struct | nea_event_s |
Supported events and their subscribers. More... | |
struct | nea_event_view_s |
Object representing particular view of event. More... | |
struct | nea_event_view_s::nea_event_queue_s |
Queued notification. More... | |
struct | nea_sub_s |
Subscription object. More... | |
Defines | |
#define | NEA_VIEW_MAX |
Number of primary views (with different MIME type or content). | |
Functions | |
nea_server_t * | nea_server_create (nta_agent_t *agent, su_root_t *root, url_t const *url, int max_subs, nea_new_event_f *callback, nea_smagic_t *context, tag_type_t tag, tag_value_t value,...) |
Create a notifier server. | |
int | nea_server_shutdown (nea_server_t *nes, int retry_after) |
Shutdown an event server. | |
void | nea_server_destroy (nea_server_t *nes) |
Destroy a server. | |
int | nea_server_update (nea_server_t *nes, nea_event_t *ev, tag_type_t tag, tag_value_t value,...) |
Update event information. | |
nea_event_view_t * | nea_view_create (nea_server_t *nes, nea_event_t *ev, nea_evmagic_t *magic, tag_type_t tag, tag_value_t value,...) |
Create a private event view. | |
void | nea_view_destroy (nea_server_t *nes, nea_event_view_t *evv) |
Destroy a private event view. | |
nea_event_view_t * | nea_event_view (nea_event_t *ev, char const *content_type) |
Get primary event view for given content type. | |
sip_content_type_t const * | nea_view_content_type (nea_event_view_t const *evv) |
Get a content type for event's payload. | |
int | nea_server_notify (nea_server_t *nes, nea_event_t *ev) |
Notify subscribers. | |
void | nea_server_flush (nea_server_t *nes, nea_event_t *event) |
Zap terminated subscribtions. | |
nta_incoming_t * | nea_subnode_get_incoming (nea_subnode_t *sn) |
Get nta_incoming_t from sn->sn_subscriber. | |
nea_event_t * | nea_event_create (nea_server_t *nes, nea_watcher_f *callback, nea_emagic_t *context, char const *name, char const *subname, char const *default_content_type, char const *accept) |
Create a new event (or subevent). | |
nea_event_t * | nea_event_tcreate (nea_server_t *nes, nea_watcher_f *callback, nea_emagic_t *context, char const *name, char const *subname, tag_type_t tag, tag_value_t value,...) |
Create a new event (or subevent) with tags. | |
nea_emagic_t * | nea_emagic_get (nea_event_t *ev) |
Return magic context bind to nea_event. | |
nea_event_t * | nea_event_get (nea_server_t const *nes, char const *e) |
Find a nea event object with given event name. | |
nta_incoming_t * | nea_sub_get_request (nea_sub_t *sub) |
Get nta_incoming_t from nea_sub_t. | |
int | nea_server_add_irq (nea_server_t *nes, nta_leg_t *leg, sip_contact_t const *local_target, nta_incoming_t *irq, sip_t const *sip) |
Add a new subscriber from subscribe transaction to an existing notifier. | |
int | nea_server_active (nea_server_t *nes, nea_event_t const *ev) |
Get number of active subscribers. | |
int | nea_server_non_embryonic (nea_server_t *nes, nea_event_t const *ev) |
Get number of (non-embryonic) subscribers. | |
int | nea_sub_version (nea_sub_t *s, unsigned version) |
Set subscriber version sequence. | |
int | nea_sub_auth (nea_sub_t *s, nea_state_t state, tag_type_t tag, tag_value_t value,...) |
Authorize a subscription. | |
nea_subnode_t const ** | nea_server_get_subscribers (nea_server_t *nes, nea_event_t const *ev) |
Obtain a list of subscriptions. | |
void | nea_server_free_subscribers (nea_server_t *nes, nea_subnode_t const **sn_list) |
Free a list of subscriptions. |
nea_emagic_t* nea_emagic_get | ( | nea_event_t * | ev | ) |
Return magic context bind to nea_event.
The function returns the magic context bound to the event.
ev | pointer to event object |
nea_event_t* nea_event_create | ( | nea_server_t * | nes, | |
nea_watcher_f * | callback, | |||
nea_emagic_t * | context, | |||
char const * | name, | |||
char const * | subname, | |||
char const * | default_content_type, | |||
char const * | accept | |||
) |
Create a new event (or subevent).
The function nea_event_create() creates a new event for the event server.
int nea_server_active | ( | nea_server_t * | nes, | |
nea_event_t const * | ev | |||
) |
Get number of active subscribers.
The function nea_server_active() counts the number of active subscribers watching the specified view. If the view is not specified (ev is NULL
), it counts the number of all subscribers.
nes | notifier | |
ev | event |
nea_server_t* nea_server_create | ( | nta_agent_t * | agent, | |
su_root_t * | root, | |||
url_t const * | url, | |||
int | max_subs, | |||
nea_new_event_f * | callback, | |||
nea_smagic_t * | context, | |||
tag_type_t | tag, | |||
tag_value_t | value, | |||
... | ||||
) |
Create a notifier server.
The function nea_server_create() initializes an event server object and registers it with nta. An event server object takes care of all events for a particular URI (eventity).
agent | pointer to an nta agent object | |
root | pointer to an root object | |
url | url of the server to be created | |
max_subs | maximum number of subscriptions | |
callback | authorization function, or NULL if no authorization is required | |
context | server context (pointer to application data) | |
tag,value,... | optional list of tag parameters |
The default throttle value is used if the subscriber does not include a throttle parameter in Event header of SUBSCRIBE request.
NULL
upon an error. void nea_server_flush | ( | nea_server_t * | nes, | |
nea_event_t * | event | |||
) |
Zap terminated subscribtions.
On first flush, mark as garbage, remove on second flush
int nea_server_non_embryonic | ( | nea_server_t * | nes, | |
nea_event_t const * | ev | |||
) |
Get number of (non-embryonic) subscribers.
The function nea_server_non_embryonic() counts the number of pending, active or terminated subscribers watching the specified view. If the view is not specified (ev is NULL
), it counts the number of all subscribers.
nes | notifier | |
ev | event view |
int nea_server_notify | ( | nea_server_t * | nes, | |
nea_event_t * | ev | |||
) |
Notify subscribers.
int nea_server_update | ( | nea_server_t * | nes, | |
nea_event_t * | ev, | |||
tag_type_t | tag, | |||
tag_value_t | value, | |||
... | ||||
) |
Update event information.
A nea event server has typed content that is delivered to the subscribers. Different content types are each assigned a separate primary view. There can be also primary views with "fake" content, content delivered to politely blocked subscribers.
In addition to primary views, there can be secondary views, views assigned to a single subscriber only.
The default throttle value is used if the subscriber does not include a throttle parameter in Event header of SUBSCRIBE request.
-1 | upon an error. | |
0 | if event document was not updated. | |
1 | if event document was updated. |
int nea_sub_auth | ( | nea_sub_t * | s, | |
nea_state_t | state, | |||
tag_type_t | tag, | |||
tag_value_t | value, | |||
... | ||||
) |
Authorize a subscription.
Application can modify the subscription state and authorize the user. The subscription state has following simple state diagram:
+---------------+ +------------------+ | | | | +-----------+ | +---------+ V | +------------+ V +------------+ | embryonic |-+->| pending |--+-+->| authorized |--+->| terminated | +-----------+ +---------+ +------------+ +------------+
0 | if successful | |
-1 | upon an error |