| 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 |
#ifndef VMHTTPREQ_H |
| 37 |
#define VMHTTPREQ_H |
| 38 |
|
| 39 |
#include "t3std.h" |
| 40 |
#include "vmtype.h" |
| 41 |
#include "vmglob.h" |
| 42 |
#include "vmobj.h" |
| 43 |
#include "vmundo.h" |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
struct vm_httpreq_ext |
| 61 |
{ |
| 62 |
|
| 63 |
static vm_httpreq_ext *alloc_ext(VMG_ class CVmObjHTTPRequest *self); |
| 64 |
|
| 65 |
|
| 66 |
class TadsHttpRequest *req; |
| 67 |
|
| 68 |
|
| 69 |
struct vm_httpreq_cookie *cookies; |
| 70 |
|
| 71 |
|
| 72 |
vm_obj_id_t server; |
| 73 |
}; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
struct vm_httpreq_cookie |
| 79 |
{ |
| 80 |
vm_httpreq_cookie(const char *name, size_t namelen, |
| 81 |
const char *val, size_t vallen) |
| 82 |
{ |
| 83 |
this->name = lib_copy_str(name, namelen); |
| 84 |
this->val = lib_copy_str(val, vallen); |
| 85 |
nxt = 0; |
| 86 |
} |
| 87 |
|
| 88 |
~vm_httpreq_cookie() |
| 89 |
{ |
| 90 |
lib_free_str(name); |
| 91 |
lib_free_str(val); |
| 92 |
if (nxt != 0) |
| 93 |
delete nxt; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
vm_httpreq_cookie *clone() |
| 98 |
{ |
| 99 |
|
| 100 |
vm_httpreq_cookie *c = new vm_httpreq_cookie( |
| 101 |
name, strlen(name), val, val != 0 ? strlen(val) : 0); |
| 102 |
|
| 103 |
|
| 104 |
if (nxt != 0) |
| 105 |
c->nxt = nxt->clone(); |
| 106 |
|
| 107 |
|
| 108 |
return c; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
int send(class TadsServerThread *t); |
| 113 |
|
| 114 |
|
| 115 |
char *name; |
| 116 |
|
| 117 |
|
| 118 |
char *val; |
| 119 |
|
| 120 |
|
| 121 |
vm_httpreq_cookie *nxt; |
| 122 |
}; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
class CVmObjHTTPRequest: public CVmObject |
| 131 |
{ |
| 132 |
friend class CVmMetaclassHTTPRequest; |
| 133 |
|
| 134 |
public: |
| 135 |
|
| 136 |
static class CVmMetaclass *metaclass_reg_; |
| 137 |
class CVmMetaclass *get_metaclass_reg() const { return metaclass_reg_; } |
| 138 |
|
| 139 |
|
| 140 |
virtual int is_of_metaclass(class CVmMetaclass *meta) const |
| 141 |
{ |
| 142 |
|
| 143 |
return (meta == metaclass_reg_ |
| 144 |
|| CVmObject::is_of_metaclass(meta)); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
static int is_vmhttpreq_obj(VMG_ vm_obj_id_t obj) |
| 149 |
{ return vm_objp(vmg_ obj)->is_of_metaclass(metaclass_reg_); } |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
static vm_obj_id_t create(VMG_ int in_root_set, |
| 156 |
class TadsHttpRequest *req, |
| 157 |
vm_obj_id_t srv_obj); |
| 158 |
|
| 159 |
|
| 160 |
static vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, |
| 161 |
uint argc); |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
static int call_stat_prop(VMG_ vm_val_t *result, |
| 168 |
const uchar **pc_ptr, uint *argc, |
| 169 |
vm_prop_id_t prop) |
| 170 |
{ |
| 171 |
return CVmObject:: |
| 172 |
call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
void notify_delete(VMG_ int in_root_set); |
| 177 |
|
| 178 |
|
| 179 |
void set_prop(VMG_ class CVmUndo *undo, |
| 180 |
vm_obj_id_t self, vm_prop_id_t prop, const vm_val_t *val); |
| 181 |
|
| 182 |
|
| 183 |
int get_prop(VMG_ vm_prop_id_t prop, vm_val_t *val, |
| 184 |
vm_obj_id_t self, vm_obj_id_t *source_obj, uint *argc); |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
void notify_new_savept() { } |
| 191 |
|
| 192 |
|
| 193 |
void apply_undo(VMG_ struct CVmUndoRecord *) { } |
| 194 |
void discard_undo(VMG_ struct CVmUndoRecord *) { } |
| 195 |
void mark_undo_ref(VMG_ struct CVmUndoRecord *) { } |
| 196 |
|
| 197 |
|
| 198 |
void mark_refs(VMG_ uint state); |
| 199 |
|
| 200 |
|
| 201 |
void remove_stale_weak_refs(VMG0_) { } |
| 202 |
void remove_stale_undo_weak_ref(VMG_ struct CVmUndoRecord *) { } |
| 203 |
|
| 204 |
|
| 205 |
void load_from_image(VMG_ vm_obj_id_t self, const char *ptr, size_t siz); |
| 206 |
|
| 207 |
|
| 208 |
void reload_from_image(VMG_ vm_obj_id_t self, |
| 209 |
const char *ptr, size_t siz); |
| 210 |
|
| 211 |
|
| 212 |
virtual ulong rebuild_image(VMG_ char *buf, ulong buflen); |
| 213 |
|
| 214 |
|
| 215 |
void save_to_file(VMG_ class CVmFile *fp); |
| 216 |
|
| 217 |
|
| 218 |
void restore_from_file(VMG_ vm_obj_id_t self, |
| 219 |
class CVmFile *fp, class CVmObjFixup *fixups); |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
int is_changed_since_load() const { return TRUE; } |
| 227 |
|
| 228 |
protected: |
| 229 |
|
| 230 |
vm_httpreq_ext *get_ext() const { return (vm_httpreq_ext *)ext_; } |
| 231 |
|
| 232 |
|
| 233 |
void load_image_data(VMG_ const char *ptr, size_t siz); |
| 234 |
|
| 235 |
|
| 236 |
CVmObjHTTPRequest() { ext_ = 0; } |
| 237 |
|
| 238 |
|
| 239 |
CVmObjHTTPRequest(VMG_ int flag); |
| 240 |
|
| 241 |
|
| 242 |
int getp_undef(VMG_ vm_obj_id_t, vm_val_t *, uint *) { return FALSE; } |
| 243 |
|
| 244 |
|
| 245 |
int getp_getServer(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 246 |
|
| 247 |
|
| 248 |
int getp_getVerb(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 249 |
|
| 250 |
|
| 251 |
int getp_getQuery(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 252 |
|
| 253 |
|
| 254 |
int getp_parseQuery(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 255 |
|
| 256 |
|
| 257 |
int getp_getQueryParam(VMG_ vm_obj_id_t self, |
| 258 |
vm_val_t *retval, uint *argc); |
| 259 |
|
| 260 |
|
| 261 |
int getp_getHeaders(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 262 |
|
| 263 |
|
| 264 |
int getp_getCookie(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 265 |
|
| 266 |
|
| 267 |
int getp_getCookies(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 268 |
|
| 269 |
|
| 270 |
int getp_setCookie(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 271 |
|
| 272 |
|
| 273 |
int getp_getFormFields(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 274 |
|
| 275 |
|
| 276 |
int getp_getBody(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 277 |
|
| 278 |
|
| 279 |
int getp_getClientAddress( |
| 280 |
VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 281 |
|
| 282 |
|
| 283 |
int getp_sendReply(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 284 |
|
| 285 |
|
| 286 |
int common_sendReply( |
| 287 |
VMG_ vm_obj_id_t self, vm_val_t *retval, uint *oargc, int wait); |
| 288 |
|
| 289 |
|
| 290 |
int getp_startChunkedReply(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 291 |
uint *argc); |
| 292 |
|
| 293 |
|
| 294 |
int getp_sendReplyChunk(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 295 |
uint *argc); |
| 296 |
|
| 297 |
|
| 298 |
int getp_endChunkedReply(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 299 |
uint *argc); |
| 300 |
|
| 301 |
|
| 302 |
int getp_sendReplyAsync( |
| 303 |
VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 304 |
|
| 305 |
|
| 306 |
static int (CVmObjHTTPRequest::*func_table_[])(VMG_ vm_obj_id_t self, |
| 307 |
vm_val_t *retval, uint *argc); |
| 308 |
}; |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
class CVmMetaclassHTTPRequest: public CVmMetaclass |
| 316 |
{ |
| 317 |
public: |
| 318 |
|
| 319 |
const char *get_meta_name() const { return "http-request/030001"; } |
| 320 |
|
| 321 |
|
| 322 |
void create_for_image_load(VMG_ vm_obj_id_t id) |
| 323 |
{ |
| 324 |
new (vmg_ id) CVmObjHTTPRequest(); |
| 325 |
G_obj_table->set_obj_gc_characteristics(id, FALSE, FALSE); |
| 326 |
G_obj_table->set_obj_transient(id); |
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
void create_for_restore(VMG_ vm_obj_id_t id) |
| 331 |
{ |
| 332 |
new (vmg_ id) CVmObjHTTPRequest(); |
| 333 |
G_obj_table->set_obj_gc_characteristics(id, FALSE, FALSE); |
| 334 |
G_obj_table->set_obj_transient(id); |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, uint argc) |
| 339 |
{ return CVmObjHTTPRequest::create_from_stack(vmg_ pc_ptr, argc); } |
| 340 |
|
| 341 |
|
| 342 |
int call_stat_prop(VMG_ vm_val_t *result, |
| 343 |
const uchar **pc_ptr, uint *argc, |
| 344 |
vm_prop_id_t prop) |
| 345 |
{ |
| 346 |
return CVmObjHTTPRequest:: |
| 347 |
call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 348 |
} |
| 349 |
}; |
| 350 |
|
| 351 |
#endif |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
VM_REGISTER_METACLASS(CVmObjHTTPRequest) |