Subversion Repositories SvarDOS

Rev

Rev 333 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 333 Rev 336
Line 164... Line 164...
164
    }
164
    }
165
 
165
 
166
    if (byteread > 0) {
166
    if (byteread > 0) {
167
      buffer[byteread] = 0;
167
      buffer[byteread] = 0;
168
      lastactivity = time(NULL);
168
      lastactivity = time(NULL);
169
      /* do I know the http code yet? */
169
      /* are headers done already? */
170
      if (httpcode < 0) {
170
      if (headersdone == 0) {
-
 
171
        if (httpcode < 0) { /* do I know the http code yet? */
171
        int spc;
172
          int spc;
172
        /* find the first space (HTTP/1.1 200 OK) */
173
          /* find the first space (HTTP/1.1 200 OK) */
173
        for (spc = 0; spc < 16; spc++) {
174
          for (spc = 0; spc < 16; spc++) {
174
          if (buffer[spc] == ' ') break;
175
            if (buffer[spc] == ' ') break;
175
          if (buffer[spc] == 0) break;
176
            if (buffer[spc] == 0) break;
176
        }
177
          }
177
        if (buffer[spc] == 0) continue; /* not enough data received */
178
          if (buffer[spc] == 0) continue; /* not enough data received */
178
        if (buffer[spc] != ' ') {
179
          if (buffer[spc] != ' ') {
179
          puts("ERROR: server answered with invalid HTTP");
180
            puts("ERROR: server answered with invalid HTTP");
180
          goto SHITQUIT;
-
 
181
        }
-
 
182
        httpcode = atoi((char *)(buffer + spc + 1));
-
 
183
        /* on error, the answer should be always printed on screen */
-
 
184
        if ((httpcode == 200) && (*outfname != 0)) {
-
 
185
          fd = fopen(outfname, "wb");
-
 
186
          if (fd == NULL) {
-
 
187
            printf("ERROR: failed to create file %s", outfname);
-
 
188
            puts("");
-
 
189
            goto SHITQUIT;
181
            goto SHITQUIT;
190
          }
182
          }
-
 
183
          httpcode = atoi((char *)(buffer + spc + 1));
-
 
184
          /* on error, the answer should be always printed on screen */
-
 
185
          if ((httpcode == 200) && (*outfname != 0)) {
-
 
186
            fd = fopen(outfname, "wb");
-
 
187
            if (fd == NULL) {
-
 
188
              printf("ERROR: failed to create file %s", outfname);
-
 
189
              puts("");
-
 
190
              goto SHITQUIT;
-
 
191
            }
-
 
192
          }
191
        }
193
        }
192
      }
-
 
193
      /* skip headers: look for \r\n\r\n or \n\n within the stream */
194
        /* skip headers: look for \r\n\r\n or \n\n within the stream */
194
      if (headersdone == 0) {
-
 
195
        byteread = detecthttpheadersend(buffer, byteread);
195
        byteread = detecthttpheadersend(buffer, byteread);
196
        headersdone = 1;
196
        headersdone = 1; /* assumes ALL headers are contained in the first packet TODO FIXME */
197
        if (byteread == 0) continue;
197
        if (byteread == 0) continue;
198
      }
198
      }
199
      /* if downloading to file, write stuff to disk */
199
      /* if downloading to file, write stuff to disk */
200
      if (fd != NULL) {
200
      if (fd != NULL) {
201
        int i;
201
        int i;