Skip to content

Commit

Permalink
Make it compile
Browse files Browse the repository at this point in the history
  • Loading branch information
uNetworkingAB committed Feb 10, 2019
1 parent a419221 commit 3e4e70d
Showing 1 changed file with 55 additions and 55 deletions.
110 changes: 55 additions & 55 deletions src/WebSocketExtensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,61 +39,6 @@ enum ExtensionTokens {
TOK_CLIENT_MAX_WINDOW_BITS = 2348
};

template <bool isServer>
class ExtensionsNegotiator {
protected:
int options;

public:
ExtensionsNegotiator(int wantedOptions) {
options = wantedOptions;
}

std::string generateOffer() {
std::string extensionsOffer;
if (options & Options::PERMESSAGE_DEFLATE) {
extensionsOffer += "permessage-deflate";

if (options & Options::CLIENT_NO_CONTEXT_TAKEOVER) {
extensionsOffer += "; client_no_context_takeover";
}

/* It is questionable sending this improves anything */
/*if (options & Options::SERVER_NO_CONTEXT_TAKEOVER) {
extensionsOffer += "; server_no_context_takeover";
}*/
}

return extensionsOffer;
}

void readOffer(std::string_view offer) {
if (isServer) {
ExtensionsParser extensionsParser(offer.data(), offer.length());
if ((options & PERMESSAGE_DEFLATE) && extensionsParser.perMessageDeflate) {
if (extensionsParser.clientNoContextTakeover || (options & CLIENT_NO_CONTEXT_TAKEOVER)) {
options |= CLIENT_NO_CONTEXT_TAKEOVER;
}

/* We leave this option for us to read even if the client did not send it */
if (extensionsParser.serverNoContextTakeover) {
options |= SERVER_NO_CONTEXT_TAKEOVER;
}/* else {
options &= ~SERVER_NO_CONTEXT_TAKEOVER;
}*/
} else {
options &= ~PERMESSAGE_DEFLATE;
}
} else {
// todo!
}
}

int getNegotiatedOptions() {
return options;
}
};

class ExtensionsParser {
private:
int *lastInteger = nullptr;
Expand Down Expand Up @@ -156,6 +101,61 @@ class ExtensionsParser {
}
};

template <bool isServer>
class ExtensionsNegotiator {
protected:
int options;

public:
ExtensionsNegotiator(int wantedOptions) {
options = wantedOptions;
}

std::string generateOffer() {
std::string extensionsOffer;
if (options & Options::PERMESSAGE_DEFLATE) {
extensionsOffer += "permessage-deflate";

if (options & Options::CLIENT_NO_CONTEXT_TAKEOVER) {
extensionsOffer += "; client_no_context_takeover";
}

/* It is questionable sending this improves anything */
/*if (options & Options::SERVER_NO_CONTEXT_TAKEOVER) {
extensionsOffer += "; server_no_context_takeover";
}*/
}

return extensionsOffer;
}

void readOffer(std::string_view offer) {
if (isServer) {
ExtensionsParser extensionsParser(offer.data(), offer.length());
if ((options & PERMESSAGE_DEFLATE) && extensionsParser.perMessageDeflate) {
if (extensionsParser.clientNoContextTakeover || (options & CLIENT_NO_CONTEXT_TAKEOVER)) {
options |= CLIENT_NO_CONTEXT_TAKEOVER;
}

/* We leave this option for us to read even if the client did not send it */
if (extensionsParser.serverNoContextTakeover) {
options |= SERVER_NO_CONTEXT_TAKEOVER;
}/* else {
options &= ~SERVER_NO_CONTEXT_TAKEOVER;
}*/
} else {
options &= ~PERMESSAGE_DEFLATE;
}
} else {
// todo!
}
}

int getNegotiatedOptions() {
return options;
}
};

}

#endif // WEBSOCKETEXTENSIONS_H

0 comments on commit 3e4e70d

Please sign in to comment.