--- projects/cms/source/ihost/ihost.c 2002/05/12 17:33:21 1.6 +++ projects/cms/source/ihost/ihost.c 2002/05/13 09:22:02 1.7 @@ -26,9 +26,9 @@ typedef struct{ }ihost_state_t; -char* sock_comm(FILE *f_r, FILE *f_w, char* sendString){ +char* sock_comm(FILE *f_r, FILE *f_w, char *sendString){ char *reply; - fprintf(f_w, "%s", sendString); + fprintf(f_w, "%s\n", sendString); fflush(f_w); reply=fpgetline(f_r); /* Returns pointer to static buffer */ @@ -80,37 +80,33 @@ int ihost_configure(ihost_state_t *ihost_state){ return -1; } - reply=sock_comm(fm_fd_r, fm_fd_w, "STARTCONFIG\n"); + reply=sock_comm(fm_fd_r, fm_fd_w, "STARTCONFIG"); if ((reply==NULL) || (strncasecmp(reply, "OK", 2) != 0) ) { errf("Server error"); return -1; } - reply=sock_comm(fm_fd_r, fm_fd_w, "LASTMODIFIED\n"); + reply=sock_comm(fm_fd_r, fm_fd_w, "LASTMODIFIED"); if((reply== NULL) || (strncasecmp(reply, "ERROR", 5) ==0)){ errf("Server error (%m)"); return -1; } - if((ihost_state->last_modified=malloc((strlen(reply))+1)) == NULL){ - errf("malloc failed (%m)"); + if((ihost_state->last_modified=strdup(reply)) == NULL){ + errf("strdup failed (%m)"); return -1; } - strcpy(ihost_state->last_modified, reply); - ihost_state->last_modified[(strlen(ihost_state->last_modified))]='\n'; - reply=sock_comm(fm_fd_r, fm_fd_w, "FILELIST\n"); + reply=sock_comm(fm_fd_r, fm_fd_w, "FILELIST"); if((reply== NULL) || (strncasecmp(reply, "ERROR", 5) ==0)){ errf("Server error (%m)"); return -1; } - if((ihost_state->files_list=malloc((strlen(reply))+1)) == NULL){ - errf("malloc failed (%m)"); + if((ihost_state->files_list=strdup(reply)) == NULL){ + errf("strdup failed (%m)"); return -1; } - strcpy(ihost_state->files_list, reply); - ihost_state->files_list[(strlen(ihost_state->files_list))]='\n'; - reply=sock_comm(fm_fd_r, fm_fd_w, "FQDN\n"); + reply=sock_comm(fm_fd_r, fm_fd_w, "FQDN"); if((reply== NULL) || (strncasecmp(reply, "ERROR", 5)==0)){ errf("Server error (%m)"); return -1; @@ -120,7 +116,7 @@ int ihost_configure(ihost_state_t *ihost_state){ return -1; } - reply=sock_comm(fm_fd_r, fm_fd_w, "UDPUpdateTime\n"); + reply=sock_comm(fm_fd_r, fm_fd_w, "UDPUpdateTime"); if(reply== NULL){ errf("Server error (%m)"); return -1; @@ -129,7 +125,7 @@ int ihost_configure(ihost_state_t *ihost_state){ ihost_state->udp_update_time=atoi(reply); } - reply=sock_comm(fm_fd_r, fm_fd_w, "TCPUpdateTime\n"); + reply=sock_comm(fm_fd_r, fm_fd_w, "TCPUpdateTime"); if(reply== NULL){ errf("Server error (%m)"); return -1; @@ -138,13 +134,13 @@ int ihost_configure(ihost_state_t *ihost_state){ ihost_state->tcp_update_time=atoi(reply); } - reply=sock_comm(fm_fd_r, fm_fd_w, "ENDCONFIG\n"); + reply=sock_comm(fm_fd_r, fm_fd_w, "ENDCONFIG"); if(reply== NULL){ errf("Server error (%m)"); return -1; } - reply=sock_comm(fm_fd_r, fm_fd_w, "FILTER\n"); + reply=sock_comm(fm_fd_r, fm_fd_w, "FILTER"); if((reply== NULL) || (strncasecmp(reply, "ERROR", 5)==0)){ errf("Server error (%m)"); return -1; @@ -174,7 +170,7 @@ int ihost_configure(ihost_state_t *ihost_state){ return -1; } - reply=sock_comm(fm_fd_r, fm_fd_w, "END\n"); + reply=sock_comm(fm_fd_r, fm_fd_w, "END"); if((reply== NULL) || (strncasecmp(reply, "ERROR", 5) ==0 )){ errf("Server error (%m)"); return -1; @@ -231,19 +227,18 @@ int heartbeat(ihost_state_t *ihost_state){ return -1; } - reply=sock_comm(fm_fd_r, fm_fd_w, "HEARTBEAT\n"); + reply=sock_comm(fm_fd_r, fm_fd_w, "HEARTBEAT"); if ((reply==NULL) || (strncasecmp(reply, "ERROR", 5) == 0) ) { errf("Server error"); return -1; } if (ihost_state->fm_host!=NULL) free(ihost_state->fm_host); - reply=sock_comm(fm_fd_r, fm_fd_w, "CONFIG\n"); + reply=sock_comm(fm_fd_r, fm_fd_w, "CONFIG"); if ((reply==NULL) || (strncasecmp(reply, "ERROR", 5) == 0) ) { errf("Server error"); return -1; } - printf("filelist %s\n",ihost_state->files_list); reply=sock_comm(fm_fd_r, fm_fd_w, ihost_state->files_list); if ((reply==NULL) || (strncasecmp(reply, "OK", 2) != 0) ) { errf("Server error"); @@ -259,21 +254,19 @@ int heartbeat(ihost_state_t *ihost_state){ /* Means the config has changed */ exitcode=RECONFIGURE_RETURN_CODE; } - reply=sock_comm(fm_fd_r, fm_fd_w, "KEY\n"); + reply=sock_comm(fm_fd_r, fm_fd_w, "KEY"); if ((reply==NULL) || (strncasecmp(reply, "ERROR", 5) == 0) ) { errf("Server error"); return -1; } if (ihost_state->key!=NULL) free(ihost_state->key); - if((ihost_state->key=malloc(strlen(reply)+1)) == NULL){ - errf("malloc failed (%m)"); + if((ihost_state->key=strdup(reply)) == NULL){ + errf("strdup failed (%m)"); return -1; } - strcpy(ihost_state->key, reply); - ihost_state->key[(strlen(ihost_state->key))]='\n'; - reply=sock_comm(fm_fd_r, fm_fd_w, "ENDHEARTBEAT\n"); + reply=sock_comm(fm_fd_r, fm_fd_w, "ENDHEARTBEAT"); if((reply== NULL) || (strncasecmp(reply, "ERROR", 5) ==0 )){ errf("Server error (%m)"); return -1;