Пример #1
0
/* Detect a video media */
int ogm_detect_video (ogg_packet *packet) {

   stream_header sth;

   if ( ((*(packet->packet) & PACKET_TYPE_BITS ) == PACKET_TYPE_HEADER) &&
       (packet->bytes >= (int)(sizeof(old_stream_header) + 1)) ) {

      /* Other type stream */
      copy_headers(&sth, (old_stream_header *)&(packet->packet[1]), packet->bytes);

      if (!strncmp(sth.streamtype, "video", 5)) return 1;
   }

   return 0;
}
Пример #2
0
void RecordList::read_all() {

    matching_header->clear(); // TODO Check what is good for the GUI
    matching_records->clear();
    matching_timesync_data->clear();

    scout->read_all_existing();

    //scout->dump_all();

    qDebug() << "Number of records: " << scout->record_info().size();

    copy_headers();
    copy_lines();
}
Пример #3
0
void writing(char name_file_message[SIZE_NAME_FILE], char name_file_case[SIZE_NAME_FILE], char name_file_result[SIZE_NAME_FILE])
{
   FILE *file_message, *file_case, *file_result;

   check_length_name_file (name_file_message);
   exist_file_check(name_file_message);

   check_length_name_file (name_file_case);
   exist_file_check(name_file_case);

   check_length_name_file (name_file_result);

   file_message = fopen (name_file_message, "r+b");
   file_case = fopen(name_file_case, "r+b");
   file_result = fopen(name_file_result, "w+b");

   if ((file_message == NULL) ||
      (file_case    == NULL) ||
      (file_result  == NULL))
   {
      std::cerr << "Error opening of file. " << std::endl;
      exit(1);
   }

   check_size_of_files_writing(file_case, file_message, name_file_message);

   fseek(file_message, 0, 0);

   copy_headers(file_case, file_result);
   write_int(strlen(name_file_message), file_case, file_result);
   write_string(name_file_message, file_case, file_result);
   write_int(filelength (fileno(file_message)), file_case, file_result);
   write_data(file_message, file_case, file_result, filelength (fileno(file_message))); 
   write_tail(file_case, file_result); 

   fclose (file_message);
   fclose (file_case);
   fclose (file_result);
}
Пример #4
0
static int
lisp_handler (request_rec * r)
{
  lisp_cfg_t * cfg
    = (ap_get_module_config ((r->per_dir_config), (&lisp_module)));
  int content_length = (-1);
  int keep_socket_p = 0;
  apr_socket_t * socket;
  const char * request_content_length = 0;

  cfg = local_lisp_cfg(cfg);

  if ((strcmp ((r->handler), "lisp-handler")) != 0)
    return (DECLINED);

  /* Open a connection to the Lisp process.  */
  ML_LOG_DEBUG (r, "open lisp connection");
  CVT_ERROR ((open_lisp_socket (cfg)), "opening connection to Lisp");
  (SERVER_SOCKET_SAFE_P (cfg)) = 0;
  socket = (SERVER_SOCKET (cfg));

  /* Remove any timeout that might be left over from earlier.  */
  ML_LOG_DEBUG (r, "clear socket timeout");
  CVT_ERROR ((apr_socket_timeout_set (socket, (-1))), "clearing read timeout");
  
  /* Convert environment variables to headers and send them.  */
  ML_LOG_DEBUG (r, "write env-var headers");
  ap_add_cgi_vars (r);
  ap_add_common_vars (r);
  if ((r->subprocess_env) != 0)
    CVT_ERROR
      ((copy_headers
	 	((r->subprocess_env), map_env_var_to_lisp_header, socket)),
              "writing to Lisp");

  /* Send this before client headers so ASSOC can be used to grab it
     without worrying about some joker sending a server-id header of
     his own.  (Robert Macomber) */
  ML_LOG_DEBUG (r, "write headers");
  CVT_ERROR ((write_lisp_header (socket, "server-id", (cfg->server_id))),
	     	     "writing to Lisp");

  CVT_ERROR ((write_lisp_header (socket, "server-baseversion", AP_SERVER_BASEVERSION)),
	     	     "writing to Lisp");
  CVT_ERROR ((write_lisp_header (socket, "modlisp-version", VERSION_STRING)),
	     	     "writing to Lisp");
  CVT_ERROR ((write_lisp_header (socket, "modlisp-major-version", "2")),
	     	     "writing to Lisp");
  /* Send all the remaining headers.  */
  if ((r->headers_in) != 0)
    CVT_ERROR
      ((copy_headers ((r->headers_in), map_header_to_lisp_header, socket)),
              "writing to Lisp");

  request_content_length = apr_table_get(r->headers_in, "Content-Length");

  /* Send the end-of-headers marker.  */
  ML_LOG_DEBUG (r, "write end-of-headers");
  CVT_ERROR ((write_lisp_line (socket, "end")), "writing to Lisp");

  /* Send the request entity.  */
  RELAY_HTTP_ERROR (ap_setup_client_block (r, REQUEST_CHUNKED_DECHUNK));
  if (ap_should_client_block (r))
    {
      char buffer [4096];
      ML_LOG_DEBUG (r, "write entity");
      while (1)
	{
	  long n_read = (ap_get_client_block (r, buffer, (sizeof (buffer))));
	  if (n_read < 0)
	    {
	      ML_LOG_PERROR (r, "error reading from client");
	      close_lisp_socket (cfg);
	      return (HTTP_INTERNAL_SERVER_ERROR);
	    }

	  /* for chunked case, when nread == 0, we will write 
	   * a terminating 0.*/
	  
	  {
	    apr_status_t status = APR_SUCCESS; 
	    
	    /* if there's no Content-Type header, the data must be chunked */
	    if (request_content_length == NULL)
	      status = write_lisp_data_chunk (socket, buffer, n_read);
	    else if (n_read != 0)
	      status = write_lisp_data (socket, buffer, n_read);
	    
	    if (APR_SUCCESS != status)
	      {
		while ((ap_get_client_block (r, buffer, sizeof(buffer)))
		       > 0)
		  ;
		ML_LOG_ERROR (status, r, "writing to Lisp");
		close_lisp_socket (cfg);
		return (HTTP_INTERNAL_SERVER_ERROR);
	      }
	  }
	  if( n_read == 0)
	    break;
	}
    }

  /* Set up read timeout so we don't hang forever if Lisp is wedged.  */
  ML_LOG_DEBUG (r, "set socket timeout");
  CVT_ERROR ((apr_socket_timeout_set (socket, READ_TIMEOUT)),
	     	     "setting read timeout");

  /* Read the headers and process them.  */
  ML_LOG_DEBUG (r, "read headers");
  while (1)
    {
      char header_name [4096];
      char header_value [MAX_STRING_LEN];
      CVT_ERROR
	((read_lisp_line (socket, header_name, (sizeof (header_name)))),
	 	 "reading from Lisp");

      if ((strcasecmp (header_name, "end")) == 0)
	break;

      CVT_ERROR
	((read_lisp_line (socket, header_value, (sizeof (header_value)))),
	 	 "reading from Lisp");

      if ((strcasecmp (header_name, "content-type")) == 0)
	{
	  char * tmp = (apr_pstrdup ((r->pool), header_value));
	  ap_content_type_tolower (tmp);
	  (r->content_type) = tmp;
	}
      else if ((strcasecmp (header_name, "status")) == 0)
	{
	  (r->status) = (atoi (header_value));
	  (r->status_line) = (apr_pstrdup ((r->pool), header_value));
	}
      else if ((strcasecmp (header_name, "location")) == 0)
	apr_table_set ((r->headers_out), header_name, header_value);
      else if ((strcasecmp (header_name, "content-length")) == 0)
	{
	  apr_table_set ((r->headers_out), header_name, header_value);
	  content_length = (atoi (header_value));
	}
      else if ((strcasecmp (header_name, "lisp-content-length")) == 0)
	{
	  content_length = (atoi (header_value));
	}
      else if ((strcasecmp (header_name, "last-modified")) == 0)
	{
	  apr_time_t mtime = (apr_date_parse_http (header_value));
	  r->mtime = mtime;
	  ap_set_last_modified (r);
	}
      else if ((strcasecmp (header_name, "keep-socket")) == 0)
	keep_socket_p = (atoi (header_value));
      else if ((strcasecmp (header_name, "log-emerg")) == 0)
	ap_log_error (APLOG_MARK, APLOG_EMERG, APR_SUCCESS, (r->server),
				  		      "%s", header_value);
      else if ((strcasecmp (header_name, "log-alert")) == 0)
	ap_log_error (APLOG_MARK, APLOG_ALERT, APR_SUCCESS, (r->server),
				  		      "%s", header_value);
      else if ((strcasecmp (header_name, "log-crit")) == 0)
	ap_log_error (APLOG_MARK, APLOG_CRIT, APR_SUCCESS, (r->server),
				  		      "%s", header_value);
      else if ((strcasecmp (header_name, "log-error")) == 0)
	ap_log_error (APLOG_MARK, APLOG_ERR, APR_SUCCESS, (r->server),
				  		      "%s", header_value);
      else if ((strcasecmp (header_name, "log-warning")) == 0)
	ap_log_error (APLOG_MARK, APLOG_WARNING, APR_SUCCESS, (r->server),
				  		      "%s", header_value);
      else if ((strcasecmp (header_name, "log-notice")) == 0)
	ap_log_error (APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, (r->server),
				  		      "%s", header_value);
      else if ((strcasecmp (header_name, "log-info")) == 0)
	ap_log_error (APLOG_MARK, APLOG_INFO, APR_SUCCESS, (r->server),
				  		      "%s", header_value);
      else if ((strcasecmp (header_name, "log-debug")) == 0)
	ap_log_error (APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, (r->server),
				  		      "%s", header_value);
      else if ((strcasecmp (header_name, "log")) == 0)
	ap_log_error (APLOG_MARK, APLOG_ERR, APR_SUCCESS, (r->server),
				  		      "%s", header_value);
      else if ((strcasecmp (header_name, "note")) == 0)
	{
	  char * p = (strchr (header_value, ' '));
	  if (p != 0)
	    {
	      (*p++) = '\0';
	      apr_table_setn ((r->notes),
			      			      (apr_pstrdup ((r->pool), header_value)),
						      			      (apr_pstrdup ((r->pool), p)));
	    }
	}
      else if ((strcasecmp (header_name, "set-cookie")) == 0)
	{
	  apr_table_add ((r->headers_out), header_name, header_value);
	}
      else
	apr_table_set ((r->headers_out), header_name, header_value);
    }

  /* Copy the reply entity from Lisp to the client...  */
  //  if (content_length > 0)
  {
    unsigned int n_read = 0;
    input_buffer_t * buffer;

    ML_LOG_DEBUG (r, "read entity");
    CVT_ERROR ((get_input_buffer (socket, (&buffer))), "reading from Lisp");
    while ((buffer->start) <= (buffer->end))
      {
	apr_status_t fill_status;
        unsigned int n_bytes = ((buffer->end) - (buffer->start));
        n_read += n_bytes;
        if ((content_length >= 0) && (n_read > content_length))
          {
            n_bytes -= (n_read - content_length);
            n_read -= (n_read - content_length);
          }
        /* ...unless it's a HEAD request. */
        if (!r->header_only && !write_client_data (r, (buffer->start), n_bytes))
          {
            close_lisp_socket (cfg);
            return (HTTP_INTERNAL_SERVER_ERROR);
          }
        (buffer->start) += n_bytes;
        if (n_read == content_length)
          break;

        fill_status = fill_input_buffer (socket);
        if ((fill_status == APR_EOF) && (content_length < 0))
          break;
        else
          CVT_ERROR (fill_status, "reading from Lisp");
      }
  }
  if ((content_length < 0) || (!keep_socket_p))
    CVT_ERROR ((close_lisp_socket (cfg)), "closing connection to Lisp");
  else
    (SERVER_SOCKET_SAFE_P (cfg)) = 1;
  ML_LOG_DEBUG (r, "request finished");
  return (OK);
}