コード例 #1
0
ファイル: pint-hint.c プロジェクト: snsl/pvfs2-osd
void encode_PINT_hint(char **pptr, const PINT_hint *hint)
{
    int transfer_count = 0;
    const PINT_hint *tmp_hint = hint;

    /* count up the transferable hints */
    while(tmp_hint)
    {
        if(tmp_hint->flags & PINT_HINT_TRANSFER)
        {
            transfer_count++;
        }

        tmp_hint = tmp_hint->next;
    }

    /* encode the number of hints to be transferred */
    encode_uint32_t(pptr, &transfer_count);

    tmp_hint = hint;
    while(tmp_hint)
    {
        /* encode the hint type */
        if(tmp_hint->flags & PINT_HINT_TRANSFER)
        {
            encode_uint32_t(pptr, &tmp_hint->type);

            /* if the type is unknown, encode the type string */
            if(tmp_hint->type == PINT_HINT_UNKNOWN)
            {
                encode_string(pptr, &tmp_hint->type_string);
                tmp_hint->encode(pptr, (void *)&tmp_hint->value);
            }
            else
            {
               /* encode the hint using the encode function provided */
               tmp_hint->encode(pptr, tmp_hint->value);
            }
        }

        tmp_hint = tmp_hint->next;
    }
}
コード例 #2
0
uint8_t *stun_generate_binding_request (const uint8_t *username, 
					uint32_t username_len,
					const uint8_t *password, 
					uint32_t password_len,
					uint32_t priority,
					transaction_id_t **tid,
					uint32_t *return_msg_len)
{
  stun_message_t msg;
  uint8_t *buffer;
  uint8_t *body;

  if (password != NULL && username == NULL) return NULL;

  stun_generate_request(&msg, STUN_BINDING_REQ,
			username, username_len,
			password, password_len);


  if (priority != 0) {
    msg.ice_priority.is_valid = true;
    msg.ice_priority.content = priority;
  }

  buffer = prepare_stun_msg(&msg, tid, return_msg_len, false);
  if (buffer == NULL || *return_msg_len == sizeof(stun_header_t)) {
    return buffer;
  }

  // header is complete.
  body = buffer + sizeof(stun_header_t);
  memset(body, 0, *return_msg_len - sizeof(stun_header_t));
  
  body += encode_uint8ptr(body, STUN_MA_USERNAME, username, username_len);
  body += encode_uint32_t(body, STUN_MA_ICE_PRIORITY, msg.ice_priority);
  body += stun_encode_message_integrity(buffer, *return_msg_len,
					password, password_len,
					body);
  return buffer;
}