This repository has been archived by the owner on Dec 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
118 lines (98 loc) · 2.09 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
** Fichero: utils.h
** Autores:
** Carlos Manjón García
** Miguel Sánchez González
*/
#ifndef __UTILS_H
#define __UTILS_H
#include <sys/socket.h>
#define ADDRNOTFOUND 0xffffffff /* value returned for unknown host */
#define HOSTLEN 512
#define TAM_BUFFER 512 /* maximum size of packets to be received for tcp */
#define TAM_ORDENES 20
#define PUERTO 21707
#define RETRIES 5 /* number of times to retry before givin up */
#define TIMEOUT 6
#define MAXCLIENTS 64
/* Error numbers */
#define ERR_NICKNAME 433
#define ERR_NOREGISTERED 460
#define ERR_NOVALIDUSER 461
#define ERR_ALREADYREGISTRED 462
#define ERR_ALREADYREGISTREDINCHANEL 463
#define ERR_NOSUCHNICK 401
#define ERR_NOREGISTEREDINCHANEL 402
#define ERR_NOSUCHCHANNEL 403
/*
* Declaraciones de tipos de datos.
*/
#ifndef __NODE_DATA
#define __NODE_DATA
typedef void * nodeData;
#endif
#ifndef __NODE
#define __NODE
typedef struct Node {
nodeData data;
struct Node * next;
} Node;
#endif
#ifndef __LIST
#define __LIST
typedef struct List {
Node * raiz;
Node * ultimo;
} List;
#endif
#ifndef __ID_POSITION
#define __ID_POSITION
typedef Node * idPosition;
#endif
#ifndef __BUFFER_TYPES
#define __BUFFER_TYPES
typedef char buffer[TAM_BUFFER];
typedef char ordenes[10];
typedef char arg_1[10];
typedef char arg_2[256];
#endif
#ifndef __DATOS_HILO
#define __DATOS_HILO
typedef struct DatosHilo {
int idSoc;
int argc;
char fichero[100];
} DatosHilo;
#endif
#ifndef __DATOS_HILO_SERVER
#define __DATOS_HILO_SERVER
typedef struct DatosHiloServer {
int idSoc;
struct sockaddr_in * addr;
buffer buff;
List *usuarios;
List *canales;
} DatosHiloServer;
#endif
#ifndef __BASE_DATOS
#define __BASE_DATOS
typedef char nick[10];
typedef char nombre[200];
typedef struct datosUsuario {
nick nickName;
nombre nombreReal;
int idSock;
struct sockaddr_in * addr;
} datosUsuario;
typedef struct datosCanal {
nombre nombreCanal;
List nicks;
} datosCanal;
#endif
/*
* Prototipos de funciones.
*/
void escribirFichero(const char * fichero, char * datos);
void leerFichero(const char * fichero, buffer ** datos, int * nRead);
char * timeString();
#endif