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

📄 simutl1.c

📁 仿真测试接口程序。根据电总《用户接入网管理功能与管理接口技术规范》之《与112集中受理系统接口规范》
💻 C
📖 第 1 页 / 共 2 页
字号:
			pstr[j++] = pstr[i];		}	}	return (pstr);}/*:*************************************************************************   TITLE: StringToupper (char * pstr )   returns pointer to a result string.   FUNCTION:      Converts all characters in string to upper case           Note: This routine depends on ASCII character set   ************************************************************************** */char *StringToupper(char *p){	char *p1;	for (p1 = p; *p1 != '\000'; p1++)	{		*p1 = (char) toupper(*p1);	}	return p;}CLIENT_STATUS *newClientStruct(){	CLIENT_STATUS *cs_ptr;	cs_ptr = malloc(sizeof(CLIENT_STATUS));	if (cs_ptr)	{		memset(cs_ptr, 0, sizeof(CLIENT_STATUS));		cs_ptr->current_process = NEW;	}	return (cs_ptr);}/*:****************************************************************************   Function Name: so_close   Param:   int fd  - file descriptor of the socket to close   Return:     - 0 if OK (-1) error   ***************************************************************************** */int so_close(int fd){	CLIENT_STATUS *cs_ptr, *pre_cs_ptr;	DRIVER_STATUS *drv_ptr, *pre_drv_ptr;	switch (so[fd].whichType)	{	case IS_HIMSELF:		break;	case IS_CLIENT:		cs_ptr = so[fd].clientStatus;		while (cs_ptr)		{			pre_drv_ptr = NULL;			drv_ptr = so[cs_ptr->driver_fd].driverStatus;			while (drv_ptr)			{				if (drv_ptr->client_fd == fd)				{					/*result from driver should be aborted and need not reply to client */					/*free the driver status struct */					if (pre_drv_ptr == NULL)					{						if (drv_ptr->timer_id)							killEventTimer(drv_ptr->timer_id);						drv_ptr = drv_ptr->next;						free(so[cs_ptr->driver_fd].driverStatus);						so[cs_ptr->driver_fd].driverStatus = drv_ptr;					}					else					{						pre_drv_ptr->next = drv_ptr->next;						if (drv_ptr->timer_id)							killEventTimer(drv_ptr->timer_id);						free(drv_ptr);						drv_ptr = pre_drv_ptr->next;					}				}				else				{					pre_drv_ptr = drv_ptr;					drv_ptr = drv_ptr->next;				}			}			so[cs_ptr->driver_fd].count--;			if (so[cs_ptr->driver_fd].count <= 0)			{				/*attention:here fatal error may be happen */				/*close the simdrv */#ifdef WIN32_ENV				closesocket(cs_ptr->driver_fd);#else				printf("Close Driver Sock, SocketID=%d\n", cs_ptr->driver_fd);				close(cs_ptr->driver_fd);#endif				/* clean up stuff */				free(so[cs_ptr->driver_fd].driverStatus);				if (so[cs_ptr->driver_fd].readBuffer != NULL)				{					free(so[cs_ptr->driver_fd].readBuffer);				}				if (so[cs_ptr->driver_fd].writeBuffer != NULL)				{					free(so[cs_ptr->driver_fd].writeBuffer);				}				memset((void *) &so[cs_ptr->driver_fd], 0, sizeof(SOCKETSTRUCT));			}			pre_cs_ptr = cs_ptr;			cs_ptr = cs_ptr->next;			free(pre_cs_ptr);		}		break;	case IS_SIMDRV:		drv_ptr = so[fd].driverStatus;		while (drv_ptr)		{			pre_cs_ptr = NULL;			cs_ptr = so[drv_ptr->client_fd].clientStatus;			while (cs_ptr)			{				if (cs_ptr->driver_fd == fd)				{					/*command from client should be aborted and need not send to driver */					/*free the client status struct */					if (pre_cs_ptr == NULL)					{						cs_ptr = cs_ptr->next;						free(so[drv_ptr->client_fd].clientStatus);						so[drv_ptr->client_fd].clientStatus = cs_ptr;					}					else					{						pre_cs_ptr->next = cs_ptr->next;						free(cs_ptr);						cs_ptr = pre_cs_ptr->next;					}				}				else				{					pre_cs_ptr = cs_ptr;					cs_ptr = cs_ptr->next;				}			}			so[drv_ptr->client_fd].count--;			if (so[drv_ptr->client_fd].count <= 0)			{				/*attention:here fatal error may be happen */				/*close the client */#ifdef WIN32_ENV				closesocket(drv_ptr->client_fd);#else				printf("Close Client Sock, SocketID=%d\n", drv_ptr->client_fd);				close(drv_ptr->client_fd);#endif				/* clean up stuff */				free(so[drv_ptr->client_fd].clientStatus);				if (so[drv_ptr->client_fd].readBuffer != NULL)				{					free(so[drv_ptr->client_fd].readBuffer);				}				if (so[drv_ptr->client_fd].writeBuffer != NULL)				{					free(so[drv_ptr->client_fd].writeBuffer);				}				memset((void *) &so[drv_ptr->client_fd], 0, sizeof(SOCKETSTRUCT));			}			if (drv_ptr->timer_id)				killEventTimer(drv_ptr->timer_id);			pre_drv_ptr = drv_ptr;			drv_ptr = drv_ptr->next;			free(pre_drv_ptr);		}	}															/*switch */#ifdef WIN32_ENV	closesocket(fd);#else	close(fd);#endif	printf("Close Sock, SocketID=%d, Type=%d\n", fd, so[fd].whichType);	/* clean up stuff */	if (so[fd].readBuffer != NULL)	{		free(so[fd].readBuffer);	}	if (so[fd].writeBuffer != NULL)	{		free(so[fd].writeBuffer);	}	memset((void *) &so[fd], 0, sizeof(SOCKETSTRUCT));	return 0;}/*:****************************************************************************   Function Name: so_write   Param:   handle      - File number handle for write   buffer      - Pointer to characters to be sent   count       - number of characters to send   Return:       - number of characters sent   ***************************************************************************** */int so_write(int handle, void *buffer, unsigned count){	int i;#ifdef WIN32_ENV	i = send(handle, buffer, count, 0);#else	int errno;	i = write(handle, buffer, count);#endif	/* i = (-1) error or blocked */	/*     zero or positive number = number of bytes transfered */	/*     i can be less than count if it would have blocked */	/* if error is would block then add to writebuffer */	/*    other errors are returned to caller    */	/* if i < count then add remainted to writebuffer */	if (i < 0)	{		/* error test for would block *//*#ifndef WIN32_ENV   if(errno == EWOULDBLOCK) {   memcpy(so[handle].writeBuffer,buffer,count);   so[handle].writeOffset=0;   return count;   } else {   #endif */		return i;/*#ifndef WIN32_ENV   }   #endif */	}	/* did we send it all or only part ?? */	if (i >= (int) count)	{		return i;	}	/* only part so add the rest to the clist */	memcpy(so[handle].writeBuffer, buffer, count);	so[handle].writeOffset = i;	return i;}/*:***************************************************************************   Function Name:  int get_param_len(char *param_ptr, int max_len);   Narrative:  This routine will get the length of the parameter value at   param_ptr   Param:  char *param_ptr;    parameter value   int  max_len;       maximum param length   Return: Length of param   **************************************************************************** */int get_param_len(char *param_ptr, int max_len){	int i;	int quote;	quote = 0;	if (*param_ptr == '"')	{		quote = 1;		++param_ptr;	}	for (i = 0; i < max_len; i++)	{		switch (*param_ptr)		{		case ':':		case ';':		case '"':			return (i);		case ',':			if (!quote)				return (i);			/* else, fall through to default case */		default:			++param_ptr;			break;		}	}	return (i);}/*:***************************************************************************   Function Name:  int tl1_get_cmd(char *tl1_cmd, long *type, int *cmd_num)   Narrative:  This routine will check the command against the commands in    the structure known_cmds, set type from type_flag, and set the     command number in cmd_num.  If the command is not in known_cmds,   type will be UNKNOWN and cmd_num will be undefined.   Param:  char *tl1_cmd;   long *type;   int *cmd_num;   Return: If the command is missing, the function will return FAILURE,   else it will return SUCCESS.   **************************************************************************** */int tl1_get_cmd(char *tl1_cmd, long *type, int *cmd_num){	int i;	/* set default error exits. */	/* in some cases cmd_num was being tested when it was never set */	/* Changes by Ed Szczebak, Jr. 18 April 1996 */	*type = UNKNOWN;	*cmd_num = UNKNOWN_CMD_NO;	if (!isalpha(*tl1_cmd))		return (PRS_FAILURE);	i = 0;	while (known_cmds[i].cmd)	{		if (!strncmp(known_cmds[i].cmd, tl1_cmd, strlen(known_cmds[i].cmd)))		{			*type = known_cmds[i].type_flag;			*cmd_num = known_cmds[i].cmd_number;			if (*cmd_num == MEAS_VG_DC || *cmd_num == MEAS_VG_AC)			{				if (strstr(tl1_cmd, ":DC") != NULL)					*cmd_num = MEAS_VG_DC;				else					*cmd_num = MEAS_VG_AC;			}			return (PRS_SUCCESS);		}		++i;	}	return (PRS_FAILURE);}/*:***************************************************************************   Function Name: int tl1_get_param(char *tl1_cmd, char *param, char *buffer,   int max_len);   Narrative:  This routine will search tl1_cmd for the param field.  It will    then copy up to max_len characters into buffer.  If param is a named    parameter, only the value portion will be copied.  If the parameter    is not present, buffer will be empty.   Param:  char *tl1_cmd;   char *param;    char *buffer;   int max_len;   Return: If TSN or CTAG is invalid, return will be FAILURE,   else SUCCESS   **************************************************************************** */int tl1_get_param(char *tl1_cmd, char *param, char *buffer, int max_len){	char *param_ptr;	char *temp_ptr;	char temp_buf[80];	int param_len;	int i, j;	char *p;	memset(buffer, 0, max_len);	param_ptr = tl1_cmd;	if (!strcmp(param, "COMMAND"))	{		param_len = get_param_len(param_ptr, max_len);		if (param_len == 0)					/* parameter is missing */			return (PRS_FAILURE);		memcpy(buffer, param_ptr, param_len);		return (PRS_SUCCESS);	}	for (i = 0; i < MAX_PARAMS; i++)	{		param_ptr = strchr(param_ptr, ':');		if (!param_ptr)			return (PRS_FAILURE);		++param_ptr;		if (!strcmp(param, "TID"))		{			param_len = get_param_len(param_ptr, max_len);			if (param_len == 0)				/* parameter is missing */				return (PRS_SUCCESS);			if (*param_ptr == '"')				++param_ptr;			memcpy(buffer, param_ptr, param_len);			/* printf("tl1_get_param()::TID=%s\n",buffer); */			/* Delete TID head string -- "S," */			p = (char *) strstr(buffer, "S,");			if (p != NULL)			{				strcpy(buffer, p + 2);				/* printf("tl1_get_param()::buffer=%s\n",buffer); */			}			return (PRS_SUCCESS);		}		if (!strcmp(param, "TSN"))		{			if (i < 1)				continue;			memcpy(temp_buf, param_ptr, sizeof(temp_buf));			temp_ptr = strchr(temp_buf, ':');			if (!temp_ptr)				return (PRS_FAILURE);			*temp_ptr = 0;			if (strchr(temp_buf, '='))			{													/* named parameter */				temp_ptr = strstr(param_ptr, "TSN=");				if (!temp_ptr)					return (PRS_SUCCESS);	/* param not present */				temp_ptr += 4;			}			else			{													/* positional parameter */				temp_ptr = param_ptr;			}			param_len = get_param_len(temp_ptr, max_len);			if (param_len != 0)				memcpy(buffer, temp_ptr, param_len);			return (PRS_SUCCESS);		}		if (!strcmp(param, "TN"))		{			if (i < 1)				continue;			memcpy(temp_buf, param_ptr, sizeof(temp_buf));			temp_ptr = strchr(temp_buf, ':');			if (!temp_ptr)				return (PRS_FAILURE);			*temp_ptr = 0;			if (strchr(temp_buf, '='))			{													/* named parameter */				temp_ptr = strstr(param_ptr, "TN=");				if (!temp_ptr)					return (PRS_SUCCESS);	/* param not present */				temp_ptr += 3;			}			else			{													/* positional, must be 3rd item in block */				temp_ptr = strpbrk(param_ptr, ":,;");				if (temp_ptr && *temp_ptr != ',')					return (PRS_SUCCESS);	/* param not present */				++temp_ptr;							/* move past ',' */			}			param_len = get_param_len(temp_ptr, max_len);			if (param_len != 0)				memcpy(buffer, temp_ptr, param_len);			return (PRS_SUCCESS);		}		if (!strcmp(param, "V5EN"))		{			if (i < 1)				continue;			temp_ptr = strstr(param_ptr, "V5EN=");			if (temp_ptr)			{				temp_ptr += 5;				param_len = get_param_len(temp_ptr, max_len);				if (param_len != 0)					memcpy(buffer, temp_ptr, param_len);				return (PRS_SUCCESS);			}		}		if (!strcmp(param, "OFFHOOK"))		{			if (i < 1)				continue;			temp_ptr = strstr(param_ptr, "OFFHOOK=");			if (temp_ptr)			{				temp_ptr += 8;				param_len = get_param_len(temp_ptr, max_len);				if (param_len != 0)					memcpy(buffer, temp_ptr, param_len);				return (PRS_SUCCESS);			}		}		if (!strcmp(param, "NUM"))		{			if (i < 1)				continue;			temp_ptr = strstr(param_ptr, "NUM=");			if (temp_ptr)			{				temp_ptr += 4;				param_len = get_param_len(temp_ptr, max_len);				if (param_len != 0)					memcpy(buffer, temp_ptr, param_len);				return (PRS_SUCCESS);			}		}		if (!strcmp(param, "LOOP"))		{			if (i < 1)				continue;			temp_ptr = strstr(param_ptr, "LOOP=");			if (temp_ptr)			{				temp_ptr += 5;				param_len = get_param_len(temp_ptr, max_len);				if (param_len != 0)					memcpy(buffer, temp_ptr, param_len);				return (PRS_SUCCESS);			}		}		if (!strcmp(param, "CHANNEL"))		{			if (i < 1)				continue;			temp_ptr = strstr(param_ptr, "CHANNEL=");			if (temp_ptr)			{				temp_ptr += 8;				param_len = get_param_len(temp_ptr, max_len);				if (param_len != 0)					memcpy(buffer, temp_ptr, param_len);				return (PRS_SUCCESS);			}		}		if (!strcmp(param, "GRADE"))		{			if (i < 1)				continue;			temp_ptr = strstr(param_ptr, "GRADE=");			if (temp_ptr)			{				temp_ptr += 6;				param_len = get_param_len(temp_ptr, max_len);				if (param_len != 0)					memcpy(buffer, temp_ptr, param_len);				return (PRS_SUCCESS);			}		}		if (!strcmp(param, "EXK"))		{			if (i < 1)				continue;			memcpy(temp_buf, param_ptr, sizeof(temp_buf));			temp_ptr = strchr(temp_buf, ':');			if (!temp_ptr)				return (PRS_FAILURE);			*temp_ptr = 0;			if (strchr(temp_buf, '='))			{													/* named parameter */				temp_ptr = strstr(param_ptr, "EXK=");				if (!temp_ptr)					return (PRS_SUCCESS);	/* param not present */				temp_ptr += 4;			}			else			{													/* positional, must be 3rd item in block */				temp_ptr = strpbrk(param_ptr, ":,;");				if (temp_ptr && *temp_ptr != ',')					return (PRS_SUCCESS);	/* param not present */				++temp_ptr;							/* move past ',' */			}			param_len = get_param_len(temp_ptr, max_len);			if (param_len != 0)				memcpy(buffer, temp_ptr, param_len);			return (PRS_SUCCESS);		}		if (!strcmp(param, "CTAG"))		{			if (i < 2)				continue;			for (j = 0; j < 6; j++)			{													/* CTAG must be 1-6 */				if (param_ptr[j] == ':' || param_ptr[j] == ';')					break;				if (!isalnum(param_ptr[j]))		/* alphanumeric characters */					return (PRS_FAILURE);			}			param_len = get_param_len(param_ptr, max_len);			memcpy(buffer, param_ptr, param_len);			return (PRS_SUCCESS);		}		if (!strcmp(param, "ACC"))		{			if (i < 4)				continue;			temp_ptr = strstr(param_ptr, "ACC=");			if (temp_ptr)			{				temp_ptr += 4;				param_len = get_param_len(temp_ptr, max_len);				if (param_len != 0)					memcpy(buffer, temp_ptr, param_len);				return (PRS_SUCCESS);			}		}	}	return (PRS_FAILURE);					/* not supported */}

⌨️ 快捷键说明

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