This introductory document includes installation instructions, example usage of the library, and pointers for what to read next.
tar -zxvf libkarmaclient-<version>.tar.gz cd libkarmaclient-<version> ./configure make make install
The basic types provided by this library are:
Apart from the primary interface, there are a number of ways to better interface your product with libkarmaclient.
// Create a new query. ks_bquery_t *q = ks_bquery_new(); // Set a distinctive id on the query. ks_bquery_id_set(q, "myid", 4); // Scan through your data and add identities to the query. // Add any relevant identities. The server will decompose and // analyse them. Distinguish "special" identities with tags. ks_bquery_identity_add_tagged(q, "fred@foo.com", KS_IDT_DOMAIN_NAME, KS_TAG_SMTP_ENV_MAIL_FROM); ks_bquery_identity_add_tagged(q, "123.45.6.7", KS_IDT_IP4_ADDRESS, KS_TAG_SMTP_CLIENT_IP); ks_bquery_identity_add(q, "http://www.phisher.com/?abc", KS_IDT_URL); // Specify the feedset you want to query. ks_bquery_composite_add(q, "karmasphere.email-sender"); // Set any query flags. This example returns all facts individually. ks_bquery_flags_set(q, KS_FL_FACTS);
// If you want to use the builtin POSIX socket functions with retries: ks_socket_t *k = ks_socket_new(NULL, 0, IPPROTO_UDP); ks_response_t *r = ks_socket_ask(k, q, 0); // Now check that r != NULL.
// If you use nio, get the raw packet data and send it: ks_string_t *s = ks_bquery_packet(q); my_nio_send(socket, ks_string_get(s), ks_string_len(s)); // Then receive raw packet data and parse it: char[] buf; int len = my_nio_recv(buf); ks_response_t *r = ks_response_bparse(buf, len);
// Check whether the query generated an error. ks_string_t *e = ks_response_error(r); if (e != NULL) { ... } // Retrieve combinations from the query. ks_combination_t *c = ks_response_combination(r, "mycombiner"); printf("%d : %s", ks_combination_score(c), ks_combination_data(c)); // Inspect the original facts, if KS_FL_FACTS was set. for (int i = 0; i < ks_response_facts_length(r); i++) { ks_fact_t *fact = ks_response_fact(r, i); printf("%s : %d : %s", ks_fact_identity(fact), ks_fact_score(fact), ks_fact_data(fact)); }
ks_bquery_free(q); ks_response_free(r);
1.5.1