| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef VMHTTPSRV_H |
| 21 |
#define VMHTTPSRV_H |
| 22 |
|
| 23 |
#include "t3std.h" |
| 24 |
#include "vmtype.h" |
| 25 |
#include "vmglob.h" |
| 26 |
#include "vmobj.h" |
| 27 |
#include "vmundo.h" |
| 28 |
#include "vmnet.h" |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
struct vm_httpsrv_ext |
| 45 |
{ |
| 46 |
|
| 47 |
static vm_httpsrv_ext *alloc_ext(VMG_ class CVmObjHTTPServer *self); |
| 48 |
|
| 49 |
|
| 50 |
class TadsListener *l; |
| 51 |
|
| 52 |
|
| 53 |
char *addr; |
| 54 |
}; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
class CVmObjHTTPServer: public CVmObject |
| 63 |
{ |
| 64 |
friend class CVmMetaclassHTTPServer; |
| 65 |
|
| 66 |
public: |
| 67 |
|
| 68 |
static class CVmMetaclass *metaclass_reg_; |
| 69 |
class CVmMetaclass *get_metaclass_reg() const { return metaclass_reg_; } |
| 70 |
|
| 71 |
|
| 72 |
virtual int is_of_metaclass(class CVmMetaclass *meta) const |
| 73 |
{ |
| 74 |
|
| 75 |
return (meta == metaclass_reg_ |
| 76 |
|| CVmObject::is_of_metaclass(meta)); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
static int is_httpsrv_obj(VMG_ vm_obj_id_t obj) |
| 81 |
{ return vm_objp(vmg_ obj)->is_of_metaclass(metaclass_reg_); } |
| 82 |
|
| 83 |
|
| 84 |
static vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, |
| 85 |
uint argc); |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
static int call_stat_prop(VMG_ vm_val_t *result, |
| 92 |
const uchar **pc_ptr, uint *argc, |
| 93 |
vm_prop_id_t prop) |
| 94 |
{ |
| 95 |
return CVmObject:: |
| 96 |
call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
void notify_delete(VMG_ int in_root_set); |
| 101 |
|
| 102 |
|
| 103 |
void set_prop(VMG_ class CVmUndo *undo, |
| 104 |
vm_obj_id_t self, vm_prop_id_t prop, const vm_val_t *val); |
| 105 |
|
| 106 |
|
| 107 |
int get_prop(VMG_ vm_prop_id_t prop, vm_val_t *val, |
| 108 |
vm_obj_id_t self, vm_obj_id_t *source_obj, uint *argc); |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
void notify_new_savept() { } |
| 115 |
|
| 116 |
|
| 117 |
void apply_undo(VMG_ struct CVmUndoRecord *) { } |
| 118 |
|
| 119 |
|
| 120 |
void discard_undo(VMG_ struct CVmUndoRecord *) { } |
| 121 |
|
| 122 |
|
| 123 |
void mark_undo_ref(VMG_ struct CVmUndoRecord *) { } |
| 124 |
|
| 125 |
|
| 126 |
void mark_refs(VMG_ uint) { } |
| 127 |
|
| 128 |
|
| 129 |
void remove_stale_weak_refs(VMG0_) { } |
| 130 |
void remove_stale_undo_weak_ref(VMG_ struct CVmUndoRecord *) { } |
| 131 |
|
| 132 |
|
| 133 |
void load_from_image(VMG_ vm_obj_id_t self, const char *ptr, size_t siz); |
| 134 |
|
| 135 |
|
| 136 |
void reload_from_image(VMG_ vm_obj_id_t self, |
| 137 |
const char *ptr, size_t siz); |
| 138 |
|
| 139 |
|
| 140 |
virtual ulong rebuild_image(VMG_ char *buf, ulong buflen); |
| 141 |
|
| 142 |
|
| 143 |
void save_to_file(VMG_ class CVmFile *fp); |
| 144 |
|
| 145 |
|
| 146 |
void restore_from_file(VMG_ vm_obj_id_t self, |
| 147 |
class CVmFile *fp, class CVmObjFixup *fixups); |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
int is_changed_since_load() const { return TRUE; } |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
int get_listener_addr(char *&addr, char *&ip, int &port) const; |
| 164 |
|
| 165 |
protected: |
| 166 |
|
| 167 |
vm_httpsrv_ext *get_ext() const |
| 168 |
{ return (vm_httpsrv_ext *)ext_; } |
| 169 |
|
| 170 |
|
| 171 |
void load_image_data(VMG_ const char *ptr, size_t siz); |
| 172 |
|
| 173 |
|
| 174 |
CVmObjHTTPServer() { ext_ = 0; } |
| 175 |
|
| 176 |
|
| 177 |
CVmObjHTTPServer(VMG_ int flag); |
| 178 |
|
| 179 |
|
| 180 |
int getp_undef(VMG_ vm_obj_id_t, vm_val_t *, uint *) { return FALSE; } |
| 181 |
|
| 182 |
|
| 183 |
int getp_shutdown(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 184 |
|
| 185 |
|
| 186 |
int getp_get_port(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 187 |
|
| 188 |
|
| 189 |
int getp_get_addr(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 190 |
|
| 191 |
|
| 192 |
int getp_get_ip(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 193 |
|
| 194 |
|
| 195 |
static int (CVmObjHTTPServer::*func_table_[])(VMG_ vm_obj_id_t self, |
| 196 |
vm_val_t *retval, uint *argc); |
| 197 |
}; |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
class CVmMetaclassHTTPServer: public CVmMetaclass |
| 205 |
{ |
| 206 |
public: |
| 207 |
|
| 208 |
const char *get_meta_name() const { return "http-server/030000"; } |
| 209 |
|
| 210 |
|
| 211 |
void create_for_image_load(VMG_ vm_obj_id_t id) |
| 212 |
{ |
| 213 |
new (vmg_ id) CVmObjHTTPServer(); |
| 214 |
G_obj_table->set_obj_gc_characteristics(id, FALSE, FALSE); |
| 215 |
G_obj_table->set_obj_transient(id); |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
void create_for_restore(VMG_ vm_obj_id_t id) |
| 220 |
{ |
| 221 |
new (vmg_ id) CVmObjHTTPServer(); |
| 222 |
G_obj_table->set_obj_gc_characteristics(id, FALSE, FALSE); |
| 223 |
G_obj_table->set_obj_transient(id); |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, uint argc) |
| 228 |
{ return CVmObjHTTPServer::create_from_stack(vmg_ pc_ptr, argc); } |
| 229 |
|
| 230 |
|
| 231 |
int call_stat_prop(VMG_ vm_val_t *result, |
| 232 |
const uchar **pc_ptr, uint *argc, |
| 233 |
vm_prop_id_t prop) |
| 234 |
{ |
| 235 |
return CVmObjHTTPServer:: |
| 236 |
call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 237 |
} |
| 238 |
}; |
| 239 |
|
| 240 |
#endif |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
VM_REGISTER_METACLASS(CVmObjHTTPServer) |