summaryrefslogtreecommitdiff
path: root/pjsip
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-02-07 21:25:17 +0000
committerBenny Prijono <bennylp@teluu.com>2006-02-07 21:25:17 +0000
commitfd07c081949edc7ee046f3953d8d099aa9624feb (patch)
tree2351a4f17391f742db335f18b79bb51ab582bb22 /pjsip
parente217f770914365fb919fedf62adfe2e58740f20d (diff)
Added missing pjsua/pjsua_reg.c to svn
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@149 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip')
-rw-r--r--pjsip/src/pjsua/pjsua_reg.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/pjsip/src/pjsua/pjsua_reg.c b/pjsip/src/pjsua/pjsua_reg.c
new file mode 100644
index 00000000..2afb48d6
--- /dev/null
+++ b/pjsip/src/pjsua/pjsua_reg.c
@@ -0,0 +1,104 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
+ *
+ * This program 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.
+ *
+ * This program 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
+ */
+#include "pjsua.h"
+
+#define THIS_FILE "pjsua_reg.c"
+
+static void regc_cb(struct pjsip_regc_cbparam *param)
+{
+ /*
+ * Print registration status.
+ */
+ if (param->code < 0 || param->code >= 300) {
+ PJ_LOG(2, (THIS_FILE, "SIP registration failed, status=%d (%s)",
+ param->code, pjsip_get_status_text(param->code)->ptr));
+ pjsua.regc = NULL;
+
+ } else if (PJSIP_IS_STATUS_IN_CLASS(param->code, 200)) {
+ PJ_LOG(3, (THIS_FILE, "SIP registration success, status=%d (%s), "
+ "will re-register in %d seconds",
+ param->code,
+ pjsip_get_status_text(param->code)->ptr,
+ param->expiration));
+
+ } else {
+ PJ_LOG(4, (THIS_FILE, "SIP registration updated status=%d", param->code));
+ }
+}
+
+
+/*
+ * Update registration. If renew is false, then unregistration will be performed.
+ */
+void pjsua_regc_update(pj_bool_t renew)
+{
+ pj_status_t status;
+ pjsip_tx_data *tdata;
+
+ if (renew) {
+ PJ_LOG(3,(THIS_FILE, "Performing SIP registration..."));
+ status = pjsip_regc_register(pjsua.regc, 1, &tdata);
+ } else {
+ PJ_LOG(3,(THIS_FILE, "Performing SIP unregistration..."));
+ status = pjsip_regc_unregister(pjsua.regc, &tdata);
+ }
+
+ if (status != PJ_SUCCESS) {
+ pjsua_perror("Unable to create REGISTER request", status);
+ return;
+ }
+
+ pjsip_regc_send( pjsua.regc, tdata );
+}
+
+/*
+ * Initialize client registration.
+ */
+pj_status_t pjsua_regc_init(void)
+{
+ pj_status_t status;
+
+ /* initialize SIP registration if registrar is configured */
+ if (pjsua.registrar_uri.slen) {
+
+ status = pjsip_regc_create( pjsua.endpt, NULL, &regc_cb, &pjsua.regc);
+
+ if (status != PJ_SUCCESS) {
+ pjsua_perror("Unable to create client registration", status);
+ return status;
+ }
+
+
+ status = pjsip_regc_init( pjsua.regc, &pjsua.registrar_uri,
+ &pjsua.local_uri,
+ &pjsua.local_uri,
+ 1, &pjsua.contact_uri,
+ pjsua.reg_timeout);
+ if (status != PJ_SUCCESS) {
+ pjsua_perror("Client registration initialization error", status);
+ return status;
+ }
+
+ pjsip_regc_set_credentials( pjsua.regc, pjsua.cred_count,
+ pjsua.cred_info );
+ }
+
+ return PJ_SUCCESS;
+}
+