本地银行
结构体 account.h
#ifndef _ACCOUNT_H__
#define _ACCOUNT_H__
enum OPER{
OPEN=1,LOGIN,GETM,SAVEM,MOVEM,PASS,CHECK,DEST,QUIT};
#define CARD_NO_LEN 16
#define PASS_LEN 6
#define NAME_LEN 48
#define ID_LEN 18
#define TEL_LEN 12
typedef struct Account{
char cardNo[CARD_NO_LEN];
char pass[PASS_LEN];
char name[NAME_LEN];
char id[ID_LEN];
char tel[TEL_LEN];
float balance;
}Account;
typedef struct OpenRet{
int status;
char cardNo[CARD_NO_LEN];
}OpenRet;
typedef struct Login{
char cardNo[CARD_NO_LEN];
char pass[PASS_LEN];
}Login;
typedef struct LoginRet{
int status;
struct Account act;
}LoginRet;
typedef struct GetM{
float money;
}GetM;
typedef struct GetMRet{
int status;
float balance;
}GetMRet;
typedef struct SaveM{
float money;
}SaveM;
typedef struct SaveMRet{
int status;
float balance;
}SaveMRet;
typedef struct MoveM{
char destCardNo[CARD_NO_LEN];
float money;
}MoveM;
typedef struct MoveMRet{
int status;
float balance;
}MoveMRet;
typedef struct Pass{
char pass[PASS_LEN];
}Pass;
typedef struct Ret{
int status;
}Ret;
#endif
business.h
#ifndef _BUSINESS_H__
#define _BUSINESS_H__
#include <stdio.h>
#include "msgque.h"
#include "account.h"
size_t business_entry(struct Msg *msg);
#endif
business.c
#include "business.h"
#include "log.h"
#include "open.h"
#include "login.h"
#include "run.h"
size_t business_entry(struct Msg *msg)
{
LOG_ERROR("msgtype:%d\n",msg->type);
static Account *pact = NULL;
size_t size = 0;
if(pact == NULL)
{
switch(msg->type)
{
case OPEN: msg_open();
case LOGIN: msg_login();
default:
break;
}
}
else
{
switch(msg->type)
{
case GETM: msg_getm(struct Msg *msg);
case SAVEM:msg_savem(struct Msg *msg);
case MOVEM:msg_movem(struct Msg *msg);
case PASS:msg_pass(struct Msg *msg);
case DEST:msg_dest(struct Msg *msg);
case CHECK:msg_check(struct Msg *msg);
case QUIT:
pact = NULL;
default:
}
}
return size;
}
login.h
#ifndef _LOGIN_H__
#define _LOGIN_H__
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <fcntl.h>
#include <signal.h>
#include "account.h"
#endif
login.c
#include "login.h"
#include "useroper.h"
static int msgid1;
static int msgid2;
msgid1 = msg_create(PATH,PRO1);
msgid2 = msg_create(PATH,PRO2);
while(1)
{
struct Msg msg={
};
msgrcv(msgid1,&msg,sizeof(Msg),7,0);
struct Account account;
Account *account = (Account