Beispiel #1
0
 CalJob(const std::string& outfile)
   : file_(outfile.c_str())
   , scene_id_(0)
 {
   if (!file_) throw std::runtime_error("Could not open outfile");
   write_headers(file_);
 }
TIDorb::core::cdr::BufferCDR*
TIDorb::core::comm::iiop::GIOPCancelRequestMessage::get_message_buffer()
{
  if (!_message_completed)
  {
    if (_header.getVersion() >= TIDorb::core::comm::iiop::Version::VERSION_1_2)
    {
      _message_buffer =
        new TIDorb::core::cdr::BufferCDR(TIDorb::core::comm::iiop::GIOPHeader::HEADER_SIZE +
                                         TIDorb::core::cdr::CDR::ULONG_SIZE);

      // write header
      TIDorb::core::cdr::CDROutputStream out(NULL,_message_buffer);
      _header.write(out);

      //write
      out.write_ulong(request_id);

      out = NULL;
      _message_completed = true;
      _headers_marshaled = true;
    }
    else
    {
      write_headers();
      _message_completed = true;
    }
  }

  return _message_buffer;
}
Beispiel #3
0
response_status
response_start(client_t *client)
{
    response_status ret ;
    if(client->status_code == 304){
        return write_headers(client, NULL, 0, 0);
    }

    if (CheckFileWrapper(client->response)) {
        DEBUG("use sendfile");
        //enable_cork(client);
        ret = start_response_file(client);
        if(ret == STATUS_OK){
            // sended header
            ret = process_sendfile(client);
        }
    }else{
        ret = start_response_write(client);
        DEBUG("start_response_write status_code %d ret = %d", client->status_code, ret);
        if(ret == STATUS_OK){
            // sended header
            ret = process_write(client);
        }
    }
    return ret;
}
Beispiel #4
0
static response_status
start_response_file(client_t *client)
{
    PyObject *filelike;
    FileWrapperObject *filewrap;
    int ret,in_fd, size;
    struct stat info;

    filewrap = (FileWrapperObject *)client->response;
    filelike = filewrap->filelike;

    in_fd = PyObject_AsFileDescriptor(filelike);
    if (in_fd == -1) {
        PyErr_Clear();
        DEBUG("can't get fd");
        return STATUS_ERROR;
    }
    ret = write_headers(client, NULL, 0, 1);
    if(!client->content_length_set){
        if (fstat(in_fd, &info) == -1){
            PyErr_SetFromErrno(PyExc_IOError);
            /* write_error_log(__FILE__, __LINE__);  */
            call_error_logger();
            return STATUS_ERROR;
        }

        size = info.st_size;
        client->content_length_set = 1;
        client->content_length = size;
    }
    return ret;

}
/**
 * handles a client request
 */
static int
write_request(stream_t *s, request_rec *r,
	      config_t *config, cluster_t *cluster, int *keepalive,
              int session_index, int backup_index,
              char *ip, char *session_id)
{
  int len;
  int code;
  int write_length;
  time_t new_time;
  time_t start_time = r->request_time;

  hmux_start_channel(s, 1);
  write_env(s, r, session_id);
  write_headers(s, r);
  write_added_headers(s, r);

  /* read post data */
  if (ap_should_client_block(r)) {
    char buf[BUF_LENGTH];
    int ack_size = s->cluster_srun->srun->send_buffer_size;
    int send_length = 0;

    while ((len = ap_get_client_block(r, buf, BUF_LENGTH)) > 0) {
      /* ap_reset_timeout(r); */
      cse_write_packet(s, HMUX_DATA, buf, len);

      send_length += len;
      
      if (ack_size <= send_length) {
	send_length = 0;
	cse_write_byte(s, HMUX_YIELD);
        code = send_data(s, r, HMUX_ACK, keepalive);
        if (code < 0 || code == HMUX_QUIT || code == HMUX_EXIT)
          break;
      }
    }
  }

  cse_write_byte(s, HMUX_QUIT);

  code = send_data(s, r, HMUX_QUIT, keepalive);

  if (code >= 0 || s->sent_data)
    return code;
  
  write_length = s->write_length; 
  if (cse_open_connection(s, cluster, session_index, backup_index,
                          r->request_time, r->pool)) {
    s->write_length = write_length;
    LOG(("retry connection %d\n", s->socket));
    
    return send_data(s, r, HMUX_QUIT, keepalive);
  }
  else {
    return HTTP_SERVICE_UNAVAILABLE;
  }
}
Beispiel #6
0
//Write all headers, empty line, and body
//TODO: support for live forwarding of chunked encoding.
static inline int write_common(HTTP_Message* message, int connection)
{
	//Write headers
	if(write_headers(message->headers, connection)) return 1;

	//Write blank line
	if(write_ref(es_temp("\r\n"), connection)) return 1;

	//Write body
	if(write_ref(es_ref(&message->body), connection)) return 1;

	return 0;
}
Beispiel #7
0
static void write_stats_full(request_rec *r, global_snapshot *gs, process_snapshot **sn)
{
	ap_rputs("<hr><h2>Tee status</h2>\n", r);
	write_global_stats_full(r, gs);
	ap_rputs("<table>\n", r);
	const char *headers[] = { "Slot", "PID", "Acc", "Status", "Queue Len", "Discarded", NULL };
	write_headers(r, headers);
	int i;
	for (i = 0; i < global_stats->count; i++) {
		if (sn[i])
			write_process_stats(r, i, sn[i]);
	}
	ap_rputs("</table>\n", r);
	ap_rputs(legend, r);
}
/**
 * handles a client request
 */
static int
write_request(stream_t *s, request_rec *r, config_t *config,
	      int session_index, int backup_index)
{
  int len;
  int code = -1;

  write_env(s, r);
  write_headers(s, r);
  write_added_headers(s, r);

  /* read post data */
  if (ap_should_client_block(r)) {
    char buf[BUF_LENGTH];
    int ack_size = s->cluster_srun->srun->send_buffer_size;
    int send_length = 0;

    while ((len = ap_get_client_block(r, buf, BUF_LENGTH)) > 0) {
      LOG(("%s:%d:write-request(): w-D %d\n", __FILE__, __LINE__, len));
      
      if (ack_size <= send_length + len && send_length > 0) {
        LOG(("%s:%d:write-request(): w-Y send_length=%d ack_size=%d\n",
             __FILE__, __LINE__, send_length, ack_size));
        
	send_length = 0;
	cse_write_byte(s, HMUX_YIELD);
        code = send_data(s, r);
        if (code != HMUX_ACK)
          break;
      }

      cse_write_packet(s, HMUX_DATA, buf, len);

      send_length += len;
    }
  }

  LOG(("%s:%d:write-request(): w-Q\n", __FILE__, __LINE__));

  cse_write_byte(s, HMUX_QUIT);
  code = send_data(s, r);

  LOG(("%s:%d:write_request(): return code %c\n", __FILE__, __LINE__, code));

  return code;
}
static void flv_output_data(void *data, struct encoder_packet *packet)
{
	struct flv_output     *stream = data;
	struct encoder_packet parsed_packet;

	if (!stream->sent_headers) {
		write_headers(stream);
		stream->sent_headers = true;
	}

	if (packet->type == OBS_ENCODER_VIDEO) {
		obs_parse_avc_packet(&parsed_packet, packet);
		write_packet(stream, &parsed_packet, false);
		obs_free_encoder_packet(&parsed_packet);
	} else {
		write_packet(stream, packet, false);
	}
}
Beispiel #10
0
int
response_start(client_t *client)
{
  int ret;
  enable_cork(client);
  if(client->status_code == 304){
    return write_headers(client);
  }
  ret = start_response_write(client);
#ifdef DEBUG
  printf("start_response_write ret = %d \n", ret);
#endif
  if(ret > 0){
    // sended header
    ret = processs_write(client);
  }
  return ret;
}
Beispiel #11
0
void run (int worker_id, int sock_fd, struct sockaddr addr, socklen_t addr_len) {
    
    headers_parse (sock_fd);
    if (headers_is_error (headers_get_state ()) || !headers_has_request()) {
        goto hangup;
    }
    
    char *name = get_request (1);
    char *strip = name;
    char response_buffer[255];
    while (*strip == '.' || *strip == '/') strip++;
    if (!*strip) {
        fprintf (stderr, "%s: No such file or directory\n", name);
        goto _404;
    }
    int len = strlen (strip);
    int file_fd;
    char *file = malloc (2 + len + 1);
    file[0] = '.';
    file[1] = '/';
    memcpy (file + 2, strip, len);
    file[len + 2] = 0;
    file_fd = open (file, O_RDONLY);
    free (file);

    struct stat info;
    if (file_fd == -1 || fstat (file_fd, &info)) {
        if (file_fd > 0) {
            close (file_fd);
        }
        file_fd = 0;
        perror (name);
        goto _404;
    }

    response_init (200);
    char content_length[25];
    sprintf (content_length, "%d", info.st_size);
    response_add ("Content-Length", content_length);
    if (write_headers (sock_fd)) {
        close (file_fd);
        goto _404;
    }
    len = read (file_fd, response_buffer, 255);
    while (len > 0) {
        if (write (sock_fd, response_buffer, len) < 0) {
            perror ("write");
            break;
        }
        len = read (file_fd, response_buffer, 255);
    }

    if (file_fd > 0) {
        close (file_fd);
    }
    goto hangup;

_404:
    response_init (404);
    write_headers (sock_fd);
    snprintf (response_buffer, 255, "File not found: '%s'\n", name);
    if (write (sock_fd, response_buffer, strlen (response_buffer)) < 0) {
        goto hangup;
    }
    goto hangup;

hangup:
    headers_cleanup ();
    hangup (sock_fd);
}
Beispiel #12
0
PIDX_return_code populate_block_layout_and_buffers(PIDX_io file, int svi, int evi, int mode, int partitioning_mode)
{
  // Three tasks
  // 1. Create the bitstring
  // 2. populate the block layout and aggregation related buffers
  // 3. Poplate the idx binary file hierarchy

  PIDX_time time = file->time;

  time->bit_string_start = PIDX_get_time();
  // calculates maxh and bitstring
  if (partitioning_mode == PIDX_IDX_IO)
  {
    if (populate_global_bit_string(file, mode) != PIDX_success)
    {
      fprintf(stderr,"File %s Line %d\n", __FILE__, __LINE__);
      return PIDX_err_file;
    }
  }
  else if (partitioning_mode == PIDX_LOCAL_PARTITION_IDX_IO)
  {
    if (populate_local_bit_string(file, mode) != PIDX_success)
    {
      fprintf(stderr,"File %s Line %d\n", __FILE__, __LINE__);
      return PIDX_err_file;
    }
  }

  // selects layout levels based on maxh
  select_io_mode(file);
  time->bit_string_end = PIDX_get_time();



  time->layout_start = PIDX_get_time();
  // calculates the block layoutven this is pure IDX only non-share block layout is populated
  if (populate_rst_block_layouts(file, svi, file->idx_b->hz_file0_from, file->idx_b->hz_n_file0_to) != PIDX_success)
  {
    fprintf(stderr,"File %s Line %d\n", __FILE__, __LINE__);
    return PIDX_err_file;
  }

  // Calculate the hz level upto which aggregation is possible
  if (find_agg_level(file, svi, evi) != PIDX_success)
  {
    fprintf(stderr,"File %s Line %d\n", __FILE__, __LINE__);
    return PIDX_err_file;
  }

  // Creates the agg and io ids
  if (create_agg_io_buffer(file) != PIDX_success)
  {
    fprintf(stderr,"File %s Line %d\n", __FILE__, __LINE__);
    return PIDX_err_file;
  }
  time->layout_end = PIDX_get_time();



  time->header_io_start = PIDX_get_time();
  // Creates the file heirarchy and writes the header info for all binary files
  if (write_headers(file, svi, evi, mode) != PIDX_success)
  {
    fprintf(stderr,"File %s Line %d\n", __FILE__, __LINE__);
    return PIDX_err_file;
  }
  time->header_io_end = PIDX_get_time();

  return PIDX_success;
}
Beispiel #13
0
/** The actual talking (user to answering machine) */
void AnswMachine::talk()
{
     char command[S_COMMAND];
     char messg_myaddr [S_MESSG];
     struct hostent *hp;
     FILE * fd = 0;      /* file descriptor, to write the message */
     char customline[S_CFGLINE];
     
#ifndef OLD_POPEN_METHOD  // never defined. Kept for systems without e.g. mkstemp.
     char fname[256];
     int fildes;
     int oldumask = umask(066);
       /* set permissions for temp file to rw- --- --- */
     int emptymail; /* 1 if empty mail allowed */
#endif
     int something_entered;
     
     hp = gethostbyaddr((char *)&caller_machine_addr, sizeof (struct in_addr), AF_INET);
     if (hp == (struct hostent *)0) 
	  TalkConnection::p_error("Answering machine : Remote machine unknown.");

     if ((!usercfg) || (!read_user_config("Mail",messg_myaddr,S_MESSG-1)))
       strcpy(messg_myaddr,local_user);

#ifdef OLD_POPEN_METHOD   // never defined
     snprintf(command,S_COMMAND,"%s %s",Options.mailprog,messg_myaddr);

    fd = popen(command,"w");
    if (!fd) 
      {
	snprintf(customline,S_CFGLINE,"Unable to open a pipe towards %s.",Options.mailprog);
	TalkConnection::p_error(customline);
      }
#else

    sprintf(fname, _PATH_TMP"/ktalkdXXXXXX");
    if ((fildes = mkstemp(fname)) == -1 || (fd = fdopen(fildes, "w+")) == 0) {
        TalkConnection::p_error("Unable to open temporary file");
    }

    umask(oldumask);
#endif
    
    write_headers(fd, hp, messg_myaddr, usercfg);

    /* read other options before setting usercfg to 0, below. */
    if ((!usercfg) || (!read_bool_user_config("EmptyMail",&emptymail)))
      /* try from user config file, otherwise default : */
      emptymail = 1;

    message("Connection established");

    if (usercfg) {
      if (!read_user_config("Msg1",customline,S_CFGLINE-1))
	{ message("Error reading Msg1"); end_user_config(); usercfg=0; }
    }

    /* No user-config'ed banner */
    if (!usercfg)
    { /* => Display Options.invitelines */
         talkconn->write_banner(Options.invitelines);
    }
    else if (mode==PROC_REQ_ANSWMACH_NOT_HERE)
    { /* => Display Options.NEUBanner* */
         talkconn->write_banner(Options.NEUBanner1);
         talkconn->write_banner(Options.NEUBanner2);
         talkconn->write_banner(Options.NEUBanner3);
    } else {
	 int linenr = 1; 
	 /* number of the Msg[1-*] line. is set to 0 after displaying banner*/
	 char m[]="Msg1"; /* used as key to read configuration */
	 
	 while (linenr) /* still something to write to the caller */
	      {
   		   talkconn->write_banner(customline);
                   
		   /* read next line in custom file. */
		   m[3]=(++linenr)+'0';
		   if (!read_user_config(m,customline,S_CFGLINE-1))
			linenr=0; /* end of message */			
	      }
    }
    /* Banner displayed. Let's take the message. */
    something_entered = read_message(fd);
#ifdef OLD_POPEN_METHOD   // never defined
    pclose(fd);
#else
    fclose(fd);

    if (something_entered || emptymail)
    { /* Don't send empty message, except if 'EmptyMail' has been set */
        int retcode;
	snprintf(command,S_COMMAND,"cat %s | %s %s",fname,Options.mailprog,messg_myaddr);
        retcode = system(command);
        if ((retcode==127) || (retcode==-1))
          syslog(LOG_ERR,"system() error : %m");
        else if (retcode!=0)
          syslog(LOG_WARNING,"%s : %m", command);
    }
    (void)unlink(fname);
#endif
}