src/wire/packet_manager.cpp
bool PacketManager::ProcessStartupPacket(InputPacket *pkt) {
  std::string token, value;
  std::unique_ptr<OutputPacket> response(new OutputPacket());

  int32_t proto_version = PacketGetInt(pkt, sizeof(int32_t));

  // Only protocol version 3 is supported
  if (PROTO_MAJOR_VERSION(proto_version) != 3) {
    LOG_ERROR("Protocol error: Only protocol version 3 is supported.");
    exit(EXIT_FAILURE);
  }

  // TODO: check for more malformed cases
  // iterate till the end
  for (;;) {
    // loop end case?
    if (pkt->ptr >= pkt->len) break;
    GetStringToken(pkt, token);

    // if the option database was found
    if (token.compare("database") == 0) {
      // loop end?
      if (pkt->ptr >= pkt->len) break;
      GetStringToken(pkt, client_.dbname);
    } else if (token.compare(("user")) == 0) {
      // loop end?
      if (pkt->ptr >= pkt->len) break;
      GetStringToken(pkt, client_.user);
    } else {
      if (pkt->ptr >= pkt->len) break;
      GetStringToken(pkt, value);
      client_.cmdline_options[token] = value;
    }
  }

  // send auth-ok ('R')
  response->msg_type = NetworkMessageType::AUTHENTICATION_REQUEST;
  PacketPutInt(response.get(), 0, 4);
  responses.push_back(std::move(response));

  // Send the parameterStatus map ('S')
  for (auto it = parameter_status_map_.begin();
       it != parameter_status_map_.end(); it++) {
    MakeHardcodedParameterStatus(*it);
  }

  // ready-for-query packet -> 'Z'
  SendReadyForQuery(NetworkTransactionStateType::IDLE);

  // we need to send the response right away
  force_flush = true;

  return true;
}
/*
 * process_startup_packet - Processes the startup packet
 *  (after the size field of the header).
 */
Processes the startup packet
(after the size field of the header).
Processes the startup packet ( after the size field of the header ) .
bool PacketManager::ProcessStartupPacket(InputPacket *pkt) {
  std::string token, value;
  std::unique_ptr<OutputPacket> response(new OutputPacket());
  int32_t proto_version = PacketGetInt(pkt, sizeof(int32_t));
  if (PROTO_MAJOR_VERSION(proto_version) != 3) {
    LOG_ERROR("Protocol error: Only protocol version 3 is supported.");
    exit(EXIT_FAILURE);
  }
  for (;;) {
    if (pkt->ptr >= pkt->len) break;
    GetStringToken(pkt, token);
    if (token.compare("database") == 0) {
      if (pkt->ptr >= pkt->len) break;
      GetStringToken(pkt, client_.dbname);
    } else if (token.compare(("user")) == 0) {
      if (pkt->ptr >= pkt->len) break;
      GetStringToken(pkt, client_.user);
    } else {
      if (pkt->ptr >= pkt->len) break;
      GetStringToken(pkt, value);
      client_.cmdline_options[token] = value;
    }
  }
  response->msg_type = NetworkMessageType::AUTHENTICATION_REQUEST;
  PacketPutInt(response.get(), 0, 4);
  responses.push_back(std::move(response));
  for (auto it = parameter_status_map_.begin();
       it != parameter_status_map_.end(); it++) {
    MakeHardcodedParameterStatus(*it);
  }
  SendReadyForQuery(NetworkTransactionStateType::IDLE);
  force_flush = true;
  return true;
}
bool PacketManager :: ProcessStartupPacket ( InputPacket * pkt ) { std :: string token , value ; std :: unique_ptr < OutputPacket > response ( new OutputPacket ( ) ) ; int32_t proto_version = PacketGetInt ( pkt , sizeof ( int32_t ) ) ; if ( PROTO_MAJOR_VERSION ( proto_version ) != 3 ) { LOG_ERROR ( " " ) ; exit ( EXIT_FAILURE ) ; } for ( ; ; ) { if ( pkt -> ptr >= pkt -> len ) break ; GetStringToken ( pkt , token ) ; if ( token . compare ( " " ) == 0 ) { if ( pkt -> ptr >= pkt -> len ) break ; GetStringToken ( pkt , client_ . dbname ) ; } else if ( token . compare ( ( " " ) ) == 0 ) { if ( pkt -> ptr >= pkt -> len ) break ; GetStringToken ( pkt , client_ . user ) ; } else { if ( pkt -> ptr >= pkt -> len ) break ; GetStringToken ( pkt , value ) ; client_ . cmdline_options [ token ] = value ; } } response -> msg_type = NetworkMessageType :: AUTHENTICATION_REQUEST ; PacketPutInt ( response . get ( ) , 0 , 4 ) ; responses . push_back ( std :: move ( response ) ) ; for ( auto it = parameter_status_map_ . begin ( ) ; it != parameter_status_map_ . end ( ) ; it ++ ) { MakeHardcodedParameterStatus ( * it ) ; } SendReadyForQuery ( NetworkTransactionStateType :: IDLE ) ; force_flush = true ; return true ; }
process_startup_packet - Processes the startup packet
  (after the size field of the header).
process_startup_packet - Processes the startup packet ( after the size field of the header ) .
// Only protocol version 3 is supported // TODO: check for more malformed cases // iterate till the end // loop end case? // if the option database was found // loop end? // loop end? // send auth-ok ('R') // Send the parameterStatus map ('S') // ready-for-query packet -> 'Z' // we need to send the response right away