MCPcopy Create free account
hub / github.com/davmac314/dinit / process_query_name

Method process_query_name

src/control.cc:1105–1143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1103}
1104
1105bool control_conn_t::process_query_name()
1106{
1107 // 1 byte packet type
1108 // 1 byte reserved
1109 // handle: service
1110 constexpr int pkt_size = 2 + sizeof(handle_t);
1111
1112 if (rbuf.get_length() < pkt_size) {
1113 chklen = pkt_size;
1114 return true;
1115 }
1116
1117 handle_t handle;
1118 rbuf.extract(&handle, 2, sizeof(handle));
1119 rbuf.consume(pkt_size);
1120 chklen = 0;
1121
1122 service_record *service = find_service_for_key(handle);
1123 if (service == nullptr || service->get_name().length() > std::numeric_limits<uint16_t>::max()) {
1124 char nak_rep[] = { (char)cp_rply::NAK };
1125 return queue_packet(nak_rep, 1);
1126 }
1127
1128 // Reply:
1129 // 1 byte packet type = cp_rply::SERVICENAME
1130 // 1 byte reserved
1131 // uint16_t length
1132 // N bytes name
1133
1134 std::vector<char> reply;
1135 const std::string &name = service->get_name();
1136 uint16_t name_length = name.length();
1137 reply.resize(2 + sizeof(uint16_t) + name_length);
1138 reply[0] = (char)cp_rply::SERVICENAME;
1139 memcpy(reply.data() + 2, &name_length, sizeof(name_length));
1140 memcpy(reply.data() + 2 + sizeof(uint16_t), name.c_str(), name_length);
1141
1142 return queue_packet(std::move(reply));
1143}
1144
1145bool control_conn_t::process_setenv()
1146{

Callers

nothing calls this directly

Calls 6

get_lengthMethod · 0.80
extractMethod · 0.80
consumeMethod · 0.80
lengthMethod · 0.45
dataMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected