struct _JsonNode* mu_msg_to_json (MuMsg *msg, unsigned docid, const MuMsgIterThreadInfo *ti, MuMsgOptions opts) { JsonNode *node; JsonBuilder *bob; time_t t; size_t s; g_return_val_if_fail (msg, NULL); g_return_val_if_fail (!((opts & MU_MSG_OPTION_HEADERS_ONLY) && (opts & MU_MSG_OPTION_EXTRACT_IMAGES)),NULL); bob = json_builder_new (); bob = json_builder_begin_object (bob); if (ti) add_thread_info (bob, ti); add_string_member (bob, "subject", mu_msg_get_subject (msg)); /* in the no-headers-only case (see below) we get a more complete list * of contacts, so no need to get them here if that's the case */ if (opts & MU_MSG_OPTION_HEADERS_ONLY) add_contacts (bob, msg); t = mu_msg_get_date (msg); if (t != (time_t)-1) add_int_member (bob, "date", t); s = mu_msg_get_size (msg); if (s != (size_t)-1) add_int_member (bob, "size", s); add_string_member (bob, "message-id", mu_msg_get_msgid (msg)); add_string_member (bob, "mailing-list", mu_msg_get_mailing_list (msg)); add_string_member (bob, "path", mu_msg_get_path (msg)); add_string_member (bob, "maildir", mu_msg_get_maildir (msg)); add_string_member (bob, "priority", mu_msg_prio_name(mu_msg_get_prio(msg))); add_flags (bob, msg); add_list_member (bob, "tags", mu_msg_get_tags(msg)); add_list_member (bob, "references", mu_msg_get_references (msg)); add_string_member (bob, "in-reply-to", mu_msg_get_header (msg, "In-Reply-To")); /* headers are retrieved from the database, views from the * message file file attr things can only be gotten from the * file (ie., mu view), not from the database (mu find). */ if (!(opts & MU_MSG_OPTION_HEADERS_ONLY)) add_file_parts (bob, msg, opts); bob = json_builder_end_object (bob); node = json_builder_get_root (bob); g_clear_object (&bob); return node; }
static void /* ie., parts that require opening the message file */ add_file_parts (JsonBuilder *bob, MuMsg *msg, MuMsgOptions opts) { const char *str; GError *err; err = NULL; if (!mu_msg_load_msg_file (msg, &err)) { g_warning ("failed to load message file: %s", err ? err->message : "some error occured"); g_clear_error (&err); return; } add_parts (bob, msg, opts); add_contacts (bob, msg); /* add the user-agent / x-mailer */ str = mu_msg_get_header (msg, "User-Agent"); if (!str) str = mu_msg_get_header (msg, "X-Mailer"); add_string_member (bob, "user-agent", str); add_body_txt_params (bob, msg, opts); add_string_member (bob, "body-txt", mu_msg_get_body_text(msg, opts)); add_string_member (bob, "body-html", mu_msg_get_body_html(msg, opts)); }
int save_aux(struct sip_msg* _m, str* forced_binding, char* _d, char* _f, char* _s) { struct save_ctx sctx; contact_t* c; contact_t* forced_c; int st; str uri; str flags_s; pv_value_t val; rerrno = R_FINE; memset( &sctx, 0 , sizeof(sctx)); sctx.max_contacts = -1; sctx.flags = 0; if (_f && _f[0]!=0) { if (fixup_get_svalue( _m, (gparam_p)_f, &flags_s)!=0) { LM_ERR("invalid flags parameter"); return -1; } for( st=0 ; st< flags_s.len ; st++ ) { switch (flags_s.s[st]) { case 'm': sctx.flags |= REG_SAVE_MEMORY_FLAG; break; case 'r': sctx.flags |= REG_SAVE_NOREPLY_FLAG; break; case 's': sctx.flags |= REG_SAVE_SOCKET_FLAG; break; case 'v': sctx.flags |= REG_SAVE_PATH_RECEIVED_FLAG; break; case 'f': sctx.flags |= REG_SAVE_FORCE_REG_FLAG; break; case 'c': sctx.max_contacts = 0; while (st<flags_s.len-1 && isdigit(flags_s.s[st+1])) { sctx.max_contacts = sctx.max_contacts*10 + flags_s.s[st+1] - '0'; st++; } break; case 'p': if (st<flags_s.len-1) { st++; if (flags_s.s[st]=='2') { sctx.flags |= REG_SAVE_PATH_STRICT_FLAG; break; } if (flags_s.s[st]=='1') { sctx.flags |= REG_SAVE_PATH_LAZY_FLAG; break; } if (flags_s.s[st]=='0') { sctx.flags |= REG_SAVE_PATH_OFF_FLAG; break; } } default: LM_WARN("unsuported flag %c \n",flags_s.s[st]); } } } if(route_type == ONREPLY_ROUTE) sctx.flags |= REG_SAVE_NOREPLY_FLAG; /* if no max_contact per AOR is defined, use the global one */ if (sctx.max_contacts == -1) sctx.max_contacts = max_contacts; if (parse_message(_m) < 0) { goto error; } if (forced_binding) { if (parse_contacts(forced_binding, &forced_c) < 0) { LM_ERR("Unable to parse forced binding [%.*s]\n", forced_binding->len, forced_binding->s); goto error; } /* prevent processing all the headers from the message */ reset_first_contact(); st = 0; c = forced_c; } else { if (check_contacts(_m, &st) > 0) { goto error; } c = get_first_contact(_m); } get_act_time(); if (_s) { if (pv_get_spec_value( _m, (pv_spec_p)_s, &val)!=0) { LM_ERR("failed to get PV value\n"); return -1; } if ( (val.flags&PV_VAL_STR)==0 ) { LM_ERR("PV vals is not string\n"); return -1; } uri = val.rs; } else { uri = get_to(_m)->uri; } if (extract_aor( &uri, &sctx.aor) < 0) { LM_ERR("failed to extract Address Of Record\n"); goto error; } if (c == 0) { if (st) { if (star((udomain_t*)_d, &sctx) < 0) goto error; } else { if (no_contacts((udomain_t*)_d, &sctx.aor) < 0) goto error; } } else { if (add_contacts(_m, c, (udomain_t*)_d, &sctx) < 0) goto error; } update_stat(accepted_registrations, 1); if (!is_cflag_set(REG_SAVE_NOREPLY_FLAG) && (send_reply(_m,sctx.flags)<0)) return -1; return 1; error: update_stat(rejected_registrations, 1); if ( !is_cflag_set(REG_SAVE_NOREPLY_FLAG) ) send_reply(_m,sctx.flags); return 0; }
int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str *_uri) { contact_t* c; int st, mode; str aor; int ret; sip_uri_t *u; rr_t *route; struct sip_uri puri; param_hooks_t hooks; param_t *params; contact_t *contact; int use_ob = 1, use_regid = 1; u = parse_to_uri(_m); if(u==NULL) goto error; rerrno = R_FINE; ret = 1; if (parse_message(_m) < 0) { goto error; } if (check_contacts(_m, &st) > 0) { goto error; } if (parse_supported(_m) == 0) { if (!(get_supported(_m) & F_OPTION_TAG_OUTBOUND) && reg_outbound_mode == REG_OUTBOUND_REQUIRE) { LM_WARN("Outbound required by server and not supported by UAC\n"); rerrno = R_OB_UNSUP; goto error; } } if (parse_require(_m) == 0) { if ((get_require(_m) & F_OPTION_TAG_OUTBOUND) && reg_outbound_mode == REG_OUTBOUND_NONE) { LM_WARN("Outbound required by UAC and not supported by server\n"); rerrno = R_OB_REQD; goto error; } } if (reg_outbound_mode != REG_OUTBOUND_NONE && _m->contact && _m->contact->parsed && !(parse_headers(_m, HDR_VIA2_F, 0) == -1 || _m->via2 == 0 || _m->via2->error != PARSE_OK)) { /* Outbound supported on server, and more than one Via: - not the first hop */ if (!(parse_headers(_m, HDR_PATH_F, 0) == -1 || _m->path == 0)) { route = (rr_t *)0; if (parse_rr_body(_m->path->body.s, _m->path->body.len, &route) < 0) { LM_ERR("Failed to parse Path: header body\n"); goto error; } if (parse_uri(route->nameaddr.uri.s, route->nameaddr.uri.len, &puri) < 0) { LM_ERR("Failed to parse Path: URI\n"); goto error; } if (parse_params(&puri.params, CLASS_URI, &hooks, ¶ms) != 0) { LM_ERR("Failed to parse Path: URI parameters\n"); goto error; } if (!hooks.uri.ob) { /* No ;ob parameter to top Path: URI - no outbound */ use_ob = 0; } } else { /* No Path: header - no outbound */ use_ob = 0; } contact = ((contact_body_t *) _m->contact->parsed)->contacts; if (!contact) { LM_ERR("empty Contact:\n"); goto error; } if ((use_ob == 0) && (reg_regid_mode == REG_REGID_OUTBOUND)) { if ((get_supported(_m) & F_OPTION_TAG_OUTBOUND) && contact->reg_id) { LM_WARN("Outbound used by UAC but not supported by edge proxy\n"); rerrno = R_OB_UNSUP_EDGE; goto error; } else { /* ignore ;reg-id parameter */ use_regid = 0; } } } get_act_time(); c = get_first_contact(_m); if (extract_aor((_uri)?_uri:&get_to(_m)->uri, &aor, NULL) < 0) { LM_ERR("failed to extract Address Of Record\n"); goto error; } mem_only = is_cflag_set(REG_SAVE_MEM_FL)?FL_MEM:FL_NONE; if (c == 0) { if (st) { if (star(_m, (udomain_t*)_d, &aor, &u->host) < 0) goto error; else ret=3; } else { if (no_contacts(_m, (udomain_t*)_d, &aor, &u->host) < 0) goto error; else ret=4; } } else { mode = is_cflag_set(REG_SAVE_REPL_FL)?1:0; if ((ret=add_contacts(_m, (udomain_t*)_d, &aor, mode, use_regid)) < 0) goto error; ret = (ret==0)?1:ret; } update_stat(accepted_registrations, 1); /* Only send reply upon request, not upon reply */ if ((is_route_type(REQUEST_ROUTE) || is_route_type(FAILURE_ROUTE)) && !is_cflag_set(REG_SAVE_NORPL_FL) && (reg_send_reply(_m) < 0)) return -1; return ret; error: update_stat(rejected_registrations, 1); if (is_route_type(REQUEST_ROUTE) && !is_cflag_set(REG_SAVE_NORPL_FL) ) reg_send_reply(_m); return 0; }
static gboolean start_tests (gpointer data) { EwsBookBackendSqliteDB *ebsdb; gboolean populated = FALSE; gchar *vcard_str = NULL, *sexp; EBookQuery *q; GSList *uids = NULL; gboolean store_vcard = FALSE; g_print ("Creating the sqlitedb \n"); op = "create sqlitedb"; ebsdb = ews_book_backend_sqlitedb_new (cache_path, email, folderid, folder_name, store_vcard, &error); if (error) goto exit; add_contacts (ebsdb); if (error) goto exit; g_print ("Getting is_populated \n"); op = "set is_populated"; ews_book_backend_sqlitedb_set_is_populated (ebsdb, folderid, TRUE, &error); if (error) goto exit; g_print ("Setting is_populated \n"); op = "set is_populated"; populated = ews_book_backend_sqlitedb_get_is_populated (ebsdb, folderid, &error); if (error) goto exit; g_print ("Populated: %d \n", populated); g_print ("Setting key value \n"); op = "set key/value"; ews_book_backend_sqlitedb_set_key_value (ebsdb, folderid, "customkey", "stored", &error); if (error) goto exit; g_print ("Get Vcard string \n"); op = "get vcard string"; vcard_str = ews_book_backend_sqlitedb_get_vcard_string (ebsdb, folderid, uid, NULL, NULL, &error); if (error) goto exit; g_print ("VCard: %s \n", vcard_str); g_free (vcard_str); q = e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_CONTAINS, "test"); sexp = e_book_query_to_string (q); search_db (ebsdb, "summary query", sexp); e_book_query_unref (q); g_free (sexp); if (error) goto exit; if (store_vcard) { q = e_book_query_any_field_contains ("word"); sexp = e_book_query_to_string (q); search_db (ebsdb, "full_search query", sexp); e_book_query_unref (q); g_free (sexp); if (error) goto exit; } g_print ("Delete contact \n"); op = "delete contact"; uids = g_slist_append (uids, (gchar *) uid); ews_book_backend_sqlitedb_remove_contacts (ebsdb, folderid, uids, &error); g_slist_free (uids); if (error) goto exit; g_print ("Delete addressbook \n"); op = "delete addressbook"; ews_book_backend_sqlitedb_delete_addressbook (ebsdb, folderid, &error); exit: g_object_unref (ebsdb); quit_tests (); return FALSE; }
int save_aux(struct sip_msg* _m, str* forced_binding, void* _d, str* flags_s, str* uri, str* _owtag) { struct save_ctx sctx; contact_t* c; contact_t* forced_c = NULL; int st; rerrno = R_FINE; memset( &sctx, 0 , sizeof(sctx)); sctx.max_contacts = -1; sctx.flags = 0; sctx.min_expires = min_expires; sctx.max_expires = max_expires; if ( flags_s ) { for( st=0 ; st< flags_s->len ; st++ ) { switch (flags_s->s[st]) { case 'm': sctx.flags |= REG_SAVE_MEMORY_FLAG; break; case 'r': sctx.flags |= REG_SAVE_NOREPLY_FLAG; break; case 's': sctx.flags |= REG_SAVE_SOCKET_FLAG; break; case 'v': sctx.flags |= REG_SAVE_PATH_RECEIVED_FLAG; break; case 'f': sctx.flags |= REG_SAVE_FORCE_REG_FLAG; break; case 'c': sctx.max_contacts = 0; while (st<flags_s->len-1 && isdigit(flags_s->s[st+1])) { sctx.max_contacts = sctx.max_contacts*10 + flags_s->s[st+1] - '0'; st++; } break; case 'e': sctx.min_expires = 0; while (st<flags_s->len-1 && isdigit(flags_s->s[st+1])) { sctx.min_expires = sctx.min_expires*10 + flags_s->s[st+1] - '0'; st++; } break; case 'E': sctx.max_expires = 0; while (st<flags_s->len-1 && isdigit(flags_s->s[st+1])) { sctx.max_expires = sctx.max_expires*10 + flags_s->s[st+1] - '0'; st++; } break; case 'p': if (st<flags_s->len-1) { st++; if (flags_s->s[st]=='2') { sctx.flags |= REG_SAVE_PATH_STRICT_FLAG; break; } if (flags_s->s[st]=='1') { sctx.flags |= REG_SAVE_PATH_LAZY_FLAG; break; } if (flags_s->s[st]=='0') { sctx.flags |= REG_SAVE_PATH_OFF_FLAG; break; } } default: LM_WARN("unsupported flag %c \n",flags_s->s[st]); } } } if(route_type == ONREPLY_ROUTE) sctx.flags |= REG_SAVE_NOREPLY_FLAG; /* if no max_contact per AOR is defined, use the global one */ if (sctx.max_contacts == -1) sctx.max_contacts = max_contacts; if (parse_reg_headers(_m) < 0) { goto error; } if (forced_binding) { if (parse_contacts(forced_binding, &forced_c) < 0) { LM_ERR("Unable to parse forced binding [%.*s]\n", forced_binding->len, forced_binding->s); goto error; } /* prevent processing all the headers from the message */ reset_first_contact(); st = 0; c = forced_c; } else { if (check_contacts(_m, &st) > 0) { goto error; } c = get_first_contact(_m); } update_act_time(); if (!uri) uri = &(get_to(_m)->uri); if (_owtag) sctx.ownership_tag = *_owtag; if (extract_aor(uri, &sctx.aor,0,0) < 0) { LM_ERR("failed to extract Address Of Record\n"); goto error; } if (c == 0) { if (st) { if (star((udomain_t*)_d, &sctx,_m) < 0) goto error; } else { if (no_contacts((udomain_t*)_d, &sctx.aor,_m) < 0) goto error; } } else { if (add_contacts(_m, c, (udomain_t*)_d, &sctx) < 0) goto error; } update_stat(accepted_registrations, 1); if (!is_cflag_set(REG_SAVE_NOREPLY_FLAG) && (send_reply(_m,sctx.flags)<0)) goto return_minus_one; if (forced_c) free_contacts(&forced_c); return 1; error: update_stat(rejected_registrations, 1); if ( !is_cflag_set(REG_SAVE_NOREPLY_FLAG) ) send_reply(_m,sctx.flags); if (forced_c) free_contacts(&forced_c); return -2; return_minus_one: if (forced_c) free_contacts(&forced_c); return -1; }
int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str *_uri) { contact_t* c; int st, mode; str aor; int ret; sip_uri_t *u; u = parse_to_uri(_m); if(u==NULL) goto error; rerrno = R_FINE; ret = 1; if (parse_message(_m) < 0) { goto error; } if (check_contacts(_m, &st) > 0) { goto error; } if (parse_supported(_m) == 0) { if (!(((struct supported_body *)_m->supported->parsed)->supported_all & F_SUPPORTED_OUTBOUND) && reg_outbound_mode == REG_OUTBOUND_REQUIRE) { LM_WARN("Outbound required by server and not supported by UAC\n"); rerrno = R_OB_UNSUP; goto error; } } get_act_time(); c = get_first_contact(_m); if (extract_aor((_uri)?_uri:&get_to(_m)->uri, &aor, NULL) < 0) { LM_ERR("failed to extract Address Of Record\n"); goto error; } mem_only = is_cflag_set(REG_SAVE_MEM_FL)?FL_MEM:FL_NONE; if (c == 0) { if (st) { if (star(_m, (udomain_t*)_d, &aor, &u->host) < 0) goto error; else ret=3; } else { if (no_contacts(_m, (udomain_t*)_d, &aor, &u->host) < 0) goto error; else ret=4; } } else { mode = is_cflag_set(REG_SAVE_REPL_FL)?1:0; if ((ret=add_contacts(_m, (udomain_t*)_d, &aor, mode)) < 0) goto error; ret = (ret==0)?1:ret; } update_stat(accepted_registrations, 1); /* Only send reply upon request, not upon reply */ if ((is_route_type(REQUEST_ROUTE)) && !is_cflag_set(REG_SAVE_NORPL_FL) && (reg_send_reply(_m) < 0)) return -1; return ret; error: update_stat(rejected_registrations, 1); if (is_route_type(REQUEST_ROUTE) && !is_cflag_set(REG_SAVE_NORPL_FL) ) reg_send_reply(_m); return 0; }