[asterisk-commits] russell: branch russell/smdi-1.4 r93116 - /team/russell/smdi-1.4/res/res_smdi.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 14 16:18:25 CST 2007


Author: russell
Date: Fri Dec 14 16:18:20 2007
New Revision: 93116

URL: http://svn.digium.com/view/asterisk?view=rev&rev=93116
Log:
Combine ast_smdi_mwi_set and unset, as they are almost identical ..

Modified:
    team/russell/smdi-1.4/res/res_smdi.c

Modified: team/russell/smdi-1.4/res/res_smdi.c
URL: http://svn.digium.com/view/asterisk/team/russell/smdi-1.4/res/res_smdi.c?view=diff&rev=93116&r1=93115&r2=93116
==============================================================================
--- team/russell/smdi-1.4/res/res_smdi.c (original)
+++ team/russell/smdi-1.4/res/res_smdi.c Fri Dec 14 16:18:20 2007
@@ -157,6 +157,35 @@
 	ast_mutex_unlock(&iface->mwi_q_lock);
 }
 
+static int smdi_toggle_mwi(struct ast_smdi_interface *iface, const char *mailbox, int on)
+{
+	FILE *file;
+	int i;
+	
+	if (!(file = fopen(iface->name, "w"))) {
+		ast_log(LOG_ERROR, "Error opening SMDI interface %s (%s) for writing\n", iface->name, strerror(errno));
+		return 1;
+	}	
+
+	ASTOBJ_WRLOCK(iface);
+
+	fprintf(file, "%s:MWI ", on ? "OP" : "RMV");
+
+	for (i = 0; i < iface->msdstrip; i++)
+	   fprintf(file, "0");
+
+	fprintf(file, "%s!\x04", mailbox);
+
+	fclose(file);
+
+	ASTOBJ_UNLOCK(iface);
+
+	ast_log(LOG_DEBUG, "Sent MWI %s message for %s on %s\n", on ? "set" : "unset", 
+		mailbox, iface->name);
+
+	return 0;
+}
+
 /*!
  * \brief Set the MWI indicator for a mailbox.
  * \param iface the interface to use.
@@ -164,28 +193,7 @@
  */
 int ast_smdi_mwi_set(struct ast_smdi_interface *iface, const char *mailbox)
 {
-	FILE *file;
-	int i;
-	
-	file = fopen(iface->name, "w");
-	if (!file) {
-		ast_log(LOG_ERROR, "Error opening SMDI interface %s (%s) for writing\n", iface->name, strerror(errno));
-		return 1;
-	}	
-
-	ASTOBJ_WRLOCK(iface);
-
-	fprintf(file, "OP:MWI ");
-
-	for (i = 0; i < iface->msdstrip; i++)
-	   fprintf(file, "0");
-
-	fprintf(file, "%s!\x04", mailbox);
-	fclose(file);
-
-	ASTOBJ_UNLOCK(iface);
-	ast_log(LOG_DEBUG, "Sent MWI set message for %s on %s\n", mailbox, iface->name);
-	return 0;
+	return smdi_toggle_mwi(iface, mailbox, 1);
 }
 
 /*! 
@@ -195,28 +203,7 @@
  */
 int ast_smdi_mwi_unset(struct ast_smdi_interface *iface, const char *mailbox)
 {
-	FILE *file;
-	int i;
-	
-	file = fopen(iface->name, "w");
-	if (!file) {
-		ast_log(LOG_ERROR, "Error opening SMDI interface %s (%s) for writing\n", iface->name, strerror(errno));
-		return 1;
-	}	
-
-	ASTOBJ_WRLOCK(iface);
-
-	fprintf(file, "RMV:MWI ");
-
-	for (i = 0; i < iface->msdstrip; i++)
-	   fprintf(file, "0");
-
-	fprintf(file, "%s!\x04", mailbox);
-	fclose(file);
-
-	ASTOBJ_UNLOCK(iface);
-	ast_log(LOG_DEBUG, "Sent MWI unset message for %s on %s\n", mailbox, iface->name);
-	return 0;
+	return smdi_toggle_mwi(iface, mailbox, 0);
 }
 
 /*!




More information about the asterisk-commits mailing list