00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <stdio.h>
00030 #include <sys/types.h>
00031 #include <sys/socket.h>
00032 #include <netinet/in.h>
00033 #include <arpa/inet.h>
00034
00035 #define true 1
00036 #define false 0
00037
00038 #ifndef nothread
00039 #include <pthread.h>
00040 #endif
00041
00042
00043
00044
00045
00046
00047 #define authfile0 "./libcomm_md5auth.pwd"
00048
00049 #define authfile1 "/etc/libcomm_md5auth.pwd"
00050
00051 #define authfilefieldseperator ':'
00052
00053 #define authfilemaxlinelenght 4096
00054
00055 #define authrandomstringsize (int) 16
00056
00057 #define authmessagetype 65535
00058
00059
00060 struct AUTHINFO {
00061
00062 char *netname;
00063
00064 char *name;
00065
00066 char *passwd;
00067
00068 char *keyencrypt;
00069
00070 char *keydecrypt;
00071 };
00072
00073 int socket_md5auth(int fd, char *netname, char *name,
00074 struct AUTHINFO **locallogin,
00075 struct AUTHINFO **remotelogin);
00076 struct AUTHINFO *getauthinfo(char *netname, char *name);
00077
00078
00079
00080
00081 #ifndef nothread
00082 struct LIBCOMMPTHREADP {
00083 void (*socket_accept_do)(int fd, int id, char *pip,
00084 struct sockaddr_in their_addr);
00085
00086 pthread_t thrd_2;
00087 pthread_attr_t thrd_2_attr;
00088 int sockport;
00089 int id;
00090 };
00091 void socket_accept_thread(struct LIBCOMMPTHREADP *libcommpthreadp);
00092 int socket_accept(int sockport, int id,
00093 void (*socket_accept_do)(int fd, int id, char *pip,
00094 struct sockaddr_in their_addr));
00095 #endif
00096
00097
00098
00099 #ifndef nothread
00100 struct LIBCOMMPTHREADS {
00101 void (*block_call_do)(int fd, int id, unsigned int type,
00102 char *buf, unsigned int size, int term);
00103 void (*block_call_term)(int fd, int id);
00104
00105 pthread_t thrd_1;
00106 pthread_attr_t thrd_1_attr;
00107 int fd;
00108 int id;
00109 int term;
00110 };
00111 void thread1(struct LIBCOMMPTHREADS *libcommpthreads);
00112 int block_call(int fd, int id, int term,
00113 void (*block_call_do)(int fd, int id, unsigned int type,
00114 char *buf, unsigned int size,
00115 int term),
00116 void (*block_call_term)(int fd, int id));
00117 #endif
00118 char *block_receive_poll(int fd, unsigned int *type, char *buf,
00119 unsigned int *size, unsigned int maxsize,
00120 int term);
00121 char *block_receive(int fd, unsigned int *type, char *buf,
00122 unsigned int *size, unsigned int maxsize,
00123 int term);
00124 int block_receive_integer(int fd, unsigned int *recvi);
00125 int block_receive_nbytes(int fd, char *buf, int n);
00126
00127
00128
00129
00130 int block_send(int fd, unsigned int type, char *buf, unsigned int size);
00131
00132
00133
00134
00135 char *block_random(char *buf, int size);
00136
00137
00138
00139
00140 int socket_bind(int port, int cqueue);
00141
00142
00143
00144
00145 int socket_connect(char *host, int port);
00146
00147
00148
00149
00150 struct LINEMONITOR_THREAD_DATA {
00151 char *server;
00152 int port;
00153 int soft_msec;
00154 int hard_msec;
00155 int wait_msec;
00156 void (*linemonitor_exception)(char *server, int port, int type);
00157 int sock;
00158 };
00159
00160
00161 void linemonitor_server_thread(struct LINEMONITOR_THREAD_DATA
00162 *linemonitor_thread_data);
00163 int linemonitor_server(int port,
00164 int soft_msec, int hard_msec, int wait_msec,
00165 void (*linemonitor_exception)(char *server, int port,
00166 int type));
00167 void linemonitor_emergencystop(int sock);
00168 int linemonitor_thread(struct LINEMONITOR_THREAD_DATA
00169 *linemonitor_thread_data);
00170 int linemonitor(char *server, int port,
00171 int soft_msec, int hard_msec, int wait_msec,
00172 void (*linemonitor_exception)(char *server, int port,
00173 int type));
00174
00175