summaryrefslogtreecommitdiff
path: root/frontends/kolibrios/kolibri_http.h
blob: 9c9fea11ee8f23c3bd6b2f0029defe45c01e0257 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef KOLIBRI_HTTP_H
#define KOLIBRI_HTTP_H

/* kolibri_http.h: Defines C style functions for using the underlying Kolibri HTTP library.
   Defines functions for performing HTTP and related routines. 

   Interface intended to make life of C programmers easy in order to use the http.obj library
   which serves as the HTTP library for KolibriOS on top of the network stack.

   Read description of kolibri_http_init() for more information.
   Read documentation of procedures in http.asm ($SVN/kolibrios/programs/develop/libraries/http/)
   for even more information on the procedures.
      
   Copyright hidnplayr , GPL v2
   Copyright ashmew2 , GPL v2
*/


struct http_msg{
  /* Internal library use only */
  unsigned int socket;
  unsigned int flags;
  unsigned int write_ptr;
  unsigned int buffer_length;
  unsigned int chunk_ptr;
  unsigned int timestamp;

  /* Available for use */
  unsigned int status;
  unsigned int header_length;
  char * content_ptr;
  unsigned int content_length;
  unsigned int content_received;
  char http_header;
};

/* C - assembly wrapper to initialize and load the http.obj DLL at runtime */
extern int init_network_asm(void);

/* Procedures found in http.obj */
extern struct http_msg* (*http_get_asm)(char *, struct http_msg *, unsigned int, char *) __attribute__((__stdcall__));
extern int (*http_receive_asm)(struct http_msg *) __attribute__((__stdcall__));
extern void (*http_disconnect_asm)(struct http_msg *) __attribute__((__stdcall__));
extern void (*http_free_asm)(struct http_msg *) __attribute__((__stdcall__));
extern struct http_msg* (*http_head_asm)(char *, struct http_msg *, unsigned int, char *) __attribute__((__stdcall__));
extern struct http_msg* (*http_post_asm)(char *, struct http_msg *, unsigned int, char *, char *, unsigned int) __attribute__((__stdcall__));
extern int (*http_send_asm)(struct http_msg *, char *, unsigned int) __attribute__((__stdcall__));
extern char * (*http_find_header_field_asm)(struct http_msg *, char *) __attribute__((__stdcall__));
extern char * (*http_escape_asm)(char *, unsigned int) __attribute__((__stdcall__));
extern char * (*http_unescape_asm)(char *, unsigned int) __attribute__((__stdcall__));

/* A C Programmer calls *ONLY* this function for initializing http.obj library at runtime */
/* After successfully returning from kolibri_http_init(), all http_*_asm functions can be used. */
/* Returns 0 on successful init */

int kolibri_http_init(void);

#define HTTP_HTTP11             1 << 0
#define HTTP_GOT_HEADER         1 << 1
#define HTTP_GOT_ALL_DATA       1 << 2
#define HTTP_CONTENT_LENGTH     1 << 3
#define HTTP_CHUNKED            1 << 4
#define HTTP_CONNECTED          1 << 5

/* Flags for user options */
#define HTTP_KEEPALIVE          1 << 8
#define HTTP_STREAM             1 << 9
#define HTTP_REUSE_BUFFER       1 << 10
#define HTTP_BLOCK              1 << 11

/* Flags for HTTP Errors */
#define HTTP_INVALID_HEADER     1 << 16
#define HTTP_NO_RAM             1 << 17
#define HTTP_SOCKET_ERROR       1 << 18
#define HTTP_TIMEOUT_ERROR      1 << 19
#define HTTP_TRANSFER_FAILED    1 << 20

#define HTTP_ERRORS             0x001F0000 /* (1 << 16) | (1 << 17) | (1 << 18) | (1 << 19) | (1 << 20) */

void http_send(struct http_msg *handle, char *data, int remaining_length);

#endif /* KOLIBRI_HTTP_H */