#ifndef _SMS_H
#define _SMS_H

#include "inf71320_SMSLimits.h"



#define SRVR_MSG_Q 123412 /* server queue ID */

/* requests */
#define M_REQ_LOGIN 1 /* log into system */
#define M_REQ_LOGOUT 2 /* logout */
#define M_REQ_PASSWD 3 /* change password */
#define M_REQ_SUBSCR 4 /* subscribe to group */
#define M_REQ_UNSUBSCR 5 /* unsubscribe from group */
#define M_REQ_VIEWGRP 6 /* view group subscribers */ 
#define M_REQ_VIEWLOG 7 /* view logged users */
#define M_REQ_VIEWALL 8 /* view all users */
#define M_REQ_GETGRPS 9 /* get groups names */
#define M_REQ_SNDUSR 10 /* send SMS to user */
#define M_REQ_SNDGRP 11 /* send SMS to group */
/* msg */
#define M_MSG 0x100



#define REQUEST_LOGIN_LEN 10
#define REQUEST_DATA_LEN 10
#define REQUEST_MSG_LEN 255

typedef struct Request {
/* req type */
long m_type;
/* login */
char login[REQUEST_LOGIN_LEN+1];
/* passwd / new passwd / group / username */
char data[REQUEST_DATA_LEN+1];
/* mesydz */
char msg[REQUEST_MSG_LEN+1]; 
} Request;

/* We use struct Request as struct Message */
typedef struct Request Message;

/* acks */
#define M_ACK_LOGIN 1 /* log into system */
#define M_ACK_LOGOUT 2 /* logout */
#define M_ACK_PASSWD 3 /* change password */
#define M_ACK_SUBSCR 4 /* subscribe to group */
#define M_ACK_UNSUBSCR 5 /* unsubscribe from group */
#define M_ACK_VIEWGRP 6 /* view group subscribers */ 
#define M_ACK_VIEWLOG 7 /* view logged users */
#define M_ACK_VIEWALL 8 /* view all users */
#define M_ACK_GETGRPS 9 /* get groups names */
#define M_ACK_SNDUSR 10 /* send SMS to user */
#define M_ACK_SNDGRP 11 /* send SMS to group */

#define RESULT_OK 0 /* no error */
#define RESULT_ERROR 1


#define ACK_MSG_LEN 255

typedef struct Ack {
/* m_type = ack'ed req type */
long m_type;
/* errno or sth */
int result;
/* mesyd¿ */
char msg[ACK_MSG_LEN+1];
} Ack;

typedef struct {
	char name[LOGIN_LENGTH+1];
	char password[MAX_USERPASS_LENGTH+1];
	int logged;
	int queue;
	Request msgbuf[MAX_QUEUE_LENGTH];
	int bufcount;
	int failedlogins;
} userdata;

typedef struct {
	char name[MAX_GROUPNAME_LENGTH+1];
	userdata *users[MAX_USERS];
} groupdata;

#endif /* _SMS_H */
