/************************************************************************* * * Function: sql_finish_query * * Purpose: End the query, such as freeing memory * *************************************************************************/ static int sql_finish_query(SQLSOCK * sqlsocket, SQL_CONFIG *config) { return sql_free_result(sqlsocket, config); }
/************************************************************************* * * Function: sql_finish_select_query * * Purpose: End the select query, such as freeing memory or result * *************************************************************************/ static sql_rcode_t sql_finish_select_query(rlm_sql_handle_t * handle, rlm_sql_config_t *config) { return sql_free_result(handle, config); }
/* Add (flagadd=1) or remove (flagadd=0) userhost from the subscriber * database table. Comment is e.g. the subscriber from line or name. It * is added to the log. Event is the action type, e.g. "probe", * "manual", etc. The direction (sub/unsub) is inferred from * flagadd. Returns 1 on success, 0 on failure. If forcehash is >=0 it * is used in place of the calculated hash. This makes it possible to * add addresses with a hash that does not exist. forcehash has to be * 0..99. For unsubscribes, the address is only removed if forcehash * matches the actual hash. This way, ezmlm-manage can be prevented from * touching certain addresses that can only be removed by * ezmlm-unsub. Usually, this would be used for sublist addresses (to * avoid removal) and sublist aliases (to prevent users from subscribing * them (although the cookie mechanism would prevent the resulting * duplicate message from being distributed. */ int sub_sql_subscribe(struct subdbinfo *info, const char *table, const char *userhost, int flagadd, const char *comment, const char *event, int forcehash) { void *result; char *cpat; char szhash[3] = "00"; unsigned int j; unsigned char ch; int nparams; make_name(info,table?"_":0,table,0); /* lowercase and check address */ stralloc_copys(&addr,userhost); if (addr.len > 255) /* this is 401 in std ezmlm. 255 */ /* should be plenty! */ strerr_die2x(100,FATAL,MSG(ERR_ADDR_LONG)); j = byte_rchr(addr.s,addr.len,'@'); if (j == addr.len) strerr_die2x(100,FATAL,MSG(ERR_ADDR_AT)); cpat = addr.s + j; case_lowerb(cpat + 1,addr.len - j - 1); if (forcehash < 0) { stralloc_copy(&lcaddr,&addr); case_lowerb(lcaddr.s,j); /* make all-lc version of address */ ch = subhashsa(&lcaddr); } else ch = (forcehash % 100); szhash[0] = '0' + ch / 10; /* hash for sublist split */ szhash[1] = '0' + (ch % 10); if (flagadd) { /* FIXME: LOCK TABLES name WRITE */ stralloc_copys(&query,"SELECT address FROM "); stralloc_cat(&query,&name); stralloc_cats(&query," WHERE "); stralloc_cats(&query,sql_subscribe_select_where_defn); stralloc_copy(¶ms[0],&addr); result = sql_select(info,&query,1,params); if (sql_fetch_row(info,result,1,params)) { sql_free_result(info,result); /* FIXME: UNLOCK TABLES */ return 0; /* already subscribed */ } else { /* not there */ sql_free_result(info,result); stralloc_copys(&query,"INSERT INTO "); stralloc_cat(&query,&name); stralloc_cats(&query," (address,hash) VALUES "); stralloc_cats(&query,sql_subscribe_list_values_defn); stralloc_copy(¶ms[0],&addr); stralloc_copys(¶ms[1],szhash); sql_exec(info,&query,2,params); /* FIXME: UNLOCK TABLES */ } } else { /* unsub */ stralloc_copys(&query,"DELETE FROM "); stralloc_cat(&query,&name); stralloc_cats(&query," WHERE "); stralloc_copy(¶ms[0],&addr); if (forcehash >= 0) { stralloc_cats(&query,sql_subscribe_delete2_where_defn); stralloc_copys(¶ms[1],szhash); nparams = 2; } else { stralloc_cats(&query,sql_subscribe_delete1_where_defn); nparams = 1; } if (sql_exec(info,&query,1,params) == 0) return 0; /* address wasn't there*/ } /* log to subscriber log */ /* INSERT INTO t_slog (address,edir,etype,fromline) */ /* VALUES('address',{'+'|'-'},'etype','[comment]') */ stralloc_copys(&query,"INSERT INTO "); stralloc_cat(&query,&name); stralloc_cats(&query,"_slog (address,edir,etype,fromline) VALUES "); stralloc_cats(&query,sql_subscribe_slog_values_defn); stralloc_copy(¶ms[0],&addr); stralloc_copys(¶ms[1],flagadd?"+":"-"); /* edir */ stralloc_copyb(¶ms[2],event+1,!!*(event+1)); /* etype */ stralloc_copys(¶ms[3],comment && *comment ? comment : ""); /* from */ sql_exec(info,&query,4,params); /* log (ignore errors) */ stralloc_0(&addr); logaddr(table,event,addr.s,comment); /* also log to old log */ return 1; /* desired effect */ }
/* * List Job record(s) that match JOB_DBR * * Currently, we return all jobs or if jr->JobId is set, * only the job with the specified id. */ void db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr, const char *range, OUTPUT_FORMATTER *sendit, e_list_type type) { char ed1[50]; char esc[MAX_ESCAPE_NAME_LENGTH]; db_lock(mdb); if (type == VERT_LIST) { if (jr->JobId == 0 && jr->Job[0] == 0) { Mmsg(mdb->cmd, "SELECT JobId,Job,Job.Name,PurgedFiles,Type,Level," "Job.ClientId,Client.Name as ClientName,JobStatus,SchedTime," "StartTime,EndTime,RealEndTime,JobTDate," "VolSessionId,VolSessionTime,JobFiles,JobErrors," "JobMissingFiles,Job.PoolId,Pool.Name as PoolName,PriorJobId," "Job.FileSetId,FileSet.FileSet " "FROM Job,Client,Pool,FileSet WHERE " "Client.ClientId=Job.ClientId AND Pool.PoolId=Job.PoolId " "AND FileSet.FileSetId=Job.FileSetId ORDER BY StartTime%s", range); } else { /* single record */ Mmsg(mdb->cmd, "SELECT JobId,Job,Job.Name,PurgedFiles,Type,Level," "Job.ClientId,Client.Name,JobStatus,SchedTime," "StartTime,EndTime,RealEndTime,JobTDate," "VolSessionId,VolSessionTime,JobFiles,JobErrors," "JobMissingFiles,Job.PoolId,Pool.Name as PoolName,PriorJobId," "Job.FileSetId,FileSet.FileSet " "FROM Job,Client,Pool,FileSet WHERE Job.JobId=%s AND " "Client.ClientId=Job.ClientId AND Pool.PoolId=Job.PoolId " "AND FileSet.FileSetId=Job.FileSetId", edit_int64(jr->JobId, ed1)); } } else { if (jr->Name[0] != 0) { mdb->db_escape_string(jcr, esc, jr->Name, strlen(jr->Name)); Mmsg(mdb->cmd, "SELECT JobId,Name,StartTime,Type,Level,JobFiles,JobBytes,JobStatus " "FROM Job WHERE Name='%s' ORDER BY JobId ASC", esc); } else if (jr->Job[0] != 0) { mdb->db_escape_string(jcr, esc, jr->Job, strlen(jr->Job)); Mmsg(mdb->cmd, "SELECT JobId,Name,StartTime,Type,Level,JobFiles,JobBytes,JobStatus " "FROM Job WHERE Job='%s' ORDER BY JobId ASC", esc); } else if (jr->JobId != 0) { Mmsg(mdb->cmd, "SELECT JobId,Name,StartTime,Type,Level,JobFiles,JobBytes,JobStatus " "FROM Job WHERE JobId=%s", edit_int64(jr->JobId, ed1)); } else { /* all records */ Mmsg(mdb->cmd, "SELECT JobId,Name,StartTime,Type,Level,JobFiles,JobBytes,JobStatus " "FROM Job ORDER BY JobId ASC%s", range); } } if (!QUERY_DB(jcr, mdb, mdb->cmd)) { goto bail_out; } sendit->array_start("jobs"); list_result(jcr, mdb, sendit, type); sendit->array_end("jobs"); sql_free_result(mdb); bail_out: db_unlock(mdb); }