File: SS_State_PARSE.cpp

package info (click to toggle)
ace 6.0.3%2Bdfsg-0.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 49,368 kB
  • sloc: cpp: 341,826; perl: 30,850; ansic: 20,952; makefile: 10,144; sh: 4,744; python: 828; exp: 787; yacc: 511; xml: 330; lex: 158; lisp: 116; csh: 48; tcl: 5
file content (61 lines) | stat: -rw-r--r-- 1,592 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// $Id: SS_State_PARSE.cpp 91730 2010-09-13 09:31:11Z johnnyw $

#include "SS_State_READ.h"
#include "SS_State_PARSE.h"
#include "SS_State_WRITE.h"
#include "SS_State_ERROR.h"
#include "SS_State_DONE.h"
#include "SS_Data.h"

int
TeraSS_State_PARSE::service (JAWS_Event_Completer *ec, void *data)
{
  JAWS_Event_Result fake_good_result (0, JAWS_Event_Result::JE_OK);
  JAWS_Event_Result fake_bad_result (0, JAWS_Event_Result::JE_ERROR);

  // Parse the request.
  TeraSS_Data *tdata = (TeraSS_Data *) data;
  char *p = tdata->mb ().rd_ptr ();
  while (p < tdata->mb ().wr_ptr () && *p != '\r' && *p != '\n')
    p++;
  if (p == tdata->mb ().wr_ptr ())
    {
      // Return to the READ state.
      ec->input_complete (fake_bad_result, 0);
      return 0;
    }
  *p = '\0';

  // Make us transition into the WRITE state.
  ec->input_complete (fake_good_result, 0);
  return 0;
}

JAWS_Protocol_State *
TeraSS_State_PARSE::transition ( const JAWS_Event_Result &result
                               , void *
                               , void *
                               )
{
  // In the PARSE state, we transition to WRITE on success,
  // and to READ on failure.

  JAWS_Protocol_State *next_state = 0;

  switch (result.status ())
    {
    case JAWS_Event_Result::JE_OK:
      next_state = TeraSS_State_WRITE::instance ();
      break;
    case JAWS_Event_Result::JE_ERROR:
      next_state = TeraSS_State_READ::instance ();
      break;
    default:
      // Just bail unceremoniously.
      next_state = TeraSS_State_DONE::instance ();
      break;
    }

  return next_state;
}