コード例 #1
0
ファイル: mydns_20150325.c プロジェクト: WangZzzz/box_rs
int url_judge(char *input)
{
	char output[50];
	int len = strlen(input);
	int i, countdown = 0, cnt_tmp = 0, n;

	for(i = len - 1; i > 0; i--)
	{
		if(input[i] == '.')
		{
			n = i + 1;
			for(cnt_tmp = 0; cnt_tmp < countdown; cnt_tmp++)
			{
				output[cnt_tmp] = input[n];
				n++;
			}
			output[cnt_tmp] = '\0';
			if(sql_select(output)==1)
			{
				return 1;
			}
			countdown++;
		}
		else
		{
			countdown++;
		}
	}

	if(sql_select(input)==1)
	{
		return 1;
	}
	return 0;
}
コード例 #2
0
ファイル: sub_sql.c プロジェクト: bruceg/ezmlm-idx
/* Outputs all addresses in the table through subwrite. subwrite must be
 * a function returning >=0 on success, -1 on error, and taking
 * arguments (char* string, unsigned int length). It will be called once
 * per address and should take care of newline or whatever needed for
 * the output form. */
unsigned long sub_sql_putsubs(struct subdbinfo *info,
			      const char *table,
			      unsigned long hash_lo,
			      unsigned long hash_hi,
			      int subwrite()) /* write function. */
{
  void *result;
  unsigned long no = 0L;
  char strnum[FMT_ULONG];

  stralloc_copyb(&params[0],strnum,fmt_ulong(strnum,hash_lo));
  stralloc_copyb(&params[1],strnum,fmt_ulong(strnum,hash_hi));
  make_name(info,table?"_":0,table,0);

  /* main query */
  stralloc_copys(&query,"SELECT address FROM ");
  stralloc_cat(&query,&name);
  stralloc_cats(&query," WHERE ");
  stralloc_cats(&query,sql_putsubs_where_defn);

  result = sql_select(info,&query,2,params);

  no = 0;
  while (sql_fetch_row(info,result,1,&addr)) {
    if (subwrite(addr.s,addr.len) == -1) die_write();
    no++;					/* count for list-list fxn */
  }
  sql_free_result(info,result);
  return no;
}
コード例 #3
0
ファイル: sub_sql.c プロジェクト: bruceg/ezmlm-idx
/* Checks the hash against the cookie table. If it matches, returns NULL,
 * else returns "". If error, returns error string. */
const char *sub_sql_checktag (struct subdbinfo *info,
			      unsigned long num,	/* message number */
			      unsigned long listno,	/* bottom of range => slave */
			      const char *action,
			      const char *seed,
			      const char *hash)		/* cookie */
{
  void *result;
  char strnum[FMT_ULONG];

  /* SELECT msgnum FROM table_cookie WHERE msgnum=num and cookie='hash' */
  /* succeeds only is everything correct. */
  if (listno) {			/* only for slaves */
    stralloc_copyb(&params[0],strnum,fmt_ulong(strnum,listno));
    stralloc_copyb(&params[1],strnum,fmt_ulong(strnum,num));
    stralloc_copys(&query,"SELECT listno FROM ");
    stralloc_cats(&query,info->base_table);
    stralloc_cats(&query,"_mlog WHERE ");
    stralloc_cats(&query,sql_checktag_listno_where_defn);

    result = sql_select(info,&query,2,params);
    if (sql_fetch_row(info,result,1,params)) {
      sql_free_result(info,result);
      return "";		/* already done */
    }
    /* no result */
    sql_free_result(info,result);
  }

  stralloc_copyb(&params[0],strnum,fmt_ulong(strnum,num));
  stralloc_copyb(&params[1],hash,COOKIE);

  stralloc_copys(&query,"SELECT msgnum FROM ");
  stralloc_cats(&query,info->base_table);
  stralloc_cats(&query,"_cookie WHERE ");
  stralloc_cats(&query,sql_checktag_msgnum_where_defn);

  result = sql_select(info,&query,2,params);
  if (!sql_fetch_row(info,result,1,params)) {
    sql_free_result(info,result);
    return "";			/* not parent => perm error */
  }
  sql_free_result(info,result);	/* success! cookie matches */
  return (char *)0;
  (void)action;
  (void)seed;
}
コード例 #4
0
ファイル: sub_sql.c プロジェクト: bruceg/ezmlm-idx
/* Searches the subscriber log and outputs via subwrite(s,len) any entry
 * that matches search. A '_' is search is a wildcard. Any other
 * non-alphanum/'.' char is replaced by a '_'. */
void sub_sql_searchlog(struct subdbinfo *info,
		       const char *table,
		       char *search,		/* search string */
		       int subwrite())		/* output fxn */
{
  void *result;
  datetime_sec when;
  struct datetime dt;
  char date[DATE822FMT];
  int nparams;
  char strnum[FMT_ULONG];

  make_name(info,table?"_":0,table,0);
/* SELECT (*) FROM list_slog WHERE fromline LIKE '%search%' OR address   */
/* LIKE '%search%' ORDER BY tai; */
/* The '*' is formatted to look like the output of the non-mysql version */
/* This requires reading the entire table, since search fields are not   */
/* indexed, but this is a rare query and time is not of the essence.     */

  stralloc_copys(&query,"SELECT ");
  stralloc_cats(&query,sql_searchlog_select_defn);
  stralloc_cats(&query," FROM ");
  stralloc_cat(&query,&name);
  stralloc_cats(&query,"_slog");
  if (*search) {	/* We can afford to wait for LIKE '%xx%' */
    stralloc_copys(&params[0],search);
    stralloc_copys(&params[1],search);
    nparams = 2;
    stralloc_cats(&query," WHERE ");
    stralloc_cats(&query,sql_searchlog_where_defn);
  }
  else
    nparams = 0;
  /* ordering by tai which is an index */
  stralloc_cats(&query," ORDER by tai");

  result = sql_select(info,&query,nparams,params);
  while (sql_fetch_row(info,result,2,params)) {
    stralloc_0(&params[0]);
    (void)scan_ulong(params[0].s,&when);
    datetime_tai(&dt,when);
    stralloc_copyb(&params[0],date,date822fmt(date,&dt)-1);
    stralloc_cats(&params[0],": ");
    stralloc_catb(&params[0],strnum,fmt_ulong(strnum,when));
    stralloc_cats(&params[0]," ");
    stralloc_cat(&params[0],&params[1]);
    if (subwrite(params[0].s,params[0].len) == -1) die_write();
  }
  sql_free_result(info,result);
}
コード例 #5
0
ファイル: sub_sql.c プロジェクト: bruceg/ezmlm-idx
int sub_sql_issub(struct subdbinfo *info,
		  const char *table,
		  const char *userhost,
		  stralloc *recorded)
{
  unsigned int j;
  void *result;
  int ret;

  /* SELECT address FROM list WHERE address = 'userhost' AND hash */
  /* BETWEEN 0 AND 52. Without the hash restriction, we'd make it */
  /* even easier to defeat. Just faking sender to the list name would*/
  /* work. Since sender checks for posts are bogus anyway, I don't */
  /* know if it's worth the cost of the "WHERE ...". */

  make_name(info,table?"_":0,table,0);

  /* Lower-case the domain portion */
  stralloc_copys(&addr,userhost);
  j = byte_rchr(addr.s,addr.len,'@');
  if (j == addr.len)
    return 0;
  case_lowerb(addr.s + j + 1,addr.len - j - 1);

  stralloc_copys(&query,"SELECT address FROM ");
  stralloc_cat(&query,&name);
  stralloc_cats(&query," WHERE ");
  stralloc_cats(&query,sql_issub_where_defn);

  result = sql_select(info,&query,1,&addr);

  if (!sql_fetch_row(info,result,1,&addr))
    ret = 0;
  else {
    /* we need to return the actual address as other dbs may accept
     * user-*@host, but we still want to make sure to send to e.g the
     * correct moderator address. */
    if (recorded != 0) {
      stralloc_copy(recorded,&addr);
      stralloc_0(recorded);
    }
    ret = 1;
  }
  sql_free_result(info,result);
  return ret;
}
コード例 #6
0
ファイル: mainwindow.cpp プロジェクト: SpelaOman/BubiLink
void MainWindow::fill_campaigns() {

    ui->campaign_name->clear();
    ui->campaign_name->addItem("");

    QString app_path = QApplication::applicationDirPath();
    QString dbase_path = app_path + "/base.bz";

    {
        QSqlDatabase base = QSqlDatabase::addDatabase("QSQLITE", "fill-campaign");
        base.setDatabaseName(dbase_path);
        base.open();
        if(base.isOpen() != true){
            QMessageBox msgbox;
            msgbox.setText("There was a problem with the database");
            msgbox.setInformativeText("Due to unknown reason there was a problem with opening the database.\nThe problem accured during initial opening of the database.");
            msgbox.exec();
        }
        else {
            // the database is open

            // fill profile combo box
            QSqlQuery sql_fill(base);
            sql_fill.prepare("SELECT * FROM campaign WHERE user LIKE '" + vApp->id_user() + "' AND profile LIKE '" + vApp->id_profile() + "'");
            sql_fill.exec();
            while ( sql_fill.next() ) {
                ui->campaign_name->addItem(sql_fill.value(sql_fill.record().indexOf("campaign_name")).toString());
            }
            sql_fill.clear();

            QSqlQuery sql_select(base);
            sql_select.prepare("SELECT * FROM campaign WHERE user LIKE '" + vApp->id_user() + "' AND profile LIKE '" + vApp->id_profile() + "' AND id LIKE '" + vApp->id_campaign() + "'");
            sql_select.exec();
            if ( sql_select.next() ) {
                ui->campaign_name->setCurrentIndex(ui->campaign_name->findText(sql_select.value(sql_select.record().indexOf("campaign_name")).toString()));
            }
        }
        base.close();
    }
    QSqlDatabase::removeDatabase("fill-campaign");

}
コード例 #7
0
ファイル: sub-sqlite3.c プロジェクト: bruceg/ezmlm-idx
int sql_exec(struct subdbinfo *info,
	     struct stralloc *q,
	     unsigned int nparams,
	     struct stralloc *params)
{
  sqlite3_stmt *stmt;
  int rows = 0;

  stmt = sql_select(info,q,nparams,params);
  switch (sqlite3_step(stmt)) {
  case SQLITE_DONE:
    rows = sqlite3_changes((sqlite3*)info->conn);
    break;
  case SQLITE_CONSTRAINT:	/* duplicated key on insert */
    break;
  default:
    die_sqlerror(info);
  }
  sqlite3_finalize(stmt);
  return rows;
}
コード例 #8
0
ファイル: db_handle.cpp プロジェクト: DavadDi/acl
bool db_handle::exec_select(query& query)
{
	return sql_select(query.to_string().c_str());
}
コード例 #9
0
Msg *mssql_fetch_msg()
{
    Msg *msg = NULL;
    Octstr *sql, *delet, *id;
    List *res, *row;
    int ret;
    DBPoolConn *pc;

    pc = dbpool_conn_consume(pool);
    if (pc == NULL) {
        error(0, "MSSql: DBPool error!");
        return;
    }

    sql = octstr_format(SQLBOX_MSSQL_SELECT_QUERY, sqlbox_insert_table);
#if defined(SQLBOX_TRACE)
     debug("SQLBOX", 0, "sql: %s", octstr_get_cstr(sql));
#endif
    if (sql_select(pc, sql, NULL, &res) != 0) {
        debug("sqlbox", 0, "SQL statement failed: %s", octstr_get_cstr(sql));
    } else {
        if (gwlist_len(res) > 0) {
            row = gwlist_extract_first(res);
            id = get_mssql_octstr_col(0);
            /* save fields in this row as msg struct */
            msg = msg_create(sms);
            msg->sms.sender     = get_mssql_octstr_col(2);
            msg->sms.receiver   = get_mssql_octstr_col(3);
            msg->sms.udhdata    = get_mssql_octstr_col(4);
            msg->sms.msgdata    = get_mssql_octstr_col(5);
            msg->sms.time       = get_mssql_long_col(6);
            msg->sms.smsc_id    = get_mssql_octstr_col(7);
            msg->sms.service    = get_mssql_octstr_col(8);
            msg->sms.account    = get_mssql_octstr_col(9);
            /* msg->sms.id      = get_mssql_long_col(10); */
            msg->sms.sms_type   = get_mssql_long_col(11);
            msg->sms.mclass     = get_mssql_long_col(12);
            msg->sms.mwi        = get_mssql_long_col(13);
            msg->sms.coding     = get_mssql_long_col(14);
            msg->sms.compress   = get_mssql_long_col(15);
            msg->sms.validity   = get_mssql_long_col(16);
            msg->sms.deferred   = get_mssql_long_col(17);
            msg->sms.dlr_mask   = get_mssql_long_col(18);
            msg->sms.dlr_url    = get_mssql_octstr_col(19);
            msg->sms.pid        = get_mssql_long_col(20);
            msg->sms.alt_dcs    = get_mssql_long_col(21);
            msg->sms.rpi        = get_mssql_long_col(22);
            msg->sms.charset    = get_mssql_octstr_col(23);
            msg->sms.binfo      = get_mssql_octstr_col(25);
            msg->sms.meta_data  = get_mssql_octstr_col(26);
            if (gwlist_get(row,24) == NULL) {
                msg->sms.boxc_id = octstr_duplicate(sqlbox_id);
            }
            else {
                msg->sms.boxc_id = get_mssql_octstr_col(24);
            }
            /* delete current row */
            delet = octstr_format(SQLBOX_MSSQL_DELETE_QUERY, sqlbox_insert_table, id);
#if defined(SQLBOX_TRACE)
     debug("SQLBOX", 0, "sql: %s", octstr_get_cstr(delet));
#endif
            sql_update(pc, delet, NULL);
            octstr_destroy(id);
            octstr_destroy(delet);
            gwlist_destroy(row, octstr_destroy_item);
        }
        gwlist_destroy(res, NULL);
    }
    dbpool_conn_produce(pc);
    octstr_destroy(sql);
    return msg;
}
コード例 #10
0
ファイル: sub_sql.c プロジェクト: bruceg/ezmlm-idx
/* 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(&params[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(&params[0],&addr);
      stralloc_copys(&params[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(&params[0],&addr);
    if (forcehash >= 0) {
      stralloc_cats(&query,sql_subscribe_delete2_where_defn);
      stralloc_copys(&params[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(&params[0],&addr);
  stralloc_copys(&params[1],flagadd?"+":"-"); /* edir */
  stralloc_copyb(&params[2],event+1,!!*(event+1)); /* etype */
  stralloc_copys(&params[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 */
}