about summary refs log tree commit diff stats
path: root/src/xmpp/capabilities.h
blob: 85f1d989ab023b77851d24c74276bc0204ae51b4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * capabilities.h
 *
 * Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
 *
 * This file is part of Profanity.
 *
 * Profanity is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Profanity is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Profanity.  If not, see <http://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give permission to
 * link the code of portions of this program with the OpenSSL library under
 * certain conditions as described in each individual source file, and
 * distribute linked combinations including the two.
 *
 * You must obey the GNU General Public License in all respects for all of the
 * code used other than OpenSSL. If you modify file(s) with this exception, you
 * may extend this exception to your version of the file(s), but you are not
 * obligated to do so. If you do not wish to do so, delete this exception
 * statement from your version. If you delete this exception statement from all
 * source files in the program, then also delete it here.
 *
 */

#ifndef XMPP_CAPABILITIES_H
#define XMPP_CAPABILITIES_H

#include <strophe.h>

#include "xmpp/xmpp.h"

void caps_init(void);

void caps_add_by_ver(const char * const ver, Capabilities *caps);
void caps_add_by_jid(const char * const jid, Capabilities *caps);
void caps_map_jid_to_ver(const char * const jid, const char * const ver);
gboolean caps_contains(const char * const ver);

char* caps_create_sha1_str(xmpp_stanza_t * const query);
xmpp_stanza_t* caps_create_query_response_stanza(xmpp_ctx_t * const ctx);
Capabilities* caps_create(xmpp_stanza_t *query);
char* caps_get_my_sha1(xmpp_ctx_t * const ctx);

#endif
ass="se">\n" " {1: number, foo: bar} <- copy 34 # test comment\n" "]\n" ); CHECK_TRACE_CONTENTS( "parse: product: {1: \"number\", \"foo\": \"bar\"}\n" ); CHECK_TRACE_COUNT("error", 0); } void test_dilated_reagent_with_comment_immediately_following() { load( "def main [\n" " 1:number <- copy {34: literal} # test comment\n" "]\n" ); CHECK_TRACE_COUNT("error", 0); } //: First augment next_word to group balanced brackets together. :(before "End next_word Special-cases") if (in.peek() == '(') return slurp_balanced_bracket(in); // treat curlies mostly like parens, but don't mess up labels if (start_of_dilated_reagent(in)) return slurp_balanced_bracket(in); :(code) // A curly is considered a label if it's the last thing on a line. Dilated // reagents should remain all on one line. bool start_of_dilated_reagent(istream& in) { if (in.peek() != '{') return false; int pos = in.tellg(); in.get(); // slurp '{' skip_whitespace_but_not_newline(in); char next = in.peek(); in.seekg(pos); return next != '\n'; } // Assume the first letter is an open bracket, and read everything until the // matching close bracket. // We balance {} () and []. string slurp_balanced_bracket(istream& in) { ostringstream result; char c; list<char> open_brackets; while (in >> c) { if (c == '(') open_brackets.push_back(c); if (c == ')') { if (open_brackets.empty() || open_brackets.back() != '(') { raise << "unbalanced ')'\n" << end(); continue; } assert(open_brackets.back() == '('); open_brackets.pop_back(); } if (c == '[') open_brackets.push_back(c); if (c == ']') { if (open_brackets.empty() || open_brackets.back() != '[') { raise << "unbalanced ']'\n" << end(); continue; } open_brackets.pop_back(); } if (c == '{') open_brackets.push_back(c); if (c == '}') { if (open_brackets.empty() || open_brackets.back() != '{') { raise << "unbalanced '}'\n" << end(); continue; } open_brackets.pop_back(); } result << c; if (open_brackets.empty()) break; } skip_whitespace_and_comments_but_not_newline(in); return result.str(); } :(after "Parsing reagent(string s)") if (starts_with(s, "{")) { assert(properties.empty()); istringstream in(s); in >> std::noskipws; in.get(); // skip '{' name = slurp_key(in); if (name.empty()) { raise << "invalid reagent '" << s << "' without a name\n" << end(); return; } if (name == "}") { raise << "invalid empty reagent '" << s << "'\n" << end(); return; } { string s = next_word(in); if (s.empty()) { assert(!has_data(in)); raise << "incomplete dilated reagent at end of file (0)\n" << end(); return; } string_tree* type_names = new string_tree(s); // End Parsing Dilated Reagent Type Property(type_names) type = new_type_tree(type_names); delete type_names; } while (has_data(in)) { string key = slurp_key(in); if (key.empty()) continue; if (key == "}") continue; string s = next_word(in); if (s.empty()) { assert(!has_data(in)); raise << "incomplete dilated reagent at end of file (1)\n" << end(); return; } string_tree* value = new string_tree(s); // End Parsing Dilated Reagent Property(value) properties.push_back(pair<string, string_tree*>(key, value)); } return; } :(code) string slurp_key(istream& in) { string result = next_word(in); if (result.empty()) { assert(!has_data(in)); raise << "incomplete dilated reagent at end of file (2)\n" << end(); return result; } while (!result.empty() && *result.rbegin() == ':') strip_last(result); while (isspace(in.peek()) || in.peek() == ':') in.get(); return result; }