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

Method process_query_dsc_dir

src/control.cc:1386–1421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1384}
1385
1386bool control_conn_t::process_query_dsc_dir()
1387{
1388 // packet contains command byte, spare byte, and service handle
1389 constexpr int pkt_size = 2 + sizeof(handle_t);
1390
1391 if (rbuf.get_length() < pkt_size) {
1392 chklen = pkt_size;
1393 return true;
1394 }
1395
1396 bool spare_ok = (rbuf[1] == 0);
1397 handle_t handle;
1398 rbuf.extract(&handle, 2, sizeof(handle));
1399 rbuf.consume(pkt_size);
1400 chklen = 0;
1401
1402 service_record *service = find_service_for_key(handle);
1403 if (service == nullptr || !spare_ok) {
1404 char nak_rep[] = { (char)cp_rply::NAK };
1405 return queue_packet(nak_rep, 1);
1406 }
1407
1408 // Reply:
1409 // 1 byte packet type = cp_rply::SVCDSCDIR
1410 // 4 bytes (uint32_t) = directory length (no nul terminator)
1411 // N bytes = directory (no nul)
1412 std::vector<char> reppkt;
1413 auto sdir_len = static_cast<uint32_t>(strlen(service->get_service_dsc_dir()));
1414 reppkt.resize(1 + sizeof(uint32_t) + sdir_len); // packet type, dir length, dir
1415 reppkt[0] = (char)cp_rply::SVCDSCDIR;
1416 std::memcpy(&reppkt[1], &sdir_len, sizeof(sdir_len));
1417 std::memcpy(&reppkt[1 + sizeof(uint32_t)], service->get_service_dsc_dir(), sdir_len);
1418
1419 if (!queue_packet(std::move(reppkt))) return false;
1420 return true;
1421}
1422
1423// Get current directory and store it at the specified position in a vector. The specified
1424// position may be beyond the current length of the vector. A null terminator is *not* appended.

Callers

nothing calls this directly

Calls 4

get_lengthMethod · 0.80
extractMethod · 0.80
consumeMethod · 0.80
get_service_dsc_dirMethod · 0.80

Tested by

no test coverage detected