示例#1
0
int printlog_cgi(HttpState* state)
{
	auto int bytes_written;

	switch(state->substate) {
		case PRTLOG_INIT:
			state->p=&prtlog_header[0];
			state->substate=PRTLOG_HEADER;
         read_log_reset();

			// intentionally no break

		case PRTLOG_HEADER:
			if(*state->p) {
				bytes_written=sock_fastwrite(&state->s,state->p,strlen(state->p));
				if(bytes_written>0)
					state->p+=bytes_written;
			} else {
				state->p=NULL;
				state->offset=0;
				state->substate=PRTLOG_PRTITEM;
			}
			break;

		case PRTLOG_PRTITEM:
			if(state->p==NULL || *state->p=='\0' || *state->p=='\xff') {
         	read_log(state->buffer, 128);

         	if(strlen(state->buffer))
            {
            	//still reading out log contents
				 	state->p=state->buffer;
               state->offset = 0;
				} else {
					state->offset=0;
					state->p=&prtlog_footer[0];
					state->substate=PRTLOG_FOOTER;
				}
				state->offset++;
			} else {
				bytes_written=sock_fastwrite(&state->s,state->p,strlen(state->p));
				if(bytes_written>0) {
					state->p+=bytes_written;
				}
			}
			break;

		case PRTLOG_FOOTER:
			if(*state->p) {
				bytes_written=sock_fastwrite(&state->s,state->p,strlen(state->p));
				if(bytes_written>0)
					state->p+=bytes_written;
			} else
				return 1;			// done

			break;
	}
	return 0;
}
示例#2
0
int printlog_cgi(HttpState *state)
{
   auto int bytes_written;

   switch (state->substate)
   {
   case PRTLOG_INIT:
      // Temporarily cast const away since the p member in HttpState is a
      // general purpose pointer
      state->p = (char *) &prtlog_header[0];
      state->substate = PRTLOG_HEADER;
      read_log_reset();

      // intentionally no break

   case PRTLOG_HEADER:
      if (*state->p)
      {
         bytes_written = sock_fastwrite(&state->s, state->p, strlen(state->p));
         if (bytes_written > 0)
         {
            state->p += bytes_written;
         }
      }
      else
      {
         state->p = NULL;
         state->offset = 0;
         state->substate = PRTLOG_PRTITEM;
      }
      break;

   case PRTLOG_PRTITEM:
      if (state->p == NULL || *state->p == '\0' || *state->p == '\xff')
      {
         read_log(state->buffer, 128);
         if (strlen(state->buffer))
         {
            //still reading out log contents
            state->p = state->buffer;
            state->offset = 0;
         }
         else
         {
            state->offset = 0;
            // Temporarily cast const away since the p member in HttpState is
            // a general purpose pointer
            state->p = (char *) &prtlog_footer[0];
            state->substate = PRTLOG_FOOTER;
         }
         ++state->offset;
      }
      else
      {
         bytes_written = sock_fastwrite(&state->s, state->p, strlen(state->p));
         if (bytes_written > 0)
         {
            state->p += bytes_written;
         }
      }
      break;

   case PRTLOG_FOOTER:
      if (*state->p)
      {
         bytes_written = sock_fastwrite(&state->s, state->p, strlen(state->p));
         if (bytes_written > 0)
         {
            state->p += bytes_written;
         }
      }
      else
      {
         return 1;   // done
      }
      break;
   }
   return 0;
}