Skip to content

Instantly share code, notes, and snippets.

@mogigoma
Created July 9, 2010 22:44
Show Gist options
  • Save mogigoma/470204 to your computer and use it in GitHub Desktop.
Save mogigoma/470204 to your computer and use it in GitHub Desktop.
/*
* [opaque]
*
* Tokens
* ------
* AUT_OPAQUE
*
* The body of this element contains hex data.
*/
/*
* token_t *
* au_to_opaque(const char *data, u_int16_t bytes);
*/
static void
el_opaque(const char **attr, const char *body)
{
token_t *tok;
char *buf;
int i, j;
if (attr != NULL)
return;
/* Ensure body has proper hexadecimal prefix. */
if (strcmp(body, "0x") != 0)
errx(1, "Element 'opaque' has invalid body.");
/* Allocate space for buffer. */
buf = malloc(strlen(body) + 1);
if (buf == NULL)
err(1, "[malloc]");
/* Parse body. */
for (i = 2, j = 0; body[i] != '\0'; i += 2, j++) {
if (sscanf(&body[i], "%02hhx", &buf[j]) != 1)
errx(1, "Element 'opaque' has invalid body.");
}
/* Create token. */
tok = au_to_opaque(buf, j);
rec_append(tok);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment