Subversion Repositories SvarDOS

Rev

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

Rev 342 Rev 344
Line 25... Line 25...
25
 * DEALINGS IN THE SOFTWARE.
25
 * DEALINGS IN THE SOFTWARE.
26
 *
26
 *
27
 * http://svardos.osdn.io
27
 * http://svardos.osdn.io
28
 */
28
 */
29
 
29
 
-
 
30
#include <direct.h> /* opendir() and friends */
30
#include <stdio.h>
31
#include <stdio.h>
31
#include <stdlib.h>
32
#include <stdlib.h>
32
#include <string.h>
33
#include <string.h>
33
#include <time.h>
34
#include <time.h>
34
 
35
 
35
#include "net.h"
36
#include "net.h"
36
#include "unchunk.h"
37
#include "unchunk.h"
37
 
38
 
-
 
39
#include "../pkg/lsm.h"
-
 
40
 
-
 
41
 
38
#define PVER "20210903"
42
#define PVER "20210903"
39
#define PDATE "2021"
43
#define PDATE "2021"
40
 
44
 
41
#define HOSTADDR "svardos.osdn.io"
45
#define HOSTADDR "svardos.osdn.io"
42
 
46
 
Line 169... Line 173...
169
 
173
 
170
/* provides body data of the POST query for checkup actions
174
/* provides body data of the POST query for checkup actions
171
   fills buff with data and returns data length.
175
   fills buff with data and returns data length.
172
   must be called repeateadly until zero-lengh is returned */
176
   must be called repeateadly until zero-lengh is returned */
173
static unsigned short checkupdata(char *buff) {
177
static unsigned short checkupdata(char *buff) {
-
 
178
  static char *dosdir = NULL;
-
 
179
  static DIR *dp;
-
 
180
  static struct dirent *ep;
-
 
181
 
-
 
182
  /* make sure I know %DOSDIR% */
-
 
183
  if (dosdir == NULL) {
-
 
184
    dosdir = getenv("DOSDIR");
-
 
185
    if ((dosdir == NULL) || (dosdir[0] == 0)) {
-
 
186
      puts("ERROR: %DOSDIR% not set");
174
  buff[0] = 0;
187
      return(0);
-
 
188
    }
-
 
189
  }
-
 
190
 
-
 
191
  /* if first call, open the package directory */
-
 
192
  if (dp == NULL) {
-
 
193
    sprintf(buff, "%s\\packages", dosdir);
-
 
194
    dp = opendir(buff);
-
 
195
    if (dp == NULL) {
-
 
196
      puts("ERROR: Could not access %DOSDIR%\\packages directory");
-
 
197
      return(0);
-
 
198
    }
-
 
199
  }
-
 
200
 
-
 
201
  for (;;) {
-
 
202
    int tlen;
-
 
203
    char ver[16];
-
 
204
    ep = readdir(dp);   /* readdir() result must never be freed (statically allocated) */
-
 
205
    if (ep == NULL) {   /* no more entries */
-
 
206
      closedir(dp);
175
  return(0);
207
      return(0);
-
 
208
    }
-
 
209
 
-
 
210
    tlen = strlen(ep->d_name);
-
 
211
    if (tlen < 4) continue; /* files must be at least 5 bytes long ("x.lst") */
-
 
212
    if (strcasecmp(ep->d_name + tlen - 4, ".lst") != 0) continue;  /* if not an .lst file, skip it silently */
-
 
213
    ep->d_name[tlen - 4] = 0; /* trim out the ".lst" suffix */
-
 
214
 
-
 
215
    /* load the metadata from %DOSDIR\APPINFO\*.lsm */
-
 
216
    sprintf(buff, "%s\\appinfo\\%s.lsm", dosdir, ep->d_name);
-
 
217
    readlsm(buff, ver, sizeof(ver));
-
 
218
 
-
 
219
    return(sprintf(buff, "%s %s\n", ep->d_name, ver));
-
 
220
  }
176
}
221
}
177
 
222
 
178
 
223
 
179
/* fetch http data from ipaddr using url
224
/* fetch http data from ipaddr using url
180
 * write result to file outfname if not null, or print to stdout otherwise
225
 * write result to file outfname if not null, or print to stdout otherwise
Line 228... Line 273...
228
  /* send chunked data for POST queries */
273
  /* send chunked data for POST queries */
229
  if (ispost) {
274
  if (ispost) {
230
    unsigned short blen;
275
    unsigned short blen;
231
    int hlen;
276
    int hlen;
232
    char *hbuf = (char *)buffer + buffersz - 16;
277
    char *hbuf = (char *)buffer + buffersz - 16;
233
    for (;;) {
278
    do {
234
      blen = checkupdata((char *)buffer);
279
      blen = checkupdata((char *)buffer);
235
      if (blen == 0) { /* last item contains the message trailer */
280
      if (blen == 0) { /* last item contains the message trailer */
236
        hlen = sprintf(hbuf, "0\r\n\r\n");
281
        hlen = sprintf(hbuf, "0\r\n");
237
      } else {
282
      } else {
238
        hlen = sprintf(hbuf, "%X\r\n", blen);
283
        hlen = sprintf(hbuf, "%X\r\n", blen);
239
      }
284
      }
240
      if (net_send(sock, hbuf, hlen) != hlen) {
285
      if (net_send(sock, hbuf, hlen) != hlen) {
241
        puts("ERROR: failed to send POST data to remote server");
286
        puts("ERROR: failed to send POST data to remote server");
242
        goto SHITQUIT;
287
        goto SHITQUIT;
243
      }
288
      }
-
 
289
      /* add trailing CR/LF to buffer as required by chunked mode */
-
 
290
      buffer[blen++] = '\r';
244
      if (blen == 0) break;
291
      buffer[blen++] = '\n';
245
      if (net_send(sock, buffer, blen) != blen) {
292
      if (net_send(sock, buffer, blen) != blen) {
246
        puts("ERROR: failed to send POST data to remote server");
293
        puts("ERROR: failed to send POST data to remote server");
247
        goto SHITQUIT;
294
        goto SHITQUIT;
248
      }
295
      }
249
    }
296
    } while (blen != 2);
250
  }
297
  }
251
 
298
 
252
  /* receive and process HTTP headers */
299
  /* receive and process HTTP headers */
253
  byteread = htget_headers(buffer, buffersz, sock, &httpcode, &ischunked);
300
  byteread = htget_headers(buffer, buffersz, sock, &httpcode, &ischunked);
254
 
301