Asterisk Source/Sip Module
|
[edit]
AsteriskSource/SipModule ¶* 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 ÀÎ °æ¿ì
[edit]
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];
};
[edit]
handle_request ¶* handle_request(p, &req, &sin);
[edit]
ast_channel_alloc ¶* sip_new
int load_module(void)
{
return ast_register_application(app, dial_exec);
}
[edit]
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. * int ast_io_wait(struct io_context *ioc, int howlong)
[edit]
Sip protocol ¶* What are the benefits of SIP?
[edit]
Cseq ¶* A CSeq header field in a request contains
[edit]
sip address ¶* sip address
Your ¡°SIP program¡± registers its online presence with a ¡°SIP Proxy¡±: ¡°Hey, i¡¯m on my home network right now, and I can be reached at this IP address¡±. When you arrive at work, your SIP program will now say ¡°Yoohoo, i¡¯ve moved, i¡¯m now here!¡±. If someone wants to call you, they¡¯ll type your SIP address in their SIP program. The SIP provider will help this person¡¯s SIP software get in touch with your computer¡¯s SIP software, partly thanks to some STUN magic thrown in the middle. A SIP address looks exactly like an e-mail address, and, with some providers such as EarthLink, can very-well be one and the same. In my case, you can send me an e-mail at hollandct@earthlink.net or plug hollandct@earthlink.net ( or sip:hollandct@earthlink.net ) in your SIP program to call me up. If i¡¯m not online or available, you¡¯ll hear my voicemail, which will then be delivered as a .wav attachment to my e-mail address ¡¦ which Mail.app plays inline just fine! You don¡¯t even need a ¡°SIP Provider¡± to do SIP. If you know your party¡¯s IP address or host name, if their SIP software is properly configured, you can plug their IP address into your SIP program to give them a ring. Having a SIP address just gives you a more universal way for people to get in touch with you. |
Nile Is Like Emacs |









