/* ml_refresh */ static void _ml_refresh(MailingLists * ml, MailerFolder * folder, MailerMessage * message) { char const * id; if(folder == NULL) { gtk_widget_hide(ml->folder); gtk_widget_hide(ml->message); gtk_widget_hide(ml->name); return; } gtk_label_set_text(GTK_LABEL(ml->folder), folder_get_name(folder)); gtk_widget_show(ml->folder); if(message == NULL) { gtk_widget_hide(ml->message); gtk_widget_hide(ml->name); return; } if((id = message_get_header(message, "List-Id")) == NULL) { gtk_label_set_text(GTK_LABEL(ml->message), "Not a mailing-list"); gtk_widget_show(ml->message); gtk_widget_hide(ml->name); return; } /* XXX parse and beautify the list's name */ gtk_widget_hide(ml->message); gtk_label_set_text(GTK_LABEL(ml->name), id); gtk_widget_show(ml->name); }
static SEND_ONE_MESSAGE_RESULT send_one_message(MESSAGE_SENDER_INSTANCE* message_sender_instance, MESSAGE_WITH_CALLBACK* message_with_callback, MESSAGE_HANDLE message) { SEND_ONE_MESSAGE_RESULT result; size_t encoded_size; size_t total_encoded_size = 0; MESSAGE_BODY_TYPE message_body_type; message_format message_format; if ((message_get_body_type(message, &message_body_type) != 0) || (message_get_message_format(message, &message_format) != 0)) { result = SEND_ONE_MESSAGE_ERROR; } else { // header HEADER_HANDLE header; AMQP_VALUE header_amqp_value; PROPERTIES_HANDLE properties; AMQP_VALUE properties_amqp_value; AMQP_VALUE application_properties; AMQP_VALUE application_properties_value; AMQP_VALUE body_amqp_value = NULL; size_t body_data_count; message_get_header(message, &header); header_amqp_value = amqpvalue_create_header(header); if (header != NULL) { amqpvalue_get_encoded_size(header_amqp_value, &encoded_size); total_encoded_size += encoded_size; } // properties message_get_properties(message, &properties); properties_amqp_value = amqpvalue_create_properties(properties); if (properties != NULL) { amqpvalue_get_encoded_size(properties_amqp_value, &encoded_size); total_encoded_size += encoded_size; } // application properties message_get_application_properties(message, &application_properties); application_properties_value = amqpvalue_create_application_properties(application_properties); if (application_properties != NULL) { amqpvalue_get_encoded_size(application_properties_value, &encoded_size); total_encoded_size += encoded_size; } result = SEND_ONE_MESSAGE_OK; // body - amqp data switch (message_body_type) { default: result = SEND_ONE_MESSAGE_ERROR; break; case MESSAGE_BODY_TYPE_VALUE: { AMQP_VALUE message_body_amqp_value; if (message_get_inplace_body_amqp_value(message, &message_body_amqp_value) != 0) { result = SEND_ONE_MESSAGE_ERROR; } else { body_amqp_value = amqpvalue_create_amqp_value(message_body_amqp_value); if ((body_amqp_value == NULL) || (amqpvalue_get_encoded_size(body_amqp_value, &encoded_size) != 0)) { result = SEND_ONE_MESSAGE_ERROR; } else { total_encoded_size += encoded_size; } } break; } case MESSAGE_BODY_TYPE_DATA: { BINARY_DATA binary_data; size_t i; if (message_get_body_amqp_data_count(message, &body_data_count) != 0) { result = SEND_ONE_MESSAGE_ERROR; } else { for (i = 0; i < body_data_count; i++) { if (message_get_body_amqp_data(message, i, &binary_data) != 0) { result = SEND_ONE_MESSAGE_ERROR; } else { amqp_binary binary_value = { binary_data.bytes, binary_data.length }; AMQP_VALUE body_amqp_data = amqpvalue_create_data(binary_value); if (body_amqp_data == NULL) { result = SEND_ONE_MESSAGE_ERROR; } else { if (amqpvalue_get_encoded_size(body_amqp_data, &encoded_size) != 0) { result = SEND_ONE_MESSAGE_ERROR; } else { total_encoded_size += encoded_size; } amqpvalue_destroy(body_amqp_data); } } } } break; } } if (result == 0) { void* data_bytes = amqpalloc_malloc(total_encoded_size); PAYLOAD payload = { data_bytes, 0 }; result = SEND_ONE_MESSAGE_OK; if (header != NULL) { if (amqpvalue_encode(header_amqp_value, encode_bytes, &payload) != 0) { result = SEND_ONE_MESSAGE_ERROR; } log_message_chunk(message_sender_instance, "Header:", header_amqp_value); } if ((result == SEND_ONE_MESSAGE_OK) && (properties != NULL)) { if (amqpvalue_encode(properties_amqp_value, encode_bytes, &payload) != 0) { result = SEND_ONE_MESSAGE_ERROR; } log_message_chunk(message_sender_instance, "Properties:", properties_amqp_value); } if ((result == SEND_ONE_MESSAGE_OK) && (application_properties != NULL)) { if (amqpvalue_encode(application_properties_value, encode_bytes, &payload) != 0) { result = SEND_ONE_MESSAGE_ERROR; } log_message_chunk(message_sender_instance, "Application properties:", application_properties_value); } if (result == SEND_ONE_MESSAGE_OK) { switch (message_body_type) { case MESSAGE_BODY_TYPE_VALUE: { if (amqpvalue_encode(body_amqp_value, encode_bytes, &payload) != 0) { result = SEND_ONE_MESSAGE_ERROR; } log_message_chunk(message_sender_instance, "Body - amqp value:", body_amqp_value); break; } case MESSAGE_BODY_TYPE_DATA: { BINARY_DATA binary_data; size_t i; for (i = 0; i < body_data_count; i++) { if (message_get_body_amqp_data(message, i, &binary_data) != 0) { result = SEND_ONE_MESSAGE_ERROR; } else { amqp_binary binary_value = { binary_data.bytes, binary_data.length }; AMQP_VALUE body_amqp_data = amqpvalue_create_data(binary_value); if (body_amqp_data == NULL) { result = SEND_ONE_MESSAGE_ERROR; } else { if (amqpvalue_encode(body_amqp_data, encode_bytes, &payload) != 0) { result = SEND_ONE_MESSAGE_ERROR; break; } amqpvalue_destroy(body_amqp_data); } } } break; } } } if (result == SEND_ONE_MESSAGE_OK) { message_with_callback->message_send_state = MESSAGE_SEND_STATE_PENDING; switch (link_transfer(message_sender_instance->link, message_format, &payload, 1, on_delivery_settled, message_with_callback)) { default: case LINK_TRANSFER_ERROR: if (message_with_callback->on_message_send_complete != NULL) { message_with_callback->on_message_send_complete(message_with_callback->context, MESSAGE_SEND_ERROR); } result = SEND_ONE_MESSAGE_ERROR; break; case LINK_TRANSFER_BUSY: message_with_callback->message_send_state = MESSAGE_SEND_STATE_NOT_SENT; result = SEND_ONE_MESSAGE_BUSY; break; case LINK_TRANSFER_OK: result = SEND_ONE_MESSAGE_OK; break; } } amqpalloc_free(data_bytes); if (body_amqp_value != NULL) { amqpvalue_destroy(body_amqp_value); } amqpvalue_destroy(application_properties); amqpvalue_destroy(application_properties_value); amqpvalue_destroy(properties_amqp_value); properties_destroy(properties); } } return result; }
/** * @brief Writes to session CALLEVENT messages * * This function sends the CALLEVENTS to a session when some filter * events triggers. It is used for Agent and Remote channel events.\n * * This function will be callbacked when one of this happens:\n * - A channel sets ACTIONID variable: This gave us leg1 channel\n * - This channel begins a Dial Action: This gave us the second leg\n * - Events on any of these two channels\n * * @param filter Triggering filter structure * @param msg Matching message from Manager * @return 0 in all cases */ int call_state(filter_t *filter, ami_message_t *msg) { // Get Call information struct app_call_info *info = (struct app_call_info *) filter_get_userdata(filter); // Get message event const char *event = message_get_header(msg, "Event"); char from[80], state[80], uniqueid[80], response[256]; bool finished = false; // Initialize arrays memset(from, 0, sizeof(from)); memset(state, 0, sizeof(state)); memset(uniqueid, 0, sizeof(uniqueid)); memset(response, 0, sizeof(response)); // So this leg is first one or second one? if (!strcasecmp(message_get_header(msg, "UniqueID"), info->ouid)) { isaac_strcpy(from, "AGENT"); } else { isaac_strcpy(from, "REMOTE"); } // Send CallStatus message depending on received event if (!strcasecmp(event, "Hangup")) { // Print status message dpending on Hangup Cause const char *cause = message_get_header(msg, "Cause"); if (!strcasecmp(cause, "0") || !strcasecmp(cause, "21")) { isaac_strcpy(state, "ERROR"); } else if (!strcasecmp(cause, "16")) { isaac_strcpy(state, "HANGUP"); } else if (!strcasecmp(cause, "17")) { isaac_strcpy(state, "BUSY"); } else { sprintf(state, "UNKNOWNHANGUP %s", cause); } // This call info has ended finished = true; } else if (!strcasecmp(event, "MusicOnHold")) { if (!strcasecmp(message_get_header(msg, "State"), "Start")) { isaac_strcpy(state, "HOLD"); } else { isaac_strcpy(state, "UNHOLD"); } // In this case, the channel that receives the Hold event is the // one that is being hold, not holding. So we should swap the // AGENT <-> REMOVE value if (!strcasecmp(message_get_header(msg, "UniqueID"), info->ouid)) { isaac_strcpy(from, "REMOTE"); } else { isaac_strcpy(from, "AGENT"); } } else if (!strcasecmp(event, "Newstate")) { // Print status message depending on Channel Status const char *chanstate = message_get_header(msg, "ChannelState"); if (!strcasecmp(chanstate, "5")) { isaac_strcpy(state, "RINGING"); } else if (!strcasecmp(chanstate, "6")) { isaac_strcpy(state, "ANSWERED"); } } else if (!strcasecmp(event, "Rename")) { if (!strcasecmp(message_get_header(msg, "UniqueID"), info->ouid)) { strcpy(info->ochannel, message_get_header(msg, "NewName")); } } else if (!strcasecmp(event, "VarSet")) { const char *varvalue = message_get_header(msg, "Value"); const char *varname = message_get_header(msg, "Variable"); // Progress event on cellphones if (!strcasecmp(varvalue, "SIP 183 Session Progress")) { isaac_strcpy(state, "PROGRESS"); } // Update recording variables if (!strncasecmp(varname, "GRABACIONES_", 12)) { char recordvar[256],recorduniqueid[80], grabaciones[80], recordtype[80]; isaac_strcpy(recordvar, varname); if (sscanf(recordvar, "%[^_]_%[^_]_%s", grabaciones, recorduniqueid, recordtype) == 3) { if (!strcasecmp(recordtype, "MODULO")) sprintf(info->grabaciones_modulo, "%s;", varvalue); if (!strcasecmp(recordtype, "TIPO")) sprintf(info->grabaciones_tipo, "%s;", varvalue); if (!strcasecmp(recordtype, "PLATAFORMA")) sprintf(info->grabaciones_plataforma, "%s;", varvalue); if (!strcasecmp(recordtype, "ORIGEN")) sprintf(info->grabaciones_origen, "%s;", varvalue); if (!strcasecmp(recordtype, "DESTINO")) sprintf(info->grabaciones_destino, "%s;", varvalue); if (!strcasecmp(recordtype, "FECHA_HORA")) sprintf(info->grabaciones_fecha_hora, "%s;", varvalue); if (!strcasecmp(recordtype, "RUTA")) sprintf(info->grabaciones_ruta, "%s;", varvalue); if (!strcasecmp(recordtype, "FICHERO")) sprintf(info->grabaciones_fichero, "%s;", varvalue); } else { isaac_log(LOG_WARNING, "Unhandled record variable %s\n", varname); } } // A channel has set ACTIONID var, this is our leg1 channel. It will Dial soon! if (!strcasecmp(varname, "ACTIONID")) { // Get the UniqueId from the agent channel isaac_strcpy(info->ouid, message_get_header(msg, "UniqueID")); // Store provisional Channel Name isaac_strcpy(info->ochannel, message_get_header(msg, "Channel")); // This messages are always from agent isaac_strcpy(from, "AGENT"); // Register a Filter for the agent statusthe custom manager application PlayDTMF. info->ofilter = filter_create_async(filter->sess, call_state); filter_new_condition(info->ofilter, MATCH_REGEX, "Event", "Hangup|MusicOnHold|Newstate|Rename|VarSet|Dial"); filter_new_condition(info->ofilter, MATCH_EXACT, "UniqueID", info->ouid); filter_set_userdata(info->ofilter, (void*) info); filter_register(info->ofilter); // Tell the client the channel is going on! isaac_strcpy(state, "STARTING"); } } else if (!strcasecmp(event, "Dial") && !strcasecmp(message_get_header(msg, "SubEvent"), "Begin")) { // Get the UniqueId from the agent channel strcpy(info->duid, message_get_header(msg, "DestUniqueID")); strcpy(info->dchannel, message_get_header(msg, "Destination")); // Register a Filter for the agent status info->dfilter = filter_create_async(filter->sess, call_state); filter_set_userdata(info->dfilter, info); filter_new_condition(info->ofilter, MATCH_REGEX, "Event", "Hangup|MusicOnHold|Newstate|Rename|VarSet|Dial"); filter_new_condition(info->dfilter, MATCH_EXACT, "UniqueID", info->duid); filter_register(info->dfilter); // This messages are always from agent isaac_strcpy(from, "REMOTE"); // Store the call state isaac_strcpy(state, "STARTING"); } // Built the event message if (strlen(state)) { // Add Uniqueid to response if requested if (info->print_uniqueid) { isaac_strcpy(uniqueid, !strcasecmp(from, "AGENT")?info->ouid:info->duid); sprintf(response, "CALLSTATUS %s %s %s %s\r\n", info->actionid, uniqueid, from, state); } else { sprintf(response, "CALLSTATUS %s %s %s\r\n", info->actionid, from, state); } // Send this message to other clients if requested if (info->broadcast) { session_write_broadcast(filter->sess, response); } else { session_write(filter->sess, response); } } // We dont expect more info about this filter, it's safe to unregister it here if (finished) filter_unregister(filter); return 0; }
static void dkim_symbol_callback (struct rspamd_task *task, void *unused) { GList *hlist; rspamd_dkim_context_t *ctx; rspamd_dkim_key_t *key; GError *err = NULL; struct raw_header *rh; /* First check if a message has its signature */ hlist = message_get_header (task, DKIM_SIGNHEADER, FALSE); if (hlist != NULL) { /* Check whitelist */ msg_debug ("dkim signature found"); if (radix_find_compressed_addr (dkim_module_ctx->whitelist_ip, &task->from_addr) == RADIX_NO_VALUE) { /* Parse signature */ msg_debug ("create dkim signature"); /* * Check only last signature as there is no way to check embeded signatures after * resend or something like this */ if (dkim_module_ctx->skip_multi) { if (hlist->next != NULL) { msg_info ( "<%s> skip dkim check as it has several dkim signatures", task->message_id); return; } } hlist = g_list_last (hlist); rh = (struct raw_header *)hlist->data; ctx = rspamd_create_dkim_context (rh->decoded, task->task_pool, dkim_module_ctx->time_jitter, &err); if (ctx == NULL) { msg_info ("cannot parse DKIM context: %s", err->message); g_error_free (err); } else { /* Get key */ if (dkim_module_ctx->trusted_only && (dkim_module_ctx->dkim_domains == NULL || g_hash_table_lookup (dkim_module_ctx->dkim_domains, ctx->domain) == NULL)) { msg_debug ("skip dkim check for %s domain", ctx->domain); return; } key = rspamd_lru_hash_lookup (dkim_module_ctx->dkim_hash, ctx->dns_key, task->tv.tv_sec); if (key != NULL) { debug_task ("found key for %s in cache", ctx->dns_key); dkim_module_check (task, ctx, key); } else { debug_task ("request key for %s from DNS", ctx->dns_key); task->dns_requests++; rspamd_get_dkim_key (ctx, task->resolver, task->s, dkim_module_key_handler, task); } } } } }