static void timer_send_update_notifies(int round) { db_key_t query_cols[1], update_cols[1], result_cols[6]; db_val_t query_vals[1], update_vals[1]; int did_col, resource_uri_col, auth_state_col, reason_col, pres_state_col, content_type_col; int n_result_cols= 0; db1_res_t *result= NULL; query_cols[0]= &str_updated_col; query_vals[0].type = DB1_INT; query_vals[0].nul = 0; query_vals[0].val.int_val= round; result_cols[did_col= n_result_cols++]= &str_rlsubs_did_col; result_cols[resource_uri_col= n_result_cols++]= &str_resource_uri_col; result_cols[auth_state_col= n_result_cols++]= &str_auth_state_col; result_cols[content_type_col= n_result_cols++]= &str_content_type_col; result_cols[reason_col= n_result_cols++]= &str_reason_col; result_cols[pres_state_col= n_result_cols++]= &str_presence_state_col; update_cols[0]= &str_updated_col; update_vals[0].type = DB1_INT; update_vals[0].nul = 0; update_vals[0].val.int_val= NO_UPDATE_TYPE; /* query in alphabetical order after rlsusbs_did * (resource list Subscribe dialog indentifier)*/ if (rlpres_dbf.use_table(rlpres_db, &rlpres_table) < 0) { LM_ERR("in use_table\n"); goto done; } if (dbmode == RLS_DB_ONLY && rlpres_dbf.start_transaction) { if (rlpres_dbf.start_transaction(rlpres_db) < 0) { LM_ERR("in start_transaction\n"); goto done; } } if(rlpres_dbf.query(rlpres_db, query_cols, 0, query_vals, result_cols, 1, n_result_cols, &str_rlsubs_did_col, &result)< 0) { LM_ERR("in sql query\n"); goto done; } if(result == NULL || result->n <= 0) goto done; if(rlpres_dbf.update(rlpres_db, query_cols, 0, query_vals, update_cols, update_vals, 1, 1)< 0) { LM_ERR("in sql update\n"); goto done; } if (dbmode == RLS_DB_ONLY && rlpres_dbf.end_transaction) { if (rlpres_dbf.end_transaction(rlpres_db) < 0) { LM_ERR("in end_transaction\n"); goto done; } } send_notifies(result, did_col, resource_uri_col, auth_state_col, reason_col, pres_state_col, content_type_col); done: if(result) rlpres_dbf.free_result(rlpres_db, result); if (dbmode == RLS_DB_ONLY && rls_dbf.abort_transaction) { if (rlpres_dbf.abort_transaction(rlpres_db) < 0) LM_ERR("in abort_transaction\n"); } }
/* Control the action of performing the udpates and sending * out notifications. Briefly, for auth failures all referenced * upd_to: fields will be notified. For error-free updates (ie, * no syntax and no auth errors) notifications will be sent to * all referenced notify: and mnt_nfy: field addresses. The * sender is always notified unless the '-x' command line flag is set * (see below). * * notify () will send the updates to IRRd. If IRRd encounters * an error and/or cannot apply the update the IRRd error message * will be relayed in the notification. * * 'null_notification' = 1 causes notify () to skip * all notifications. In this case, notify () will send the * updates to IRRd but no notifications will be sent. '*tmpfname' * is the file template for 'mkstemp ()' to use to build * the notification files. There will be one notification file * per unique notify/updto email address. * * 'null_submission' means the user sent in an empty submission. * For an email submission all we have is the email header and an * empty body. For a TCP submission all we have is an empty body * and a return IP address. Note that 'null_submission' would * have been better name 'non_null_lines' since 'null_submission' * equal to 0 means we have a NULL submission. * * Return: * void * Results of the updates are included in the notifications. */ void notify (trace_t *tr, char *tmpfname, FILE *fin, int null_submission, int null_notification, int dump_stdout, char *web_origin_str, int rps_dist_flag, char *IRRd_HOST, int IRRd_PORT, char *db_admin, char *pgpdir, char *dbdir, char *tlogfn, long tlog_fpos, FILE *ack_fd, char * from_ip) { ret_info_t rstart; trans_info_t trans_info; char buf[MAXLINE]; irrd_result_t *p; long offset = 0; char pbuf[256]; /*fprintf (dfile, "Enter notify()\n");*/ rstart.first = rstart.last = NULL; if (rps_dist_flag) perform_rpsdist_trans (tr, fin, &rstart, null_submission, tlogfn, tlog_fpos, IRRd_HOST, IRRd_PORT, dbdir); else perform_transactions (tr, fin, &rstart, null_submission, IRRd_HOST, IRRd_PORT, pgpdir); /* JW want to go to this when we make irr_submit/IRRd transaction compliant perform_transactions_new (tr, fin, &rstart, null_submission, IRRd_HOST, IRRd_PORT, pgpdir); */ p = rstart.first; /* just to be safe rewind */ if (fseek (fin, 0L, SEEK_SET) != 0) { fprintf (stderr, "ERROR: cannot rewind input file, exit!\n"); exit (0); } /* init global data structures */ nnext = notify_addrs; fnext = forward_addrs; snext = sender_addrs; num_notify = num_forward = num_sender = 0; /* pointer to array of file names and handles to * notify/forward mail replies. */ num_hdls = 0; while (fgets (buf, MAXLINE, fin) != NULL) { if (strncmp (HDR_START, buf, strlen (HDR_START) - 1)) continue; /* fprintf (dfile, "found a start header %s strlen-(%d)\n", buf, strlen (buf));*/ if (parse_header (tr, fin, &offset, &trans_info)) break; /* illegal hdr field found or EOF * (ie, no object after hdr) */ /* Make sure sender is not getting duplicate notifications */ if (trans_info.hdr_fields & FROM_F) remove_sender (trans_info.sender_addrs, trans_info.notify_addrs, &(trans_info.nnext)); else if (dump_stdout) { /* We have a tcp user, ie, an IRRj user */ trans_info.hdr_fields |= FROM_F; if(from_ip == NULL) from_ip = "localhost"; sprintf(pbuf,"TCP(%s)", from_ip); strcpy (trans_info.sender_addrs, pbuf); trans_info.snext += strlen (trans_info.sender_addrs) + 1; } trans_info.web_origin_str = web_origin_str; if (web_origin_str != NULL) { sprintf(pbuf,"%s Route Registry Update", trans_info.source ? trans_info.source : ""); trans_info.subject = strdup (pbuf); } /* JW this is for debug only */ /* print_hdr_struct (dfile, &trans_info); */ chk_email_fields (&trans_info); if (!(trans_info.hdr_fields & OP_F)) trans_info.op = strdup ("UPDATE"); if (!(trans_info.hdr_fields & OBJ_KEY_F)) trans_info.obj_key = strdup (""); if (!(trans_info.hdr_fields & OBJ_TYPE_F)) trans_info.obj_type = strdup (""); if (chk_hdr_flds (trans_info.hdr_fields)) { build_notify_responses (tr, tmpfname, fin, &trans_info, p, db_admin, MAX_IRRD_OBJ_SIZE, null_notification); if ((trans_info.hdr_fields & OLD_OBJ_FILE_F) && (*trans_info.old_obj_fname < '0' || *trans_info.old_obj_fname > '9')) unlink (trans_info.old_obj_fname); } /*else fprintf (dfile, "nofify () bad hdr file found, skipping...\n");*/ free_ti_mem (&trans_info); p = p->next; } send_notifies (tr, null_notification, ack_fd, dump_stdout); remove_tempfiles (tr); /*fprintf (dfile, "Exit notify ()\n");*/ }