int on_message_begin(ryah_http_parser *parser) { GET_WRAPPER(wrapper, parser); wrapper->request_url = rb_str_new2(""); wrapper->request_path = rb_str_new2(""); wrapper->query_string = rb_str_new2(""); wrapper->fragment = rb_str_new2(""); wrapper->headers = rb_hash_new(); wrapper->upgrade_data = rb_str_new2(""); VALUE ret = Qnil; if (wrapper->callback_object != Qnil && rb_respond_to(wrapper->callback_object, Ion_message_begin)) { ret = rb_funcall(wrapper->callback_object, Ion_message_begin, 0); } else if (wrapper->on_message_begin != Qnil) { ret = rb_funcall(wrapper->on_message_begin, Icall, 0); } if (ret == Sstop) { wrapper->stopped = Qtrue; return -1; } else { return 0; } }
int on_header_field(ryah_http_parser *parser, const char *at, size_t length) { GET_WRAPPER(wrapper, parser); if (wrapper->curr_field_name == Qnil) { wrapper->last_field_name = Qnil; wrapper->curr_field_name = rb_str_new(at, length); } else { rb_str_cat(wrapper->curr_field_name, at, length); } return 0; }
int on_header_field(ryah_http_parser *parser, const char *at, size_t length) { GET_WRAPPER(wrapper, parser); wrapper->last_field_name = Qnil; if (wrapper->last_field_name_at == NULL) { wrapper->last_field_name_at = at; wrapper->last_field_name_length = length; } else { wrapper->last_field_name_length += length; } return 0; }
int on_header_value(ryah_http_parser *parser, const char *at, size_t length) { GET_WRAPPER(wrapper, parser); int new_field = 0; VALUE current_value; if (wrapper->last_field_name == Qnil) { new_field = 1; wrapper->last_field_name = wrapper->curr_field_name; wrapper->curr_field_name = Qnil; } current_value = rb_hash_aref(wrapper->headers, wrapper->last_field_name); if (new_field == 1) { if (current_value == Qnil) { if (wrapper->header_value_type == Sarrays) { rb_hash_aset(wrapper->headers, wrapper->last_field_name, rb_ary_new3(1, rb_str_new2(""))); } else { rb_hash_aset(wrapper->headers, wrapper->last_field_name, rb_str_new2("")); } } else { if (wrapper->header_value_type == Smixed) { if (TYPE(current_value) == T_STRING) { rb_hash_aset(wrapper->headers, wrapper->last_field_name, rb_ary_new3(2, current_value, rb_str_new2(""))); } else { rb_ary_push(current_value, rb_str_new2("")); } } else if (wrapper->header_value_type == Sarrays) { rb_ary_push(current_value, rb_str_new2("")); } else { rb_str_cat(current_value, ", ", 2); } } current_value = rb_hash_aref(wrapper->headers, wrapper->last_field_name); } if (TYPE(current_value) == T_ARRAY) { current_value = rb_ary_entry(current_value, -1); } rb_str_cat(current_value, at, length); return 0; }
int on_body(ryah_http_parser *parser, const char *at, size_t length) { GET_WRAPPER(wrapper, parser); VALUE ret = Qnil; if (wrapper->callback_object != Qnil && rb_respond_to(wrapper->callback_object, Ion_body)) { ret = rb_funcall(wrapper->callback_object, Ion_body, 1, rb_str_new(at, length)); } else if (wrapper->on_body != Qnil) { ret = rb_funcall(wrapper->on_body, Icall, 1, rb_str_new(at, length)); } if (ret == Sstop) { wrapper->stopped = Qtrue; return -1; } else { return 0; } }
int on_message_complete(ryah_http_parser *parser) { GET_WRAPPER(wrapper, parser); VALUE ret = Qnil; if (wrapper->callback_object != Qnil && rb_respond_to(wrapper->callback_object, Ion_message_complete)) { ret = rb_funcall(wrapper->callback_object, Ion_message_complete, 0); } else if (wrapper->on_message_complete != Qnil) { ret = rb_funcall(wrapper->on_message_complete, Icall, 0); } if (ret == Sstop) { wrapper->stopped = Qtrue; return -1; } else { return 0; } }
int on_header_value(ryah_http_parser *parser, const char *at, size_t length) { GET_WRAPPER(wrapper, parser); if (wrapper->last_field_name == Qnil) { wrapper->last_field_name = rb_str_new(wrapper->last_field_name_at, wrapper->last_field_name_length); VALUE val = rb_hash_aref(wrapper->headers, wrapper->last_field_name); if (val != Qnil) { rb_str_cat(val, ", ", 2); } wrapper->last_field_name_at = NULL; wrapper->last_field_name_length = 0; } HASH_CAT(wrapper->headers, wrapper->last_field_name, at, length); return 0; }
static void pro_start_indication (PROFILE_INSTANCE *pi, PROFILE *po) { char certbuf[BUFSIZ], *certfile, *cp, *dir, keybuf[BUFSIZ], *keyfile, *serverName; DIAGNOSTIC ds, *d = &ds; PROFILE ps, *p = &ps; PRO_LOCALDATA *il; struct configobj *appconfig = bp_get_config (pi -> channel -> conn); struct cfgsearchobj *cs; if (!(serverName = bp_server_name (pi -> channel -> conn))) serverName = pi -> channel -> inbound -> server_name; if (pro_debug) { fprintf (stderr, "TLS start_indication: servername=\"%s\" piggyback=\"%s\"\n", serverName ? serverName : "<NULL>", po -> piggyback ? po -> piggyback : "<NULL>"); fflush (stderr); } memset (p, 0, sizeof *p); p -> uri = po -> uri; memset (d, 0, sizeof *d); d -> code = 421; if (((cp = config_get (appconfig, SASL_LOCAL_CODE)) != NULL) && (*cp == '2')) { d -> code = 520; d -> message = "already tuned for authentication"; bpc_start_response (pi -> channel, p, d); return; } if (!(il = (PRO_LOCALDATA *) lib_malloc (sizeof *il))) { d -> message = "out of memory"; bpc_start_response (pi -> channel, p, d); return; } certfile = keyfile = NULL; if ((dir = config_get (appconfig, TLS_CERTDIR)) && !(strstr (serverName, "/")) && !(strstr (serverName, ".."))) { sprintf (certbuf, "%s/%s", dir, serverName); #ifndef WIN32 if (access (certbuf, R_OK) >= 0) { certfile = keyfile = certbuf; if ((dir = config_get (appconfig, TLS_KEYDIR)) != NULL) { sprintf (keybuf, "%s/%s", dir, serverName); if (access (keybuf, R_OK) >= 0) keyfile = keybuf; else certfile = keyfile = NULL; } } #else certfile = keyfile = certbuf; if ((dir = config_get (appconfig, TLS_KEYDIR)) != NULL) { sprintf (keybuf, "%s/%s", dir, serverName); keyfile = keybuf; } #endif } memset (il, 0, sizeof *il); if (!(il -> pl_ctx = SSL_CTX_new (SSLv23_server_method ()))) { if (pro_debug) ERR_print_errors_fp (stderr); d -> message = "unable to create server context"; } else if (!certfile && !(certfile = config_get (appconfig, TLS_CERTFILE))) { d -> message = "TLS_CERTFILE not present in configuration"; } else if (SSL_CTX_use_certificate_file (il -> pl_ctx, certfile, SSL_FILETYPE_PEM) <= 0) { if (pro_debug) ERR_print_errors_fp (stderr); d -> message = "unable to use certificate file"; } else if (!keyfile && !(keyfile = config_get (appconfig, TLS_KEYFILE))) { d -> message = "TLS_KEYFILE not present in configuration"; } else if (SSL_CTX_use_PrivateKey_file (il -> pl_ctx, keyfile, SSL_FILETYPE_PEM) <= 0) { if (pro_debug) ERR_print_errors_fp (stderr); d -> message = "unable to use private key file"; } else if (!SSL_CTX_check_private_key (il -> pl_ctx)) { d -> message = "private key does not match certificate's public key"; } else if (po -> piggyback_length == 0) d = NULL; else if (strstr (po -> piggyback, "<ready")) { bp_slist *list; CHANNEL_INSTANCE *inst; for (list = pi -> channel -> conn -> channel_instance; list; list = list -> next) { if ((inst = list -> data) -> channel_number == 0) { bpc_tuning_reset_request (inst); break; } } p -> piggyback_length = strlen (p -> piggyback = "<proceed />"); #if 0 err = workqueue_add_item(notifyqueue, tls_tuning_reset_notify, pi); if (err == 0) { fiostate_block_read (GET_WRAPPER(pi->channel->conn) -> iostate); d = NULL; } else { d -> message = "unable to wait for channels to become quiescent"; } #else fiostate_block_read (GET_WRAPPER(pi->channel->conn) -> iostate); d = NULL; #endif } else d = bp_diagnostic_new (pi -> channel -> conn, 504, NULL, "expecting ready element in piggyback"); if (d && d -> message) { lib_free (il); } else { pi -> user_ptr1 = il; cs = config_search_init (appconfig, PRIVACY_PREFIX, ""); for (cp = config_search_string_firstkey (cs); cp; cp = config_search_string_nextkey (cs)) config_delete (appconfig, cp); config_search_fin (&cs); } bpc_start_response (pi -> channel, p, d); #if 1 workqueue_add_item(notifyqueue, tls_tuning_reset_notify, pi); #endif if ((d != NULL) && (d != &ds)) bp_diagnostic_destroy (pi -> channel -> conn, d); }
int on_fragment(ryah_http_parser *parser, const char *at, size_t length) { GET_WRAPPER(wrapper, parser); rb_str_cat(wrapper->fragment, at, length); return 0; }
int on_query_string(ryah_http_parser *parser, const char *at, size_t length) { GET_WRAPPER(wrapper, parser); rb_str_cat(wrapper->query_string, at, length); return 0; }
int on_path(ryah_http_parser *parser, const char *at, size_t length) { GET_WRAPPER(wrapper, parser); rb_str_cat(wrapper->request_path, at, length); return 0; }