Esempio n. 1
0
 void SessionImpl::transmit( const Response& response, const function< void ( const error_code&, size_t ) >& callback ) const
 {
     auto hdrs = m_settings->get_default_headers( );
     
     if ( m_resource not_eq nullptr )
     {
         const auto m_resource_headers = m_resource->m_pimpl->m_default_headers;
         hdrs.insert( m_resource_headers.begin( ), m_resource_headers.end( ) );
     }
     
     hdrs.insert( m_headers.begin( ), m_headers.end( ) );
     
     auto response_headers = response.get_headers( );
     hdrs.insert( response_headers.begin( ), response_headers.end( ) );
     
     auto payload = make_shared< Response >( );
     payload->set_headers( hdrs );
     payload->set_body( response.get_body( ) );
     payload->set_version( response.get_version( ) );
     payload->set_protocol( response.get_protocol( ) );
     payload->set_status_code( response.get_status_code( ) );
     payload->set_status_message( response.get_status_message( ) );
     
     if ( payload->get_status_message( ).empty( ) )
     {
         payload->set_status_message( m_settings->get_status_message( payload->get_status_code( ) ) );
     }
     
     m_request->m_pimpl->m_socket->start_write( Http::to_bytes( payload ), callback );
 }
Esempio n. 2
0
// ## send not found
static void send_not_found(req_res_t* rr) {
    if(rr != NULL)
    {
        DEBUG("send_not_found\n");
        // `rr->close_after_write = 1` makes `on_tcp_write` close the connection.
        rr->close_after_write = 1;
        memcpy(rr->content_type, "text/html", 9);
        rr->content_type_len = 9;
        set_headers(rr, "404 Not Found");
        // Check if `headers_buf` is initialized.
        if (rr->headers_buf == NULL) return;
        // Check if the buffer is big enough to add the `Not found` body.
        if (rr->headers_buf->len+20 >= HEADERS_BUF_SIZE) {
            fprintf(stderr, "headers buffer too small: -3");
            //return;
        }
        else {
            // Add the body and set the new buffer size.
            memcpy(rr->headers_buf->base+rr->headers_buf->len, "<h1>Not Found</h1>\n\0", 20);
            rr->headers_buf->len += 20;
            send_headers_buf(rr);
        }
    }
    else {
        DEBUG("send_not_found error: rr is NULL.\n");
    }
}
Esempio n. 3
0
void
test_body(void) {
    set_headers();
    balde_app_t *app = balde_app_init();
    balde_request_t *request = balde_make_request(app, NULL);
    g_assert_cmpstr(request->priv->body->str, ==, "guda=bola&moises=arcoiro");
    g_assert_cmpint(request->priv->body->len, ==, 24);
    balde_request_free(request);
    balde_app_free(app);
}
Esempio n. 4
0
void
test_read(void) {
    set_headers();
    balde_app_t *app = balde_app_init();
    GString *body = balde_cgi_stdin_read(app);
    g_assert_cmpstr(body->str, ==, "guda=bola&moises=arcoiro");
    g_assert_cmpint(body->len, ==, 24);
    g_string_free(body, TRUE);
    balde_app_free(app);
}
Esempio n. 5
0
SEXP R_handle_reset(SEXP ptr){
  //reset all fields
  reference *ref = get_ref(ptr);
  set_form(ref, NULL);
  set_headers(ref, NULL);
  curl_easy_reset(ref->handle);

  //restore default settings
  set_handle_defaults(ref);
  return ScalarLogical(1);
}
Esempio n. 6
0
void
test_form(void) {
    set_headers();
    balde_app_t *app = balde_app_init();
    balde_request_t *request = balde_make_request(app, NULL);
    g_assert(request->priv->form != NULL);
    g_assert(g_hash_table_size(request->priv->form) == 2);
    g_assert_cmpstr(g_hash_table_lookup(request->priv->form, "guda"), ==, "bola");
    g_assert_cmpstr(g_hash_table_lookup(request->priv->form, "moises"), ==, "arcoiro");
    balde_request_free(request);
    balde_app_free(app);
}
Esempio n. 7
0
 Promise fetch()
 {
   auto request = Http::Request::get(get_url());
   
   request->set_headers({{"Accept",Archive::mimetype}});
   return request->send().then([this, request]()
   {
     auto response = request->get_response();
     
     if (response->ok())
     {
       if (response->has_body())
         parse(response->get_response_text());
       synced.trigger();
     }
   });
 }
Esempio n. 8
0
void StorageReserveWidget::fill_table(){
    QSqlQuery query(base);
    delete ui->table_widget->model();
    QString query_str = QString("SELECT g.id as id, "                               // 0
                                "g.trademark_id as trademark_id, "                  // 1
                                "g.place_id as place_id, "                          // 2
                                "g.inspection_id as inspection_id, "                // 3
                                "g.category_id as category_id, "                    // 4
                                "t.name as name, "                                  // 5
                                "g.quantity as quantity, "                          // 6
                                "g.year as year, "                                  // 7
                                "i.insp_name as inspection, "                       // 8
                                "p.storage as storage, "                            // 9
                                "p.rack as rack, "                                  // 10
                                "p.board as board, "                                // 11
                                "p.box as box, "                                    // 12
                                "g.pack as nu, "                                    // 13
                                "c.category_name as category, "                     // 14
                                "g.add_info as add_info, "                          // 15
                                "g.defect as defect, "                              // 16
                                "g.photo as photo "                                 // 17
                                "FROM greytable g "
                                "JOIN trademarks t ON g.trademark_id = t.id "
                                "JOIN places p ON g.place_id = p.id "
                                "JOIN categories c ON g.category_id = c.id "
                                "JOIN inspections i ON g.inspection_id = i.id "
                                "WHERE g.add_user_id = %1 AND g.status = 4")
            .arg(USER_ID);
    qDebug() << query_str;
    source->setQuery(query_str, base);
    if(source->lastError().isValid()){
        QMessageBox::information(this, "Не удалось сформировать таблицу", source->lastError().text(), QMessageBox::Ok);
        return;
    }
    model = new QSortFilterProxyModel(this);
    model->setSourceModel(source);
    set_headers();
    ui->table_widget->setModel(model);
    ui->table_widget->hideColumn(0);
    ui->table_widget->hideColumn(1);
    ui->table_widget->hideColumn(2);
    ui->table_widget->hideColumn(3);
    ui->table_widget->hideColumn(4);
    ui->table_widget->hideColumn(17);
}
static GstFlowReturn
gst_rtp_base_depayload_prepare_push (GstRTPBaseDepayload * filter,
    gboolean is_list, gpointer obj)
{
  if (is_list) {
    GstBufferList **blist = obj;
    gst_buffer_list_foreach (*blist, (GstBufferListFunc) set_headers, filter);
  } else {
    GstBuffer **buf = obj;
    set_headers (buf, 0, filter);
  }

  /* if this is the first buffer send a NEWSEGMENT */
  if (G_UNLIKELY (filter->priv->segment_event)) {
    gst_pad_push_event (filter->srcpad, filter->priv->segment_event);
    filter->priv->segment_event = NULL;
    GST_DEBUG_OBJECT (filter, "Pushed newsegment event on this first buffer");
  }

  return GST_FLOW_OK;
}
Esempio n. 10
0
/* Updates the SSRC, payload type, seqnum and timestamp of the RTP buffer
 * before the buffer is pushed. */
static GstFlowReturn
gst_rtp_base_payload_prepare_push (GstRTPBasePayload * payload,
    gpointer obj, gboolean is_list)
{
  GstRTPBasePayloadPrivate *priv;
  HeaderData data;

  if (payload->clock_rate == 0)
    goto no_rate;

  priv = payload->priv;

  /* update first, so that the property is set to the last
   * seqnum pushed */
  payload->seqnum = priv->next_seqnum;

  /* fill in the fields we want to set on all headers */
  data.payload = payload;
  data.seqnum = payload->seqnum;
  data.ssrc = payload->current_ssrc;
  data.pt = payload->pt;

  /* find the first buffer with a timestamp */
  if (is_list) {
    data.dts = -1;
    data.pts = -1;
    data.offset = GST_BUFFER_OFFSET_NONE;
    gst_buffer_list_foreach (GST_BUFFER_LIST_CAST (obj), find_timestamp, &data);
  } else {
    data.dts = GST_BUFFER_DTS (GST_BUFFER_CAST (obj));
    data.pts = GST_BUFFER_PTS (GST_BUFFER_CAST (obj));
    data.offset = GST_BUFFER_OFFSET (GST_BUFFER_CAST (obj));
  }

  /* convert to RTP time */
  if (priv->perfect_rtptime && data.offset != GST_BUFFER_OFFSET_NONE &&
      priv->base_offset != GST_BUFFER_OFFSET_NONE) {
    /* if we have an offset, use that for making an RTP timestamp */
    data.rtptime = payload->ts_base + priv->base_rtime +
        data.offset - priv->base_offset;
    GST_LOG_OBJECT (payload,
        "Using offset %" G_GUINT64_FORMAT " for RTP timestamp", data.offset);
  } else if (GST_CLOCK_TIME_IS_VALID (data.pts)) {
    gint64 rtime;

    /* no offset, use the gstreamer pts */
    rtime = gst_segment_to_running_time (&payload->segment, GST_FORMAT_TIME,
        data.pts);

    if (rtime == -1) {
      GST_LOG_OBJECT (payload, "Clipped pts, using base RTP timestamp");
      rtime = 0;
    } else {
      GST_LOG_OBJECT (payload,
          "Using running_time %" GST_TIME_FORMAT " for RTP timestamp",
          GST_TIME_ARGS (rtime));
      rtime =
          gst_util_uint64_scale_int (rtime, payload->clock_rate, GST_SECOND);
      priv->base_offset = data.offset;
      priv->base_rtime = rtime;
    }
    /* add running_time in clock-rate units to the base timestamp */
    data.rtptime = payload->ts_base + rtime;
  } else {
    GST_LOG_OBJECT (payload,
        "Using previous RTP timestamp %" G_GUINT32_FORMAT, payload->timestamp);
    /* no timestamp to convert, take previous timestamp */
    data.rtptime = payload->timestamp;
  }

  /* set ssrc, payload type, seq number, caps and rtptime */
  if (is_list) {
    gst_buffer_list_foreach (GST_BUFFER_LIST_CAST (obj), set_headers, &data);
  } else {
    GstBuffer *buf = GST_BUFFER_CAST (obj);
    set_headers (&buf, 0, &data);
  }

  priv->next_seqnum = data.seqnum;
  payload->timestamp = data.rtptime;

  GST_LOG_OBJECT (payload, "Preparing to push packet with size %"
      G_GSIZE_FORMAT ", seq=%d, rtptime=%u, pts %" GST_TIME_FORMAT,
      (is_list) ? -1 : gst_buffer_get_size (GST_BUFFER (obj)),
      payload->seqnum, data.rtptime, GST_TIME_ARGS (data.pts));

  if (g_atomic_int_compare_and_exchange (&payload->
          priv->notified_first_timestamp, 1, 0)) {
    g_object_notify (G_OBJECT (payload), "timestamp");
    g_object_notify (G_OBJECT (payload), "seqnum");
  }

  return GST_FLOW_OK;

  /* ERRORS */
no_rate:
  {
    GST_ELEMENT_ERROR (payload, STREAM, NOT_IMPLEMENTED, (NULL),
        ("subclass did not specify clock-rate"));
    return GST_FLOW_ERROR;
  }
}
Esempio n. 11
0
HttpEntity::HttpEntity(const HttpHeaders & header)
: m_content_length_(0)
, m_content_length_is_known_(false)
{
    set_headers(header);
}
Esempio n. 12
0
SEXP R_handle_setheaders(SEXP ptr, SEXP vec){
  if(!isString(vec))
    error("header vector must be a string.");
  set_headers(get_ref(ptr), vec_to_slist(vec));
  return ScalarLogical(1);
}
Esempio n. 13
0
// ## on file open
static void on_file_open(uv_fs_t* req) {
    if(req != NULL) {
        int status = req->result;
        req_res_t* rr = (req_res_t*) req->data;
        if(rr != NULL) {
            rr->pending_requests--;
            
            // Check if an error occurred in an other handler.
            if (rr->dead) {
                req_res_free(rr);
            }
            else {
                char* path_buf;
                int r;
                DEBUG("on_file_open %s\n", rr->path);
                
                uv_fs_req_cleanup(req);
                free(req);
                
                // Check if `uv_fs_open` returned an error.
                if (status < 0) {
                    // Send an `404` response only on `File not found` and `Illegal on directory` error.
                    // Note: It is important to close the file on `EMFILE` and other errors.
                    if (status == UV_ENOENT || status == UV_EISDIR) {
                        send_not_found(rr);
                        //return;
                    }
                    else {
                    fprintf(stderr, "async open error '%s': %s\n", rr->path, uv_strerror(status));
                    // Close the file and free the memory.
                    req_res_free(rr);
                    //return;
                    }
                }
                else {
                    // TODO: Recheck if it is possible to fail in `on_file_open` and get `status < 0`.
                    uv_fs_t stat_req;
                    
                    r = uv_fs_stat(uv_default_loop(), &stat_req, rr->path, NULL);
                    if (r != 0) {
                        fprintf(stderr, "uv_fs_stat error '%s': %s\n", rr->path, uv_strerror(r));
                        req_res_free(rr);
                        //return;
                    }
                    else {
                        uv_stat_t* s = &stat_req.statbuf;
                        
                        if(s != NULL) {
                            if (!S_ISREG(s->st_mode)) {
                                // If the file is a directory append `index.html` to the path and reopen it.
                                if (S_ISDIR(s->st_mode)) {
                                    if (rr->path_len+10 >= MAX_PATH_SIZE) {
                                        fprintf(stderr, "headers buffer too small: -4");
                                        req_res_free(rr);
                                        //return;
                                    }
                                    else {
                                        /* ToDo: Please do not use magic numbers.*/
                                        path_buf = malloc(rr->path_len+11);
                                        if(path_buf != NULL) {
                                            
                                            memcpy(path_buf, rr->path, rr->path_len);
                                            memcpy(path_buf+rr->path_len, "index.html\0", 11);
                                            free(rr->path);
                                            rr->path = path_buf;
                                            rr->path_len += 10;
                                            // Set the content type.
                                            memcpy(rr->content_type, "text/html", 9);
                                            rr->content_type_len = 9;
                                            // Close the directory file handle.
                                            rr->file = status;
                                            req_res_free_file(rr);
                                            // Open the new path.
                                            open_path_as_file(rr);
                                        }
                                        else {
                                            DEBUG("on_file_open error: memory leak, no handle for path_buf with length %d.\n", rr->path_len+11);
                                        }
                                    }
                                } else {
                                    // Not a file or directory, send a `404`.
                                    send_not_found(rr);
                                }
                                //return;
                            }
                        
                            // Store the file handle.
                            rr->file = status;
                            // Send the `200` response headers.
                            rr->read_on_write = 1;
                            req_res_init_file_buf(rr);
                            // Send the `200` response headers.
                            set_headers(rr, "200 OK");
                            send_headers_buf(rr);
                        }
                        else {
                            DEBUG("on_file_open error: &stat_req.statbuf is NULL.\n");
                        }
                    }
                }
            }
        }
        else {
            DEBUG("on_file_open error: req->result is NULL.\n");
        }
    }
    else {
        DEBUG("on_file_open error: req is NULL.\n");
    }
}