Subversion Repositories Kolibri OS

Rev

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

Rev 7925 Rev 8549
Line 1... Line 1...
1
/*
1
/*
2
    This is adapded thunk for console.obj sys library
2
    This is adapded thunk for http.obj sys library
3
    .h is equal to svn:\programs\develop\libraries\http\http_en.txt 
3
    .h is equal to svn:\\programs\develop\libraries\http\http_en.txt 
Line 4... Line 4...
4
 
4
 
5
    Adapted for TCC's dynamic API by Magomed Kostoev, 2020
5
    Adapted for TCC's dynamic API by Magomed Kostoev, 2020
Line 6... Line 6...
6
*/
6
*/
7
 
7
 
Line 8... Line 8...
8
#ifndef __kos__http__h________
8
#ifndef _HTTP_H_
9
#define __kos__http__h________
9
#define _HTTP_H_
Line 10... Line 10...
10
 
10
 
11
#define cdecl   __attribute__ ((cdecl))
11
#define cdecl   __attribute__ ((cdecl))
-
 
12
#define stdcall __attribute__ ((stdcall))
12
#define stdcall __attribute__ ((stdcall))
13
 
13
 
14
// Bitflags for http_msg.flags
14
// Bitflags for http_msg.flags
15
// status
15
// status
16
 
16
#define HTTP_FLAG_HTTP11             1 << 0
17
#define HTTP_FLAG_HTTP11             1 << 0
Line 63... Line 64...
63
    unsigned status;           // HTTP status
64
    unsigned status;           // HTTP status
64
    unsigned header_length;    // length of HTTP header
65
    unsigned header_length;    // length of HTTP header
65
    void *   content_ptr;      // ptr to content
66
    void *   content_ptr;      // ptr to content
66
    unsigned content_length;   // total length of HTTP content
67
    unsigned content_length;   // total length of HTTP content
67
    unsigned content_received; // number of currently received content bytes
68
    unsigned content_received; // number of currently received content bytes
68
    char http_header[1];
69
    char *   http_header;
69
} http_msg;
70
} http_msg;
Line 70... Line 71...
70
 
71
 
71
/*
72
/*
72
    url = pointer to ASCIIZ URL
73
    url = pointer to ASCIIZ URL
Line 75... Line 76...
75
    add_header = pointer to ASCIIZ additional header parameters, or null for none.
76
    add_header = pointer to ASCIIZ additional header parameters, or null for none.
76
    Every additional parameter must end with CR LF bytes, including the last line.
77
    Every additional parameter must end with CR LF bytes, including the last line.
77
    Initiates a HTTP connection, using 'GET' method.
78
    Initiates a HTTP connection, using 'GET' method.
78
    Returns NULL on error, identifier otherwise.
79
    Returns NULL on error, identifier otherwise.
79
*/
80
*/
80
extern http_msg * stdcall (*get)(const char *url, http_msg *identifier, unsigned flags, const char *add_header);
81
extern http_msg * stdcall (*http_get)(const char *url, http_msg *identifier, unsigned flags, const char *add_header);
Line 81... Line 82...
81
 
82
 
82
/*
83
/*
83
    url = pointer to ASCIIZ URL
84
    url = pointer to ASCIIZ URL
84
    identifier = identifier of previously opened connection (keep-alive), or 0 to open a new one.
85
    identifier = identifier of previously opened connection (keep-alive), or 0 to open a new one.
85
    flags = bit flags (see end of this document).
86
    flags = bit flags (see end of this document).
86
    add_header = pointer to ASCIIZ additional header parameters, or null for none.    
87
    add_header = pointer to ASCIIZ additional header parameters, or null for none.    
87
    Every additional parameter must end with CR LF bytes, including the last line.    
88
    Every additional parameter must end with CR LF bytes, including the last line.    
88
    Initiate a HTTP connection, using 'HEAD' method.
89
    Initiate a HTTP connection, using 'HEAD' method.
89
    Returns NULL on error, identifier otherwise.
90
    Returns NULL on error, identifier otherwise.
90
*/
91
*/
Line 91... Line 92...
91
extern http_msg * stdcall (*head)(const char *url, http_msg *identifier, unsigned flags, const char *add_header);
92
extern http_msg * stdcall (*http_head)(const char *url, http_msg *identifier, unsigned flags, const char *add_header);
92
 
93
 
93
/*
94
/*
94
    url = pointer to ASCIIZ URL
95
    url = pointer to ASCIIZ URL
Line 101... Line 102...
101
    Initiate a HTTP connection, using 'POST' method.
102
    Initiate a HTTP connection, using 'POST' method.
102
    The content itself must be send to the socket (which you can find in the structure),
103
    The content itself must be send to the socket (which you can find in the structure),
103
    using system function 75, 6.
104
    using system function 75, 6.
104
    Returns 0 on error, identifier otherwise
105
    Returns 0 on error, identifier otherwise
105
*/
106
*/
106
extern http_msg * stdcall (*post)(const char *url, http_msg *identifier, unsigned flags, const char *add_header,
107
extern http_msg * stdcall (*http_post)(const char *url, http_msg *identifier, unsigned flags, const char *add_header,
107
                                  const char *content_type, unsigned content_length);
108
                                  const char *content_type, unsigned content_length);
Line 108... Line 109...
108
 
109
 
109
/*
110
/*
110
    identifier = identifier which one of the previous functions returned
111
    identifier = identifier which one of the previous functions returned
Line 123... Line 124...
123
    In header_length you'll find the length of the header as soon as it has been received.
124
    In header_length you'll find the length of the header as soon as it has been received.
124
    In content_ptr you'll find a pointer to the actual content.
125
    In content_ptr you'll find a pointer to the actual content.
125
    In content_length you'll find the length of the content. 
126
    In content_length you'll find the length of the content. 
126
    In content_received, you'll find the number of content bytes already received.
127
    In content_received, you'll find the number of content bytes already received.
127
*/
128
*/
128
extern int stdcall (*receive)(http_msg *identifier);
129
extern int stdcall (*http_receive)(http_msg *identifier);
Line 129... Line 130...
129
 
130
 
130
/*
131
/*
131
    identifier = identifier which one of the previous functions returned
132
    identifier = identifier which one of the previous functions returned
132
    dataptr = pointer to the data you want to send
133
    dataptr = pointer to the data you want to send
133
    datalength = length of the data to send (in bytes)
134
    datalength = length of the data to send (in bytes)
134
    This procedure can be used to send data to the server (POST)
135
    This procedure can be used to send data to the server (POST)
135
    Returns number of bytes sent, -1 on error
136
    Returns number of bytes sent, -1 on error
136
*/
137
*/
-
 
138
extern int stdcall (*http_send)(http_msg *identifier, void *dataptr, unsigned datalength);
-
 
139
 
-
 
140
/*
-
 
141
    Sometimes the http_receive function receives incomplete data. If you have the same problem then a macro can help you:
-
 
142
*/
Line 137... Line -...
137
extern int stdcall (*send)(http_msg *identifier, void *dataptr, unsigned datalength);
-
 
138
 
143
#define http_long_receive(x) while(http_receive(x)){}; 
-
 
144