Skip to content

Instantly share code, notes, and snippets.

@ahf
Created May 20, 2011 14:15
Show Gist options
  • Save ahf/982979 to your computer and use it in GitHub Desktop.
Save ahf/982979 to your computer and use it in GitHub Desktop.
#include <ratbox_lib.h>
#include "websocket.h"
struct WebSocketKey *parse_websocket_key(const char *s) {
struct WebSocketKey *r;
int i;
r = rb_malloc(sizeof(struct WebSocketKey));
r->digits = 0;
r->spaces = 0;
for (i = 0; s[i]; ++i) {
if (s[i] == ' ') {
r->spaces++;
continue;
}
if (s[i] >= '0' && s[i] <= '9') {
r->digits = r->digits * 10 + (uint32_t)s[i] - '0';
}
}
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment