⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libmodem-1.0.0.pha.patch

📁 手机短消息的服务器端和客户端的源代码 是应用于LINUX/UNIX开发环境的
💻 PATCH
字号:
diff -r -u libmodem-1.0.0.orig/Makefile libmodem-1.0.0/Makefile--- libmodem-1.0.0.orig/Makefile	Tue Aug 26 17:19:48 1997+++ libmodem-1.0.0/Makefile	Thu Oct  8 16:46:58 1998@@ -31,7 +31,7 @@  include CONFIG.MAKE -CFLAGS= -I. $(CCFLAGS) $(DEFINES) $(DEBUG) -DLIBRARY -DLIB_VERSION=$(LIB_VERSION)+CFLAGS= -I. $(CCFLAGS) $(DEFINES) $(DEBUG) -DLIBRARY -DLIB_VERSION=$(LIB_VERSION) -DSMS_FIX MANFIN= $(MANDIR)/man$(MANEXT)  # for the librarydiff -r -u libmodem-1.0.0.orig/dial/modems.h.in libmodem-1.0.0/dial/modems.h.in--- libmodem-1.0.0.orig/dial/modems.h.in	Tue Aug 26 14:11:17 1997+++ libmodem-1.0.0/dial/modems.h.in	Wed Oct 14 15:27:42 1998@@ -112,6 +112,10 @@ extern int ldial(char *, char *); extern int bdial(char *, int); extern int bldial(char *, char *, int);+extern int open_mdm_line();+extern int lopen_mdm_line(char *);+extern int bopen_mdm_line(int);+extern int blopen_mdm_line(char *, int); extern int close_nohangup(int); extern int hangup(int); extern struct modems *getopenmodem(void);diff -r -u libmodem-1.0.0.orig/line_manage.c libmodem-1.0.0/line_manage.c--- libmodem-1.0.0.orig/line_manage.c	Tue Aug 26 09:48:22 1997+++ libmodem-1.0.0/line_manage.c	Wed Oct 14 15:27:06 1998@@ -288,6 +288,182 @@     return fd; } +int open_mdm_line()  {+    struct modems *mdl;+    int ret = 0;++    open_mdm_log();+    mdmerrno = 0;+    setmdms();++    while ((mdl = getnextmdm()) != NULL) {+/*+ * if locked, skip to the next modem+ */+        if (mdm_chklock(mdl) == SUCCESS)+		continue;++/*+ * Try to dial...+ */+        ret = blopen_mdm_line(mdl->line, mdl->bd);++/*+ * If the user ask it, cycle all the modems on error+ */+	if ((ret < 0) && mdm_cycle) {+/*+ * If cycle is chosen, the meaning of mdm_cycle is not only an on/off, it is+ * the max number of times we cycle. At 0, end of the story: no more retries.+ */+		--mdm_cycle;+/*+ * Log the error and continue (we force the error log because this modem can+ * be in a fault state while the sysadmin don't know the faulty state).+ */+		mdm_log(LOG_INFO,+			"Error encountered while opening %s (%s)\n",+			mdl->line,+			mdmstrerror(ret));++		switch (ret) {+			case -EUNMDMERR:+			case -ENOMDMFILE:+			case -EMDMBUSY:+/*+ * If config file don't exist or unknown error is returned,  or line is busy+ * don't cycle the modems.+ */+				break;+			default:+		    		continue;+		}+	}+/*+ * If the modem is alredy used, skip to the next modem else return the error+ */+	if (ret != EMDMOPEN)+		return ret;+    }++    return (mdmerrno = -ENOMDMDEV);+}++int lopen_mdm_line(char *line) {+    struct modems *mdl;++    open_mdm_log();+    mdmerrno = 0;++    if ((mdl = getmdmnam(line)) == NULL)+        return mdmerrno;++/*+ * dial at the maximum baud rate+ */+    return blopen_mdm_line(line, mdl->bd);+}++int bopen_mdm_line(int baud)  {+    struct modems *mdl;+    int ret = 0;++    open_mdm_log();+    mdmerrno = 0;+    setmdms();++    while ((mdl = getnextmdm()) != NULL) {+        if (baud <= mdl->bd) {+/*+ * if locked, skip this modem+ */+            if (mdm_chklock(mdl) == SUCCESS)+	    	continue;+/*+ * Try to dial...+ */+            ret = blopen_mdm_line(mdl->line, baud);+/*+ * If the user ask it, cycle all the modems on error+ */+	    if ((ret < 0) && mdm_cycle) {+/*+ * If cycle is chosen, the meaning of mdm_cycle is not only an on/off, it is+ * the max number of times we cycle. At 0, end of the story: no more retries.+ */+		--mdm_cycle;+/*+ * Log the error and continue+ */+			mdm_log(LOG_INFO,+				"Error encountered while opening %s (%s)\n",+				mdl->line,+				mdmstrerror(ret));++		    	switch (ret) {+				case -EUNMDMERR:+				case -ENOMDMFILE:+				case -EMDMBUSY:+/*+ * If config file don't exist or unknown error is returned, or line is busy+ * don't cycle the modems.+ */+					break;+				default:+		    			continue;+		    	}+	    }+/*+ * If the modem is alredy used, skip to the next modem else return the error+ */+            if (ret != EMDMOPEN)+                    return ret;+        }+    }++    return (mdmerrno = -ENOMDMDEV);+}++int blopen_mdm_line(char *line, int baud) {+    struct modems *mdl;+    int fd, ret = 0;++    open_mdm_log();+    mdmerrno = 0;++    if ((mdl = getmdmnam(line)) == NULL)+        return mdmerrno;++    if (mdm_chklock(mdl) == SUCCESS)+	    return (mdmerrno = -EMDMLOCK);+/*+ * lock and open the modem line and set it up for communications+ * remember to unlock the mdl device when returning an error.+ */+    if ((fd = open_modem_setup_line(mdl, baud)) < 0)+        return fd;++/*+ * Now we must save the actual device to have it in hands when hangup+ */+    mdmopendevice = mdl;++/*+ * set up the modem: init string et al+ */+    if ((ret = initialize_modem(fd, mdl)) < 0) {+        mdm_unlock(mdl);+        hangup(fd);+        return ret;+    }++/*+ * Comm link now open with modem, returning fd+ */+    close_mdm_log();+    return fd;+}+ static int dial_to_num(int fd, struct modems *device, char *num) { 	char *buffer; 	int ret = -ENOMDMERR;@@ -638,6 +814,280 @@ 	return FAILURE; } ++#if defined(SMS_FIX)+/* Angelo: + *+ * Problem with this routine:+ * When we send command strings to the modem+ * We are expecting return values from the modem in the form+ * of simple strings.+ * + * When we send the ATDT command we expect a CONNECT+ * string to be returned, if we write the ATDT command and read+ * the result into a buffer - reading 1000 charaters we get the+ * result and potentially any other data that may follow. It is + * a very bad idea to throw away this data as an application+ * will never see it!!!+ * + * The solution is to read the result a character at a time + * stopping as soon as we get the resonse string we are looking+ * for.+ */++static+int talk_to_modem(int fd, struct modems *device, char *command, int isdial) {+	fd_set readfds;+	struct timeval tmout;+	int ret;+	int cmd_found = FAILURE;+	int retries = SYNC_RTRY;+	int mdm_read_retries = READ_RTRY;+	char *cmdbuffer;+	char *bigbuffer;+	char *cmdmodem;+	char *buffer;++	cmdbuffer = mdmalloc(BUFSIZE);++	if (!cmdbuffer)+		return -EMDMEM;++	bigbuffer = mdmalloc(BUFSIZE);++	if (!bigbuffer) {+		mdmfree(cmdbuffer);+		return -EMDMEM;+	}++	cmdmodem = mdmalloc(BUFSIZE);++	if (!cmdmodem) {+		mdmfree(cmdbuffer);+		mdmfree(bigbuffer);+		return -EMDMEM;+	}++	buffer = mdmalloc(BUFSIZE);++	if (!buffer) {+		mdmfree(cmdbuffer);+		mdmfree(bigbuffer);+		mdmfree(cmdmodem);+		return -EMDMEM;+	}++#if defined(DEBUG)+	mdm_log(LOG_DEBUG, "Using SMS_FIX version of talk_to_modem\n");+	mdm_log(LOG_DEBUG, "writing >> %s << to modem\n", command);+#endif /* DEBUG */++/*+ * write the command to modem+ */++	if (write(fd, command, strlen(command)) != strlen(command)) {+		mdmfree(cmdbuffer);+		mdmfree(bigbuffer);+		mdmfree(cmdmodem);+		mdmfree(buffer);+		return (mdmerrno = -EMDMWRITE);+	}++	mdm_log(LOG_INFO, "written >> %s << to modem\n", command);++    /*+     * I need to check this thing.+     */+	sleep (1);+++	/* Angelo:+	 * +	 * As we will be reading only 1 character at+	 * a time to avoid eating data, mdm_read_retries+	 * needs to be higher, the size of the buffer+	 * is ok forthis.+	 */++	mdm_read_retries = BUFSIZE;++	while (!cmd_found) {++		memset(bigbuffer, 0, BUFSIZE);++		FD_ZERO(&readfds);+		FD_SET(fd, &readfds);++		tmout.tv_sec  = device->dl;+		tmout.tv_usec = 0;++		ret = select(FD_SETSIZE, &readfds, NULL, NULL, &tmout);++		if (ret < 0) {+			mdmfree(cmdbuffer);+			mdmfree(bigbuffer);+			mdmfree(cmdmodem);+			mdmfree(buffer);+			return (mdmerrno = -EMDMSEL);+		}++		if (!FD_ISSET(fd, &readfds)) {+			mdmfree(cmdbuffer);+			mdmfree(bigbuffer);+			mdmfree(cmdmodem);+			mdmfree(buffer);+			return (mdmerrno = -EMDMNOFDSET);+		}+++		/* Angelo:+		 *+		 * Data is waiting to be read from fd+		 * read only 1 character and append to buf. +		 * Reading more than 1 character will potentially+		 * eat into data being sent from remote machine+		 */++		if ((ret = read(fd, bigbuffer, 1)) < 0) {+			mdmfree(cmdbuffer);+			mdmfree(bigbuffer);+			mdmfree(cmdmodem);+			mdmfree(buffer);+			return (mdmerrno = -EMDMREAD);+		}+        +		bigbuffer[ret] = '\0';+++#if defined(DEBUG)+		mdm_log(LOG_DEBUG, "read >> %s << from modem\n", bigbuffer);+#endif /* DEBUG */++		strcat(cmdbuffer, bigbuffer);++		if (get_command(cmdbuffer, cmdmodem) == FAILURE) {+			if (!(mdm_read_retries--)) {+				mdmfree(cmdbuffer);+				mdmfree(bigbuffer);+				mdmfree(cmdmodem);+				mdmfree(buffer);+				return (mdmerrno = -EMDMRDRT);+			}+			continue;+		}++/*+ * Reset read retries: we have found something.+ */++		mdm_read_retries = BUFSIZE;++		if (!strcmp(command, cmdmodem)) {+/*+ * local echo enabled!!! strip out the command from modem answer!!!!+ * that is "command\r\nOK\r\n" or something like that+ */+			if (get_command(cmdbuffer, cmdmodem) == FAILURE) {+				if (!(mdm_read_retries--)) {+					mdmfree(cmdbuffer);+					mdmfree(bigbuffer);+					mdmfree(cmdmodem);+					mdmfree(buffer);+					return (mdmerrno = -EMDMRDRT);+				}+				continue;+			}++			mdm_read_retries = BUFSIZE;+		}++		mdm_log(LOG_INFO, "checking >> %s << from modem\n", cmdmodem);++		if (check_for_string(cmdmodem, buffer) == SUCCESS)+			cmd_found = 1;+		if (!(retries--)) {+			mdmfree(cmdbuffer);+			mdmfree(bigbuffer);+			mdmfree(cmdmodem);+			mdmfree(buffer);+			return (mdmerrno = -EMDMSYNC);+		}+	}++/*+ * If modem return ERROR, we must return the error now+ * if it is RINGing we must return.+ */+	if (!strcmp(buffer, "ERROR")) {+		mdmfree(cmdbuffer);+		mdmfree(bigbuffer);+		mdmfree(cmdmodem);+		mdmfree(buffer);+		return (mdmerrno = -EMDMERROR);+	}++	if (!strcmp(buffer, "RING")) {+		mdmfree(cmdbuffer);+		mdmfree(bigbuffer);+		mdmfree(cmdmodem);+		mdmfree(buffer);+		return (mdmerrno = -EMDMRING);+	}++	if (isdial) {+/*+ * check the answer against 'CONNECT' or BUSY+ */+		if (!strcmp(buffer, "CONNECT")) {+			mdmfree(cmdbuffer);+			mdmfree(bigbuffer);+			mdmfree(cmdmodem);+			mdmfree(buffer);+			return (mdmerrno = -ENOMDMERR);+		}+		if (!strcmp(buffer, "BUSY")) {+			mdmfree(cmdbuffer);+			mdmfree(bigbuffer);+			mdmfree(cmdmodem);+			mdmfree(buffer);+			return (mdmerrno = -EMDMBUSY);+		}+		if (!strcmp(buffer, "NO DIALTONE")) {+			mdmfree(cmdbuffer);+			mdmfree(bigbuffer);+			mdmfree(cmdmodem);+			mdmfree(buffer);+			return (mdmerrno = -EMDMTONE);+		}+		if (!strcmp(buffer, "NO ANSWER")) {+			mdmfree(cmdbuffer);+			mdmfree(bigbuffer);+			mdmfree(cmdmodem);+			mdmfree(buffer);+			return (mdmerrno = -EMDMANSW);+		}+	} else {+/*+ * check the answer against 'OK' ? No err : Unk err+ */+		if (!strcmp(buffer, "OK")) {+			mdmfree(cmdbuffer);+			mdmfree(bigbuffer);+			mdmfree(cmdmodem);+			mdmfree(buffer);+			return (mdmerrno = -ENOMDMERR);+		}+	}+	mdmfree(cmdbuffer);+	mdmfree(bigbuffer);+	mdmfree(cmdmodem);+	mdmfree(buffer);+	return (mdmerrno = -EUNMDMERR);+}++#else  /* SMS_FIX */+ static int talk_to_modem(int fd, struct modems *device, char *command, int isdial) { 	fd_set readfds;@@ -872,6 +1322,9 @@ 	mdmfree(buffer); 	return (mdmerrno = -EUNMDMERR); }++#endif /* SMS_FIX */+  static int check_for_string(char *from, char *to) { 	int i;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -