feat: 对接Python,暴露接口

This commit is contained in:
2026-03-30 22:48:36 +08:00
parent 24467c04c0
commit d678bfc326
22 changed files with 1311 additions and 51 deletions

View File

@@ -8,11 +8,12 @@ static const char *protocol_message_type_table[] = {
"text",
"file",
"register",
"error"
"error",
"binary"
};
const char *protocol_message_type_name(message_type_t type) {
if ((int) type < 0 || type >= MSG_TYPE_INVALID) {
if ((int) type < 0 || (size_t) type >= OMNI_ARRAY_LEN(protocol_message_type_table)) {
return "invalid";
}
return protocol_message_type_table[type];
@@ -102,6 +103,11 @@ int protocol_validate_message(const message_t *msg, char *err, size_t err_len) {
return protocol_set_err(err, err_len, "protocol: missing file name");
}
break;
case MSG_TYPE_BINARY:
if (msg->file_name[0] != '\0') {
return protocol_set_err(err, err_len, "protocol: unexpected file name");
}
break;
case MSG_TYPE_REGISTER:
if (strcmp(msg->to, SERVER_PEER_ID) != 0) {
return protocol_set_err(err, err_len, "protocol: invalid register target");