LCOV - code coverage report
Current view: top level - waltz/grpc - fd_grpc_codec.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 1 19 5.3 %
Date: 2025-07-01 05:00:49 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_waltz_grpc_fd_grpc_codec_h
       2             : #define HEADER_fd_src_waltz_grpc_fd_grpc_codec_h
       3             : 
       4             : /* fd_grpc_codec.h provides helpers for gRPC over HTTP/2.
       5             : 
       6             :    https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md */
       7             : 
       8             : #include "../h2/fd_h2_base.h"
       9             : #include "../h2/fd_h2_hdr_match.h"
      10             : 
      11             : /* gRPC protocol status codes
      12             :    https://github.com/grpc/grpc/blob/v1.71.0/doc/statuscodes.md */
      13             : 
      14           0 : #define FD_GRPC_STATUS_OK                        0
      15           0 : #define FD_GRPC_STATUS_CANCELLED                 1
      16          36 : #define FD_GRPC_STATUS_UNKNOWN                   2
      17           0 : #define FD_GRPC_STATUS_INVALID_ARGUMENT          3
      18           0 : #define FD_GRPC_STATUS_DEADLINE_EXCEEDED         4
      19           0 : #define FD_GRPC_STATUS_NOT_FOUND                 5
      20           0 : #define FD_GRPC_STATUS_ALREADY_EXISTS            6
      21           0 : #define FD_GRPC_STATUS_PERMISSION_DENIED         7
      22           0 : #define FD_GRPC_STATUS_RESOURCE_EXHAUSTED        8
      23           0 : #define FD_GRPC_STATUS_FAILED_PRECONDITION       9
      24           0 : #define FD_GRPC_STATUS_ABORTED                  10
      25           0 : #define FD_GRPC_STATUS_OUT_OF_RANGE             11
      26           0 : #define FD_GRPC_STATUS_UNIMPLEMENTED            12
      27           0 : #define FD_GRPC_STATUS_INTERNAL                 13
      28           0 : #define FD_GRPC_STATUS_UNAVAILABLE              14
      29           0 : #define FD_GRPC_STATUS_DATA_LOSS                15
      30           0 : #define FD_GRPC_STATUS_UNAUTHENTICATED          16
      31             : 
      32             : /* Internal IDs for gRPC headers */
      33             : 
      34           0 : #define FD_GRPC_HDR_STATUS  0x101
      35           0 : #define FD_GRPC_HDR_MESSAGE 0x102
      36             : 
      37             : /* fd_grpc_hdr_t is the header part of a Length-Prefixed-Message. */
      38             : 
      39             : struct __attribute__((packed)) fd_grpc_hdr {
      40             :   uchar compressed; /* in [0,1] */
      41             :   uint  msg_sz;     /* net order */
      42             :   /* msg_sz bytes follow ... */
      43             : };
      44             : 
      45             : typedef struct fd_grpc_hdr fd_grpc_hdr_t;
      46             : 
      47             : struct fd_grpc_req_hdrs {
      48             :   char const * host; /* excluding port */
      49             :   ulong        host_len; /* <=255 */
      50             :   ushort       port;
      51             :   char const * path;
      52             :   ulong        path_len;
      53             :   uint         https : 1; /* 1 if https, 0 if http */
      54             :   char const * bearer_auth;
      55             :   ulong        bearer_auth_len;
      56             : };
      57             : 
      58             : typedef struct fd_grpc_req_hdrs fd_grpc_req_hdrs_t;
      59             : 
      60             : struct fd_grpc_resp_hdrs {
      61             :   /* Headers */
      62             : 
      63             :   uint h2_status;   /* 0 implies invalid */
      64             :   uint is_grpc_proto : 1;
      65             : 
      66             :   /* Trailers */
      67             : 
      68             :   uint grpc_status; /* 0 implies invalid */
      69             :   char grpc_msg[ 1008 ];
      70             :   uint grpc_msg_len;
      71             : };
      72             : 
      73             : typedef struct fd_grpc_resp_hdrs fd_grpc_resp_hdrs_t;
      74             : 
      75             : FD_PROTOTYPES_BEGIN
      76             : 
      77             : /* fd_grpc_h2_gen_request_hdrs generates a HEADERS frame with gRPC
      78             :    request headers.  Returns FD_H2_SUCCESS on success.  On failure,
      79             :    returns FD_H2_INTERNAL_ERROR (insufficient space in rbuf_tx). */
      80             : 
      81             : int
      82             : fd_grpc_h2_gen_request_hdrs( fd_grpc_req_hdrs_t const * req,
      83             :                              fd_h2_rbuf_t *             rbuf_tx,
      84             :                              char const *               version,
      85             :                              ulong                      version_len );
      86             : 
      87             : /* fd_grpc_h2_rec_response_hdrs consumes a HEADERS frame and recovers
      88             :    selected gRPC request headers.  Ignores unknown headers.  Returns
      89             :    FD_H2_SUCCESS on success, or FD_H2_ERR_PROTOCOL on parse failure.
      90             :    Logs reason for failure. */
      91             : 
      92             : int
      93             : fd_grpc_h2_read_response_hdrs( fd_grpc_resp_hdrs_t *       resp,
      94             :                                fd_h2_hdr_matcher_t const * matcher,
      95             :                                uchar const *               payload,
      96             :                                ulong                       payload_sz );
      97             : 
      98             : char const *
      99             : fd_grpc_status_cstr( uint status );
     100             : 
     101             : FD_PROTOTYPES_END
     102             : 
     103             : #endif /* HEADER_fd_src_waltz_grpc_fd_grpc_codec_h */

Generated by: LCOV version 1.14