[Asterisk-code-review] chan_ooh323: fix h323 log file path (...asterisk[13])

Alexander Anikin asteriskteam at digium.com
Wed Apr 10 18:11:54 CDT 2019


Alexander Anikin has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/11258


Change subject: chan_ooh323: fix h323 log file path
......................................................................

chan_ooh323: fix h323 log file path

Change h323 log path relative to AST_LOG_DIR instead of
/var/log/asterisk hardcoded
Add return back error message from OOH323EP initialize

ASTERISK-28348 #close

Reported by: Dmitry Shubin

Change-Id: Ib102dd36bbe6c2a7a4ce6870ae9110d9000d7e98
---
M addons/chan_ooh323.c
M addons/chan_ooh323.h
M addons/ooh323c/src/ooh323ep.c
M addons/ooh323c/src/ooh323ep.h
4 files changed, 17 insertions(+), 11 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/58/11258/1

diff --git a/addons/chan_ooh323.c b/addons/chan_ooh323.c
index a883ace..e80fc34 100644
--- a/addons/chan_ooh323.c
+++ b/addons/chan_ooh323.c
@@ -82,7 +82,7 @@
 /* Defaults */
 #define DEFAULT_CONTEXT "default"
 #define DEFAULT_H323ID "Asterisk PBX"
-#define DEFAULT_LOGFILE "/var/log/asterisk/h323_log"
+#define DEFAULT_LOGFILE "h323_log"
 #define DEFAULT_H323ACCNT "ast_h323"
 
 /* Flags */
@@ -346,7 +346,8 @@
 
 extern OOH323EndPoint gH323ep;
 
-static char gLogFile[256] = DEFAULT_LOGFILE;
+static char gLogFile[PATH_MAX] = DEFAULT_LOGFILE;
+static char gInitError[256] = "";
 static int  gPort = 1720;
 static char gIP[2+8*4+7];	/* Max for IPv6 addr */
 struct ast_sockaddr bindaddr;
@@ -2855,7 +2856,7 @@
 	}
 
 	/* Inintialize everything to default */
-	strcpy(gLogFile, DEFAULT_LOGFILE);
+	snprintf(gLogFile, sizeof(gLogFile), "%s/%s", ast_config_AST_LOG_DIR, DEFAULT_LOGFILE);
 	gPort = 1720;
 	gIP[0] = '\0';
 	strcpy(gCallerID, DEFAULT_H323ID);
@@ -3029,7 +3030,11 @@
             			ast_copy_string(gGatekeeper, v->value, sizeof(gGatekeeper));
 			}
 		} else if (!strcasecmp(v->name, "logfile")) {
-         		ast_copy_string(gLogFile, v->value, sizeof(gLogFile));
+			if (v->value[0] == '/') {
+				ast_copy_string(gLogFile, v->value, sizeof(gLogFile));
+			} else {
+				snprintf(gLogFile, sizeof(gLogFile), "%s/%s", ast_config_AST_LOG_DIR, v->value);
+			}
 		} else if (!strcasecmp(v->name, "context")) {
          		ast_copy_string(gContext, v->value, sizeof(gContext));
          		ast_verb(3, "  == Setting default context to %s\n", gContext);
@@ -3833,9 +3838,9 @@
 	if (!reload_config(0)) {
 
 		/* fire up the H.323 Endpoint */
-		if (OO_OK != ooH323EpInitialize(OO_CALLMODE_AUDIOCALL, gLogFile)) {
-         		ast_log(LOG_ERROR, "Failed to initialize OOH323 endpoint-"
-                            "OOH323 Disabled\n");
+		if (OO_OK != ooH323EpInitialize(OO_CALLMODE_AUDIOCALL, gLogFile, gInitError, sizeof(gInitError))) {
+			ast_log(LOG_ERROR, "Failed to initialize OOH323 endpoint: %s"
+				"OOH323 Disabled\n", gInitError);
 			ao2_ref(gCap, -1);
 			gCap = NULL;
 			ao2_ref(ooh323_tech.capabilities, -1);
diff --git a/addons/chan_ooh323.h b/addons/chan_ooh323.h
index 0dde50b..ae26a0b 100644
--- a/addons/chan_ooh323.h
+++ b/addons/chan_ooh323.h
@@ -66,6 +66,7 @@
 #include "asterisk/udptl.h"
 #include "asterisk/stasis_channels.h"
 #include "asterisk/format_cache.h"
+#include "asterisk/paths.h"
 
 #include "ootypes.h"
 #include "ooUtils.h"
diff --git a/addons/ooh323c/src/ooh323ep.c b/addons/ooh323c/src/ooh323ep.c
index 1dedecd..be43896 100644
--- a/addons/ooh323c/src/ooh323ep.c
+++ b/addons/ooh323c/src/ooh323ep.c
@@ -34,7 +34,7 @@
 extern DList g_TimerList;
 
 int ooH323EpInitialize
-   (enum OOCallMode callMode, const char* tracefile)
+   (enum OOCallMode callMode, const char* tracefile, char* errstr, int errstr_max)
 {
 
    memset(&gH323ep, 0, sizeof(ooEndPoint));
@@ -46,7 +46,7 @@
    {
       if(strlen(tracefile)>= MAXFILENAME)
       {
-         printf("Error:File name longer than allowed maximum %d\n",
+         snprintf(errstr, errstr_max, "Error:File name longer than allowed maximum %d\n",
                  MAXFILENAME-1);
          return OO_FAILED;
       }
@@ -59,7 +59,7 @@
    gH323ep.fptraceFile = fopen(gH323ep.traceFile, "a");
    if(gH323ep.fptraceFile == NULL)
    {
-      printf("Error:Failed to open trace file %s for write.\n",
+      snprintf(errstr, errstr_max, "Error:Failed to open trace file %s for write.\n",
                   gH323ep.traceFile);
       return OO_FAILED;
    }
diff --git a/addons/ooh323c/src/ooh323ep.h b/addons/ooh323c/src/ooh323ep.h
index a77b9e3..5c9c3dd 100644
--- a/addons/ooh323c/src/ooh323ep.h
+++ b/addons/ooh323c/src/ooh323ep.h
@@ -163,7 +163,7 @@
  * @return               OO_OK, on success. OO_FAILED, on failure
  */
 EXTERN int ooH323EpInitialize
-   (enum OOCallMode callMode, const char* tracefile);
+   (enum OOCallMode callMode, const char* tracefile, char* errstr, int errstr_max);
 
 /**
  * This function is used to represent the H.323 application endpoint as

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/11258
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: Ib102dd36bbe6c2a7a4ce6870ae9110d9000d7e98
Gerrit-Change-Number: 11258
Gerrit-PatchSet: 1
Gerrit-Owner: Alexander Anikin <may213 at yandex.ru>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190410/9f44a39e/attachment.html>


More information about the asterisk-code-review mailing list