| 26 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 27 |  | }ihost_state_t; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 28 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 29 | < | char* sock_comm(FILE *f_r, FILE *f_w, char* sendString){ | 
 
 
 
 
 
 
 
 
 | 29 | > | char* sock_comm(FILE *f_r, FILE *f_w, char *sendString){ | 
 
 
 
 
 
 
 
 
 
 
 | 30 |  | char *reply; | 
 
 
 
 
 
 
 
 
 
 
 | 31 | < | fprintf(f_w, "%s", sendString); | 
 
 
 
 
 
 
 
 
 | 31 | > | fprintf(f_w, "%s\n", sendString); | 
 
 
 
 
 
 
 
 
 
 
 | 32 |  | fflush(f_w); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 33 |  | reply=fpgetline(f_r); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 34 |  | /* Returns pointer to static buffer */ | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 80 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 81 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 82 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 83 | < | reply=sock_comm(fm_fd_r, fm_fd_w, "STARTCONFIG\n"); | 
 
 
 
 
 
 
 
 
 | 83 | > | reply=sock_comm(fm_fd_r, fm_fd_w, "STARTCONFIG"); | 
 
 
 
 
 
 
 
 
 
 
 | 84 |  | if ((reply==NULL) || (strncasecmp(reply, "OK", 2) != 0) ) { | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 85 |  | errf("Server error"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 86 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 87 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 88 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 89 | < | reply=sock_comm(fm_fd_r, fm_fd_w, "LASTMODIFIED\n"); | 
 
 
 
 
 
 
 
 
 | 89 | > | reply=sock_comm(fm_fd_r, fm_fd_w, "LASTMODIFIED"); | 
 
 
 
 
 
 
 
 
 
 
 | 90 |  | if((reply== NULL) || (strncasecmp(reply, "ERROR", 5) ==0)){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 91 |  | errf("Server error (%m)"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 92 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 93 |  | } | 
 
 
 
 
 
 
 
 
 
 
 | 94 | < | if((ihost_state->last_modified=malloc((strlen(reply))+1)) == NULL){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 95 | < | errf("malloc failed (%m)"); | 
 
 
 
 
 
 
 
 
 | 94 | > | if((ihost_state->last_modified=strdup(reply)) == NULL){ | 
 
 
 
 
 | 95 | > | errf("strdup failed (%m)"); | 
 
 
 
 
 
 
 
 
 
 
 | 96 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 97 |  | } | 
 
 
 
 
 
 
 
 
 | 98 | – | strcpy(ihost_state->last_modified, reply); | 
 
 
 
 
 
 
 
 
 | 99 | – | ihost_state->last_modified[(strlen(ihost_state->last_modified))]='\n'; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 98 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 99 | < | reply=sock_comm(fm_fd_r, fm_fd_w, "FILELIST\n"); | 
 
 
 
 
 
 
 
 
 | 99 | > | reply=sock_comm(fm_fd_r, fm_fd_w, "FILELIST"); | 
 
 
 
 
 
 
 
 
 
 
 | 100 |  | if((reply== NULL) || (strncasecmp(reply, "ERROR", 5) ==0)){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 101 |  | errf("Server error (%m)"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 102 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 103 |  | } | 
 
 
 
 
 
 
 
 
 
 
 | 104 | < | if((ihost_state->files_list=malloc((strlen(reply))+1)) == NULL){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 105 | < | errf("malloc failed (%m)"); | 
 
 
 
 
 
 
 
 
 | 104 | > | if((ihost_state->files_list=strdup(reply)) == NULL){ | 
 
 
 
 
 | 105 | > | errf("strdup failed (%m)"); | 
 
 
 
 
 
 
 
 
 
 
 | 106 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 107 |  | } | 
 
 
 
 
 
 
 
 
 | 110 | – | strcpy(ihost_state->files_list, reply); | 
 
 
 
 
 
 
 
 
 | 111 | – | ihost_state->files_list[(strlen(ihost_state->files_list))]='\n'; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 108 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 109 | < | reply=sock_comm(fm_fd_r, fm_fd_w, "FQDN\n"); | 
 
 
 
 
 
 
 
 
 | 109 | > | reply=sock_comm(fm_fd_r, fm_fd_w, "FQDN"); | 
 
 
 
 
 
 
 
 
 
 
 | 110 |  | if((reply== NULL) || (strncasecmp(reply, "ERROR", 5)==0)){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 111 |  | errf("Server error (%m)"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 112 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 116 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 117 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 118 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 119 | < | reply=sock_comm(fm_fd_r, fm_fd_w, "UDPUpdateTime\n"); | 
 
 
 
 
 
 
 
 
 | 119 | > | reply=sock_comm(fm_fd_r, fm_fd_w, "UDPUpdateTime"); | 
 
 
 
 
 
 
 
 
 
 
 | 120 |  | if(reply== NULL){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 121 |  | errf("Server error (%m)"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 122 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 125 |  | ihost_state->udp_update_time=atoi(reply); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 126 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 127 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 128 | < | reply=sock_comm(fm_fd_r, fm_fd_w, "TCPUpdateTime\n"); | 
 
 
 
 
 
 
 
 
 | 128 | > | reply=sock_comm(fm_fd_r, fm_fd_w, "TCPUpdateTime"); | 
 
 
 
 
 
 
 
 
 
 
 | 129 |  | if(reply== NULL){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 130 |  | errf("Server error (%m)"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 131 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 134 |  | ihost_state->tcp_update_time=atoi(reply); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 135 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 136 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 137 | < | reply=sock_comm(fm_fd_r, fm_fd_w, "ENDCONFIG\n"); | 
 
 
 
 
 
 
 
 
 | 137 | > | reply=sock_comm(fm_fd_r, fm_fd_w, "ENDCONFIG"); | 
 
 
 
 
 
 
 
 
 
 
 | 138 |  | if(reply== NULL){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 139 |  | errf("Server error (%m)"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 140 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 141 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 142 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 143 | < | reply=sock_comm(fm_fd_r, fm_fd_w, "FILTER\n"); | 
 
 
 
 
 
 
 
 
 | 143 | > | reply=sock_comm(fm_fd_r, fm_fd_w, "FILTER"); | 
 
 
 
 
 
 
 
 
 
 
 | 144 |  | if((reply== NULL) || (strncasecmp(reply, "ERROR", 5)==0)){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 145 |  | errf("Server error (%m)"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 146 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 170 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 171 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 172 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 173 | < | reply=sock_comm(fm_fd_r, fm_fd_w, "END\n"); | 
 
 
 
 
 
 
 
 
 | 173 | > | reply=sock_comm(fm_fd_r, fm_fd_w, "END"); | 
 
 
 
 
 
 
 
 
 
 
 | 174 |  | if((reply== NULL) || (strncasecmp(reply, "ERROR", 5) ==0 )){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 175 |  | errf("Server error (%m)"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 176 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 227 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 228 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 229 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 230 | < | reply=sock_comm(fm_fd_r, fm_fd_w, "HEARTBEAT\n"); | 
 
 
 
 
 
 
 
 
 | 230 | > | reply=sock_comm(fm_fd_r, fm_fd_w, "HEARTBEAT"); | 
 
 
 
 
 
 
 
 
 
 
 | 231 |  | if ((reply==NULL) || (strncasecmp(reply, "ERROR", 5) == 0) ) { | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 232 |  | errf("Server error"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 233 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 234 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 235 |  | if (ihost_state->fm_host!=NULL) free(ihost_state->fm_host); | 
 
 
 
 
 
 
 
 
 
 
 | 236 | < | reply=sock_comm(fm_fd_r, fm_fd_w, "CONFIG\n"); | 
 
 
 
 
 
 
 
 
 | 236 | > | reply=sock_comm(fm_fd_r, fm_fd_w, "CONFIG"); | 
 
 
 
 
 
 
 
 
 
 
 | 237 |  | if ((reply==NULL) || (strncasecmp(reply, "ERROR", 5) == 0) ) { | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 238 |  | errf("Server error"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 239 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 240 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 241 |  |  | 
 
 
 
 
 
 
 
 
 | 246 | – | printf("filelist %s\n",ihost_state->files_list); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 242 |  | reply=sock_comm(fm_fd_r, fm_fd_w, ihost_state->files_list); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 243 |  | if ((reply==NULL) || (strncasecmp(reply, "OK", 2) != 0) ) { | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 244 |  | errf("Server error"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 254 |  | /* Means the config has changed */ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 255 |  | exitcode=RECONFIGURE_RETURN_CODE; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 256 |  | } | 
 
 
 
 
 
 
 
 
 
 
 | 257 | < | reply=sock_comm(fm_fd_r, fm_fd_w, "KEY\n"); | 
 
 
 
 
 
 
 
 
 | 257 | > | reply=sock_comm(fm_fd_r, fm_fd_w, "KEY"); | 
 
 
 
 
 
 
 
 
 
 
 | 258 |  | if ((reply==NULL) || (strncasecmp(reply, "ERROR", 5) == 0) ) { | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 259 |  | errf("Server error"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 260 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 261 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 262 |  | if (ihost_state->key!=NULL) free(ihost_state->key); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 263 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 264 | < | if((ihost_state->key=malloc(strlen(reply)+1)) == NULL){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 265 | < | errf("malloc failed (%m)"); | 
 
 
 
 
 
 
 
 
 | 264 | > | if((ihost_state->key=strdup(reply)) == NULL){ | 
 
 
 
 
 | 265 | > | errf("strdup failed (%m)"); | 
 
 
 
 
 
 
 
 
 
 
 | 266 |  | return -1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 267 |  | } | 
 
 
 
 
 
 
 
 
 | 273 | – | strcpy(ihost_state->key, reply); | 
 
 
 
 
 
 
 
 
 | 274 | – | ihost_state->key[(strlen(ihost_state->key))]='\n'; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 268 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 269 | < | reply=sock_comm(fm_fd_r, fm_fd_w, "ENDHEARTBEAT\n"); | 
 
 
 
 
 
 
 
 
 | 269 | > | reply=sock_comm(fm_fd_r, fm_fd_w, "ENDHEARTBEAT"); | 
 
 
 
 
 
 
 
 
 
 
 | 270 |  | if((reply== NULL) || (strncasecmp(reply, "ERROR", 5) ==0 )){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 271 |  | errf("Server error (%m)"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 272 |  | return -1; |