ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/ihost/ihost.c
(Generate patch)

Comparing projects/cms/source/ihost/ihost.c (file contents):
Revision 1.6 by pajs, Sun May 12 17:33:21 2002 UTC vs.
Revision 1.8 by pajs, Mon May 13 11:01:27 2002 UTC

# Line 26 | Line 26 | typedef struct{
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 */
# Line 71 | Line 71 | int ihost_configure(ihost_state_t *ihost_state){
71  
72          /* Need to open 2 files, one for reading one for writing, as it gets confused if we only use 1 :) */
73          if ((fm_fd_r=fdopen(sd,"r")) == NULL){
74 <                errf("Failed to open stream (%m)");
74 >                errf("Failed to open read stream (%m)");
75                  return -1;
76          }
77  
78          if ((fm_fd_w=fdopen(dup(sd),"w")) == NULL){
79 <                errf("Failed to open stream (%m)");
79 >                errf("Failed to open write stream (%m)");
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;
# Line 120 | Line 116 | int ihost_configure(ihost_state_t *ihost_state){
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;
# Line 129 | Line 125 | int ihost_configure(ihost_state_t *ihost_state){
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;
# Line 138 | Line 134 | int ihost_configure(ihost_state_t *ihost_state){
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;
# Line 159 | Line 155 | int ihost_configure(ihost_state_t *ihost_state){
155                  errf("strdup failed (%m)");
156                  return -1;
157          }
158 <        reply=++reply_ptr;
158 >        reply=reply_ptr + 1;
159          reply_ptr=strchr(reply,';');
160          if (reply_ptr==NULL){
161                  errf("Incorrect data returned 2");
# Line 167 | Line 163 | int ihost_configure(ihost_state_t *ihost_state){
163          }
164          *reply_ptr='\0';
165          ihost_state->server_udp_port=atoi(reply);
166 <        reply=++reply_ptr;
166 >        reply=reply_ptr+1;
167          ihost_state->server_tcp_port=atoi(reply);
168          if ((ihost_state->server_tcp_port==0) || (ihost_state->server_udp_port==0)){
169                  errf("Incorrect data returned 3 ");
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;
177          }
178  
179          if(fclose(fm_fd_r) !=0){
180 <                errf("Failed to close FD (%m)");
180 >                errf("Failed to close read FD (%m)");
181                  return -1;
182          }
183          if(fclose(fm_fd_w) !=0){
184 <                errf("Failed to close FD (%m)");
184 >                errf("Failed to close write FD (%m)");
185                  return -1;
186          }
187  
# Line 231 | Line 227 | int heartbeat(ihost_state_t *ihost_state){
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");
# Line 259 | Line 254 | int heartbeat(ihost_state_t *ihost_state){
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;
273          }
274  
275          if(fclose(fm_fd_r) !=0){
276 <                errf("Failed to close FD (%m)");
276 >                errf("Failed to close read FD (%m)");
277                  return -1;
278          }
279          if(fclose(fm_fd_w) !=0){
280 <                errf("Failed to close FD (%m)");
280 >                errf("Failed to close write FD (%m)");
281                  return -1;
282          }
283  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines