Subversion Repositories SvarDOS

Rev

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

Rev 1559 Rev 1560
Line 41... Line 41...
41
 
41
 
42
 
42
 
43
#define PVER "20230823"
43
#define PVER "20230823"
44
#define PDATE "2021-2023"
44
#define PDATE "2021-2023"
45
 
45
 
46
#define HOSTNAME "svardos.org"
46
#define HOSTADDR "svardos.org"
47
#define HOSTADDR "141.95.149.60"
-
 
-
 
47
 
48
 
48
 
49
/* convenience define that outputs nls strings to screen (followed by CR/LF) */
49
/* convenience define that outputs nls strings to screen (followed by CR/LF) */
50
#define putsnls(x,y) puts(svarlang_strid((x << 8) | y))
50
#define putsnls(x,y) puts(svarlang_strid((x << 8) | y))
51
 
51
 
52
 
52
 
Line 260... Line 260...
260
  buffersz -= sizeof(*unchstate);
260
  buffersz -= sizeof(*unchstate);
261
  memset(unchstate, 0, sizeof(*unchstate));
261
  memset(unchstate, 0, sizeof(*unchstate));
262
 
262
 
263
  sock = net_connect(ipaddr, 80, tcpbuflen);
263
  sock = net_connect(ipaddr, 80, tcpbuflen);
264
  if (sock == NULL) {
264
  if (sock == NULL) {
265
    printf(svarlang_strid(0x0902), HOSTNAME); /* "ERROR: failed to connect to " HOSTNAME */
265
    printf(svarlang_strid(0x0902), HOSTADDR); /* "ERROR: failed to connect to " HOSTADDR */
266
    puts("");
266
    puts("");
267
    goto SHITQUIT;
267
    goto SHITQUIT;
268
  }
268
  }
269
 
269
 
270
  /* wait for net_connect() to actually connect */
270
  /* wait for net_connect() to actually connect */
271
  for (;;) {
271
  for (;;) {
272
    int connstate = net_isconnected(sock);
272
    int connstate = net_isconnected(sock);
273
    if (connstate > 0) break;
273
    if (connstate > 0) break;
274
    if (connstate < 0) {
274
    if (connstate < 0) {
275
      printf(svarlang_strid(0x0902), HOSTNAME); /* "ERROR: failed to connect to " HOSTNAME */
275
      printf(svarlang_strid(0x0902), HOSTADDR); /* "ERROR: failed to connect to " HOSTADDR */
276
      puts("");
276
      puts("");
277
      goto SHITQUIT;
277
      goto SHITQUIT;
278
    }
278
    }
279
    _asm int 28h;  /* DOS idle */
279
    _asm int 28h;  /* DOS idle */
280
  }
280
  }
281
 
281
 
282
  /* socket is connected - send the http request (MUST be HTTP/1.0 because I do not support chunked transfers!) */
282
  /* socket is connected - send the http request (MUST be HTTP/1.0 because I do not support chunked transfers!) */
283
  if (ispost) {
283
  if (ispost) {
284
    snprintf((char *)buffer, buffersz, "POST %s HTTP/1.1\r\nHOST: " HOSTNAME "\r\nUSER-AGENT: pkgnet/" PVER "\r\nTransfer-Encoding: chunked\r\nConnection: close\r\n\r\n", url);
284
    snprintf((char *)buffer, buffersz, "POST %s HTTP/1.1\r\nHOST: " HOSTADDR "\r\nUSER-AGENT: pkgnet/" PVER "\r\nTransfer-Encoding: chunked\r\nConnection: close\r\n\r\n", url);
285
  } else {
285
  } else {
286
    snprintf((char *)buffer, buffersz, "GET %s HTTP/1.1\r\nHOST: " HOSTNAME "\r\nUSER-AGENT: pkgnet/" PVER "\r\nConnection: close\r\n\r\n", url);
286
    snprintf((char *)buffer, buffersz, "GET %s HTTP/1.1\r\nHOST: " HOSTADDR "\r\nUSER-AGENT: pkgnet/" PVER "\r\nConnection: close\r\n\r\n", url);
287
  }
287
  }
288
 
288
 
289
  if (net_send(sock, buffer, strlen((char *)buffer)) != (int)strlen((char *)buffer)) {
289
  if (net_send(sock, buffer, strlen((char *)buffer)) != (int)strlen((char *)buffer)) {
290
    putsnls(9, 3); /* "ERROR: failed to send a HTTP query to remote server" */
290
    putsnls(9, 3); /* "ERROR: failed to send a HTTP query to remote server" */
291
    goto SHITQUIT;
291
    goto SHITQUIT;
Line 419... Line 419...
419
  unsigned short tcpbufsz = (16 * 1024);
419
  unsigned short tcpbufsz = (16 * 1024);
420
  int ispost; /* is the request a POST? */
420
  int ispost; /* is the request a POST? */
421
 
421
 
422
  struct {
422
  struct {
423
    unsigned char buffer[5000];
423
    unsigned char buffer[5000];
-
 
424
    char ipaddr[64];
424
    char url[64];
425
    char url[64];
425
    char outfname[16];
426
    char outfname[16];
426
  } *mem;
427
  } *mem;
427
 
428
 
428
 
429
 
Line 463... Line 464...
463
    return(1);
464
    return(1);
464
  }
465
  }
465
 
466
 
466
  puts(""); /* required because watt-32 likes to print out garbage sometimes ("configuring through DHCP...") */
467
  puts(""); /* required because watt-32 likes to print out garbage sometimes ("configuring through DHCP...") */
467
 
468
 
-
 
469
  if (net_dnsresolve(mem->ipaddr, HOSTADDR, 2) != 0) {
-
 
470
    putsnls(9, 12); /* "ERROR: DNS resolution failed" */
-
 
471
    return(1);
-
 
472
  }
-
 
473
 
468
  flen = htget(HOSTADDR, mem->url, mem->outfname, &bsum, ispost, mem->buffer, sizeof(mem->buffer), tcpbufsz);
474
  flen = htget(mem->ipaddr, mem->url, mem->outfname, &bsum, ispost, mem->buffer, sizeof(mem->buffer), tcpbufsz);
469
  if (flen < 1) return(1);
475
  if (flen < 1) return(1);
470
 
476
 
471
  if (mem->outfname[0] != 0) {
477
  if (mem->outfname[0] != 0) {
472
    /* print bsum, size, filename */
478
    /* print bsum, size, filename */
473
    printf(svarlang_strid(0x0200), flen >> 10, mem->outfname, bsum); /* Downloaded %ld KiB into %s (BSUM: %04X) */
479
    printf(svarlang_strid(0x0200), flen >> 10, mem->outfname, bsum); /* Downloaded %ld KiB into %s (BSUM: %04X) */