91 static void srds_destroy_cb(
void *data)
100 .destroy = srds_destroy_cb,
110 if (!(srds =
ast_calloc(1,
sizeof(*srds) + strlen(service)))) {
117 ast_log(LOG_NOTICE,
"Error performing lookup of service '%s'\n", service);
123 strcpy(srds->id, service);
125 if (!(datastore = ast_datastore_alloc(&srv_result_datastore_info, srds->id))) {
131 datastore->
data = srds;
132 ast_channel_lock(chan);
134 ast_channel_unlock(chan);
135 return srds->context;
138 static int srv_query_read(
struct ast_channel *chan,
const char *cmd,
char *
data,
char *buf,
size_t len)
143 ast_log(LOG_WARNING,
"%s cannot be used without a channel\n", cmd);
147 if (ast_strlen_zero(data)) {
148 ast_log(LOG_WARNING,
"%s requires a service as an argument\n", cmd);
155 ast_channel_lock(chan);
157 ast_channel_unlock(chan);
164 if (!srv_datastore_setup(data, chan)) {
175 .read = srv_query_read,
178 static int srv_result_read(
struct ast_channel *chan,
const char *cmd,
char *data,
char *buf,
size_t len)
185 unsigned short port, priority, weight;
194 ast_log(LOG_WARNING,
"%s cannot be used without a channel\n", cmd);
198 if (ast_strlen_zero(data)) {
199 ast_log(LOG_WARNING,
"%s requires two arguments (id and resultnum)\n", cmd);
207 ast_channel_lock(chan);
209 ast_channel_unlock(chan);
215 srv_context = srv_datastore_setup(args.id, chan);
220 srds = datastore->
data;
221 srv_context = srds->context;
224 if (!strcasecmp(args.resultnum,
"getnum")) {
229 if (ast_strlen_zero(args.field)) {
230 ast_log(LOG_ERROR,
"A field must be provided when requesting SRV data\n");
234 if (sscanf(args.resultnum,
"%30u", &num) != 1) {
235 ast_log(LOG_ERROR,
"Invalid value '%s' for resultnum to %s\n", args.resultnum, cmd);
240 ast_log(LOG_ERROR,
"Failed to get record number %u for %s\n", num, cmd);
244 if (!strcasecmp(args.field,
"host")) {
246 }
else if (!strcasecmp(args.field,
"port")) {
247 snprintf(buf, len,
"%d", port);
248 }
else if (!strcasecmp(args.field,
"priority")) {
249 snprintf(buf, len,
"%d", priority);
250 }
else if (!strcasecmp(args.field,
"weight")) {
251 snprintf(buf, len,
"%d", weight);
253 ast_log(LOG_WARNING,
"Unrecognized SRV field '%s'\n", args.field);
262 .read = srv_result_read,
265 static int unload_module(
void)
275 static int load_module(
void)
289 AST_MODULE_INFO_STANDARD(
ASTERISK_GPL_KEY,
"SRV related dialplan functions");
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
Support for DNS SRV records, used in to locate SIP services.
void ast_srv_cleanup(struct srv_context **context)
Cleanup resources associated with ast_srv_lookup.
Structure for a data store type.
Structure for a data store object.
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Asterisk datastore objects.
int ast_srv_get_nth_record(struct srv_context *context, int record_num, const char **host, unsigned short *port, unsigned short *priority, unsigned short *weight)
Retrieve details from a specific SRV record.
General Asterisk PBX channel definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Data structure associated with a custom dialplan function.
Core PBX routines and definitions.
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
#define ast_calloc(num, len)
A wrapper for calloc()
unsigned int ast_srv_get_record_count(struct srv_context *context)
Get the number of records for a given SRV context.
Module has failed to load, may be in an inconsistent state.
int ast_srv_lookup(struct srv_context **context, const char *service, const char **host, unsigned short *port)
Retrieve set of SRV lookups, in order.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
#define ast_custom_function_register(acf)
Register a custom function.
#define AST_APP_ARG(name)
Define an application argument.