Asterisk Ver0-2-0/Chan Sip
AsteriskVer0-2-0/channels/chan_sip.c ¶* asterisk-0.2.0
* you need a username and password which will allow you to call someone who is registered.
* To receive a call, you must be a registered user and have an extension.
* SIP Address of Record (AOR). This is the address people use to call you, the format looks like an email address.
* SIP Contact Address is the temporary address and is determined by what IP address you currently have, the device name, and the port number you are using for SIP. This address is usually temporary and stored in memory. When you register with a SIP server, the server maps this address onto your SIP Address of Record (AOR).
* load_module -> restart_monitor
* restart_monitor -> pthread_create(&monitor_thread, NULL, do_monitor, NULL)
* do_monitor(NULL)
struct sched_context { /* Number of events processed */ int eventcnt; /* Number of outstanding schedule events */ int schedcnt; /* Schedule entry and main queue */ struct sched *schedq; #ifdef SCHED_MAX_CACHE /* Cache of unused schedule structures and how many */ struct sched *schedc; int schedccnt; #endif }; struct sched_context *sched_context_create(void) { struct sched_context *tmp; tmp = malloc(sizeof(struct sched_context)); if (tmp) { tmp->eventcnt = 1; tmp->schedcnt = 0; tmp->schedq = NULL; #ifdef SCHED_MAX_CACHE tmp->schedc = NULL; tmp->schedccnt = 0; #endif } return tmp; }
struct io_context { /* Poll structure */ struct pollfd *fds; /* Associated I/O records */ struct io_rec *ior; /* First available fd */ unsigned int fdcnt; /* Maximum available fd */ unsigned int maxfdcnt; /* Currently used io callback */ int current_ioc; /* Whether something has been deleted */ int needshrink; }; struct io_context *io_context_create(void) { /* Create an I/O context */ struct io_context *tmp; tmp = malloc(sizeof(struct io_context)); if (tmp) { tmp->needshrink = 0; tmp->fdcnt = 0; tmp->maxfdcnt = GROW_SHRINK_SIZE/2; tmp->current_ioc = -1; tmp->fds = malloc((GROW_SHRINK_SIZE/2) * sizeof(struct pollfd)); if (!tmp->fds) { free(tmp); tmp = NULL; } else { tmp->ior = malloc((GROW_SHRINK_SIZE/2) * sizeof(struct io_rec)); if (!tmp->ior) { free(tmp->fds); free(tmp); tmp = NULL; } } } return tmp; }
int *ast_io_add(struct io_context *ioc, int fd, ast_io_cb callback, short events, void *data) { /* * Add a new I/O entry for this file descriptor * with the given event mask, to call callback with * data as an argument. Returns NULL on failure. */ int *ret; DEBUG(ast_log(LOG_DEBUG, "ast_io_add()\n")); if (ioc->fdcnt >= ioc->maxfdcnt) { /* * We don't have enough space for this entry. We need to * reallocate maxfdcnt poll fd's and io_rec's, or back out now. */ if (io_grow(ioc)) return NULL; } /* * At this point, we've got sufficiently large arrays going * and we can make an entry for it in the pollfd and io_r * structures. */ ioc->fds[ioc->fdcnt].fd = fd; ioc->fds[ioc->fdcnt].events = events; ioc->ior[ioc->fdcnt].callback = callback; ioc->ior[ioc->fdcnt].data = data; ioc->ior[ioc->fdcnt].id = (int *)malloc(sizeof(int)); /* Bonk if we couldn't allocate an int */ if (!ioc->ior[ioc->fdcnt].id) return NULL; *(ioc->ior[ioc->fdcnt].id) = ioc->fdcnt; ret = ioc->ior[ioc->fdcnt].id; ioc->fdcnt++; return ret; }
//! Determines number of seconds until the next outstanding event to take place /*! * \param con context to act upon * Determine the number of seconds until the next outstanding event * should take place, and return the number of milliseconds until * it needs to be run. This value is perfect for passing to the poll * call. Returns "-1" if there is nothing there are no scheduled events * (and thus the poll should not timeout) */
//! Waits for IO /*! * \param ioc which context to act upon * \param howlong how many milliseconds to wait * Wait for I/O to happen, returning after * howlong milliseconds, and after processing * any necessary I/O. Returns the number of * I/O events which took place. * If the value of howlong is -1, poll() shall block * until a requested event occurs or until the call is * interrupted. */
//! Runs the queue /*! * \param con Scheduling context to run * Run the queue, executing all callbacks which need to be performed * at this time. Returns the number of events processed. */ * handle_request ¿¡¼ request °¡ REGISTER ÀÎ °æ¿ì
sipsock_read ¶* static int sipsock_read(int *id, int fd, short events, void *ignore)
struct sip_request { int len; int headers; /* SIP Headers */ char *header[SIP_MAX_HEADERS]; int lines; /* SDP Content */ char *line[SIP_MAX_LINES]; char data[SIP_MAX_PACKET]; };
handle_request ¶* handle_request(p, &req, &sin);
ast_channel_alloc ¶* sip_new
int load_module(void) { return ast_register_application(app, dial_exec); } ast_channel_register ¶* 0.2.0
struct chanlist { char type[80]; char description[80]; int capabilities; struct ast_channel * (*requester)(char *type, int format, void *data); struct chanlist *next; } *backends = NULL;* int ast_channel_register(char *type, char *description, int capabilities, struct ast_channel *(*requester)(char *type, int format, void *data))
io.c ¶* int *ast_io_add(struct io_context *ioc, int fd, ast_io_cb callback, short events, void *data)
Add a new I/O entry for this file descriptor with the given event mask, to call callback with data as an argument. Returns NULL on failure. sip_call ¶* static int sip_call(struct ast_channel *ast, char *dest, int timeout)
ast_setstate ¶* static int sip_answer(struct ast_channel *ast)
|
The person you rejected yesterday could make you happy, if you say yes. |