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

📄 appinit.c

📁 电力与银行通讯的源码 1.应用tuxedo中间件. 2.与银行的前置机通讯. 3.proc*c 的应用
💻 C
字号:
#include "midware.h"#include "public.h"#include <string.h>#include <malloc.h>CDatabase theDatabase;int tpsvrinit(int argc, char *argv[]){	char szTemp[200] = "";	int iRet = 0;	char szServer[30] = "";	char szDataBase[30] = "";	char szUser[30] = "";	char szPass[30] = "";/*	if (tpopen() == -1)	{2	3		sprintf(szTemp,"Open Database error = %d",tperrno );		userlog(szTemp);		return -1;	}	*/	if ((gf_GetINIString("config.ini", "DataBase","Server","",szServer) !=0) || 		(gf_GetINIString("config.ini", "DataBase","DataBase","",szDataBase) !=0) || 		(gf_GetINIString("config.ini", "DataBase","User","",szUser) !=0) || 		(gf_GetINIString("config.ini", "DataBase","Pass","",szPass) !=0))	{		MW_Trace("没有设置config.ini文件中的数据库连接参数!");		return -1;	}	DB_Construct(&theDatabase);	iRet = DB_Open(&theDatabase,szServer,szDataBase,szUser,szPass);	if (iRet == 0)	{		MW_Trace("数据库连接失败!");		return(-1);	}	else	{	  	return 0;			}	return 0;}void tpsvrdone(){//	tpclose();	DB_CommitTransaction(&theDatabase);	DB_Close(&theDatabase,1);}int gf_GetINIString(char * aszFileName, /*INI文件名*/					char * aszSession,  /*段*/					char * aszKey,      /*关键值*/					char * aszDefault,  /*缺省值*/					char * aszText)		/*返回值*/{	FILE * fp;	char szLineBuf[255] = "";	/*一行数据的缓冲*/	int  iInSession = 0; /*是否在所需的SESSION中*/	int  iHaveKey = 0;	int  i ,j;	int  iLen = 0;	int  iBegin = 0;	char szSession[40] = "";	char szKey[40] = "";	char szText[255] = "";	strcpy(aszText,aszDefault);		if ((fp = fopen(aszFileName,"r")) == NULL) return -1;	while(fgets(szLineBuf,254,fp) != NULL)	{		/*分析输入的字符行*/		iLen = strlen(szLineBuf);		/*取第一个字符*/		i = 0;		for (;i < iLen && szLineBuf[i] == ' ' && szLineBuf[i] < '!' ;i ++ );		if (i == iLen ) continue;		if (szLineBuf[i] == '#') continue;		if (szLineBuf[i] == '[')		{			if (iInSession)		/*当前已在所需的Session中,但有遇到下一个session,故退出(不存在Key)*/			{				fclose(fp);				return 101;			}			/*取Session*/			for (j = i + 1;(j < iLen && szLineBuf[j] != ']');j ++);			memcpy(szSession,szLineBuf + i + 1,j - i - 1);			szSession[j - i - 1] = '\0';			if (strcmp(szSession,aszSession) == 0) iInSession = 1;			continue;		}		else if (iInSession)	/*是Key时,应已在Session中,否则continue*/		{			/*取Key*/			for (j = i ;(j < iLen && (szLineBuf[j] != ' ' && szLineBuf[j] != '=' ) && szLineBuf[j] >= '0');j ++);			memcpy(szKey,szLineBuf + i ,j - i );			szKey[j - i ] = '\0';			i = j;			if (strcmp(szKey,aszKey) == 0)	/*找到Key*/			{	/*取返回值*/				for (;i < iLen && (szLineBuf[i] < '-' || szLineBuf[i] == '=') ;i ++ );				for (j = i ;j < iLen && (szLineBuf[j] != '#') ;j ++);				memcpy(szText,szLineBuf + i ,j - i - 1);				rtrim(szText,0);				szText[j - i - 1] = '\0';				strcpy(aszText,szText);				iHaveKey = 1;				break;			}		}		else		{			continue;		}	}	fclose(fp);	if (iHaveKey)		return 0;	else				return 100;}void rtrim(char * aszData,int aiLen ){	int iLen,i;	iLen = strlen(aszData);	if (aiLen == 0)	{	/*//直接rtrim()*/		for (i = iLen -1 ;i >=0 ;i--)		{			if(aszData[i] != ' ')				return;			if(aszData[i] == ' ')				aszData[i] = '\0';		}		return;	}	if (iLen > aiLen)	{		for (i = iLen -1 ;i >=aiLen   ;i--)		{			/*//if(aszData[i] == ' ')*/				aszData[i] = '\0';		}	}	else	{		for (i = iLen;i<aiLen ;i++)			aszData[i] = ' ';		aszData[aiLen ] = '\0';	}}void RightTrim(char * szData){  int iEnd;  int i=0;  iEnd=strlen(szData);  for (i=strlen(szData)-1;i>=0 ;i--)  {	  if (szData[i]!=' ') 	  {		  iEnd=i;		  break;	  }  }    szData[strlen(szData)]=' ';  szData[iEnd+1]='\0';}static char base64_table[] =	{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',	  'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',	  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',	  'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',	  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0'	};static char base64_pad = '=';unsigned char *base64_encode(const unsigned char *str, int length, int *ret_length) {	const unsigned char *current = str;	int i = 0;	unsigned char *result = (unsigned char *)malloc(((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(char));	while (length > 2) { /* keep going until we have less than 24 bits */		result[i++] = base64_table[current[0] >> 2];		result[i++] = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];		result[i++] = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)];		result[i++] = base64_table[current[2] & 0x3f];		current += 3;		length -= 3; /* we just handle 3 octets of data */	}	/* now deal with the tail end of things */	if (length != 0) {		result[i++] = base64_table[current[0] >> 2];		if (length > 1) {			result[i++] = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];			result[i++] = base64_table[(current[1] & 0x0f) << 2];			result[i++] = base64_pad;		}		else {			result[i++] = base64_table[(current[0] & 0x03) << 4];			result[i++] = base64_pad;			result[i++] = base64_pad;		}	}	if(ret_length) {		*ret_length = i;	}	result[i] = '\0';	return result;}/* as above, but backwards. :) */unsigned char *base64_decode(const unsigned char *str, int length, int *ret_length) {	const unsigned char *current = str;	int ch, i = 0, j = 0, k;	/* this sucks for threaded environments */	static short reverse_table[256];	static int table_built;	unsigned char *result;	if (++table_built == 1) {		char *chp;		for(ch = 0; ch < 256; ch++) {			chp = strchr(base64_table, ch);			if(chp) {				reverse_table[ch] = chp - base64_table;			} else {				reverse_table[ch] = -1;			}		}	}	result = (unsigned char *)malloc(length + 1);	if (result == NULL) {		return NULL;	}	/* run through the whole string, converting as we go */	while ((ch = *current++) != '\0') {		if (ch == base64_pad) break;	    /* When Base64 gets POSTed, all pluses are interpreted as spaces.		   This line changes them back.  It's not exactly the Base64 spec,		   but it is completely compatible with it (the spec says that		   spaces are invalid).  This will also save many people considerable		   headache.  - Turadg Aleahmad <turadg@wise.berkeley.edu>	    */		if (ch == ' ') ch = '+'; 		ch = reverse_table[ch];		if (ch < 0) continue;		switch(i % 4) {		case 0:			result[j] = ch << 2;			break;		case 1:			result[j++] |= ch >> 4;			result[j] = (ch & 0x0f) << 4;			break;		case 2:			result[j++] |= ch >>2;			result[j] = (ch & 0x03) << 6;			break;		case 3:			result[j++] |= ch;			break;		}		i++;	}	k = j;	/* mop things up if we ended on a boundary */	if (ch == base64_pad) {		switch(i % 4) {		case 0:		case 1:			free(result);			return NULL;		case 2:			k++;		case 3:			result[k++] = 0;		}	}	if(ret_length) {		*ret_length = j;	}	result[k] = '\0';	return result;}

⌨️ 快捷键说明

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