MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / on_request_recv

Function on_request_recv

modules/http2d/server.c:535–627  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

533
534
535static int on_request_recv(nghttp2_session *session,
536 http2_session_data *session_data,
537 http2_stream_data *stream_data) {
538 int rc;
539 struct timespec wait_until;
540 struct timeval now, wait_time, res;
541 struct timespec begin;
542 unsigned long long diff_ns;
543 char *H;
544
545 if (!stream_data->path) {
546 if (error_reply(session, stream_data) != 0) {
547 return NGHTTP2_ERR_CALLBACK_FAILURE;
548 }
549 return 0;
550 }
551
552 LM_INFO("%s GET %s (stream_id: %d)\n", session_data->client_addr,
553 stream_data->path, stream_data->stream_id);
554 if (stream_data->data.len)
555 LM_INFO("body: (%d) %.*s\n", stream_data->data.len, stream_data->data.len, stream_data->data.s);
556 else
557 LM_INFO("body: (none)\n");
558
559 if (!check_path(stream_data->path)) {
560 if (error_reply(session, stream_data) != 0) {
561 return NGHTTP2_ERR_CALLBACK_FAILURE;
562 }
563 return 0;
564 }
565
566 pthread_mutex_lock(&ng_h2_response->mutex);
567
568 H = cJSON_PrintUnformatted(stream_data->hdrs);
569 h2_raise_event_request(stream_data->method, stream_data->path,
570 H, &stream_data->data);
571 cJSON_PurgeString(H);
572
573 gettimeofday(&now, NULL);
574 wait_time.tv_sec = h2_response_timeout / 1000;
575 wait_time.tv_usec = h2_response_timeout % 1000 * 1000UL;
576 LM_DBG("awaiting HTTP2 reply (%ld s, %ld us)...\n", wait_time.tv_sec, wait_time.tv_usec);
577
578 timeradd(&now, &wait_time, &res);
579
580 wait_until.tv_sec = res.tv_sec;
581 wait_until.tv_nsec = res.tv_usec * 1000UL;
582
583 clock_gettime(CLOCK_REALTIME, &begin);
584 rc = pthread_cond_timedwait(&ng_h2_response->cond,
585 &ng_h2_response->mutex, &wait_until);
586 diff_ns = get_clock_diff(&begin);
587 LM_DBG("waited %llu ns in total\n", diff_ns);
588 if (rc != 0) {
589 pthread_mutex_unlock(&ng_h2_response->mutex);
590
591 LM_ERR("timeout (errno: %d '%s') while awaiting "
592 "HTTP2 reply from opensips.cfg\n", rc, strerror(rc));

Callers 1

on_frame_recv_callbackFunction · 0.85

Calls 9

error_replyFunction · 0.85
check_pathFunction · 0.85
h2_raise_event_requestFunction · 0.85
cJSON_PurgeStringFunction · 0.85
get_clock_diffFunction · 0.85
timeout_replyFunction · 0.85
h2_fdpackFunction · 0.85
send_response_fdFunction · 0.85
cJSON_PrintUnformattedFunction · 0.50

Tested by

no test coverage detected