Skip to content

Commit

Permalink
Use postfix API commands to set status, updated master start daemon i…
Browse files Browse the repository at this point in the history
…nfo, added .gitignore file
  • Loading branch information
Stephan Ferraro committed Dec 5, 2012
1 parent 0fe6c36 commit 197694e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.o
Makefile
*.a
bin/*
libexec/*
33 changes: 21 additions & 12 deletions src/global/dict_mongodb.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ typedef struct {
char *collection; /* collection */
char *key; /* key */
mongo conn[1]; /* MongoDB connection structure */
int connected; /* 1 = connected, 0 = disconnected */
} DICT_MONGODB;

/*
Expand Down Expand Up @@ -132,7 +133,12 @@ static const char *dict_mongodb_lookup(DICT *dict, const char *name)
mongo_cursor cursor[1];
char *db_coll_str;
char *found = NULL;


/* Check if there is a connection to MongoDB server */
if (!dict_mongodb->connected) {
msg_warn("lookup failed: no connection to MongoDB server: %s:%d", dict_mongodb->host, dict_mongodb->port);
DICT_ERR_VAL_RETURN(dict, DICT_STAT_ERROR, NULL);
}
bson_init(query);
bson_append_string(query, dict_mongodb->key, name);
bson_finish(query);
Expand All @@ -159,7 +165,13 @@ static const char *dict_mongodb_lookup(DICT *dict, const char *name)
mongo_cursor_destroy( cursor );
myfree(db_coll_str);

return found;
if (found) {
// Value found in database
dict->error = DICT_STAT_SUCCESS;
return found;
}
// Value not found in database
DICT_ERR_VAL_RETURN(dict, DICT_STAT_SUCCESS, NULL);
}

/* dict_mysql_close - close MYSQL database */
Expand All @@ -177,7 +189,7 @@ static void dict_mongodb_close(DICT *dict)
myfree(dict_mongodb->collection);
myfree(dict_mongodb->key);
dict_free(dict);
// mongo_destroy( conn );
mongo_destroy(dict_mongodb->conn);
}

/* dict_mongodb_my_connect - connect to mongodb database */
Expand All @@ -186,20 +198,20 @@ int dict_mongodb_my_connect(DICT_MONGODB *dict_mongodb)
/*
* Connect to mongodb database
*/
dict_mongodb->connected = 0;
if (mongo_client(dict_mongodb->conn , dict_mongodb->host, dict_mongodb->port)) {
msg_fatal("connect to mongodb database failed: %s at port %d", dict_mongodb->host, dict_mongodb->port);
dict_mongodb_close((DICT *)dict_mongodb);
return -1;
DICT_ERR_VAL_RETURN(&dict_mongodb->dict, DICT_ERR_RETRY, DICT_ERR_RETRY);
}
if (dict_mongodb->auth) {
/* Authentificate to MongoDB server */
if (mongo_cmd_authenticate(dict_mongodb->conn, dict_mongodb->dbname, dict_mongodb->username, dict_mongodb->password) == MONGO_ERROR) {
msg_fatal("mongodb autentification failed: %s at host %s", dict_mongodb->username, dict_mongodb->host);
dict_mongodb_close((DICT *)dict_mongodb);
return -1;
DICT_ERR_VAL_RETURN(&dict_mongodb->dict, DICT_ERR_RETRY, DICT_ERR_RETRY);
}
}
return 0;
dict_mongodb->connected = 1;
DICT_ERR_VAL_RETURN(&dict_mongodb->dict, DICT_ERR_NONE, DICT_ERR_NONE);
}

/* dict_mongodb_open - open memcache */
Expand Down Expand Up @@ -227,10 +239,7 @@ DICT *dict_mongodb_open(const char *name, int open_flags, int dict_flags)
dict_mongodb->parser = parser;
mongodb_parse_config(dict_mongodb, name);
dict_mongodb->dict.owner = cfg_get_owner(dict_mongodb->parser);

if (dict_mongodb_my_connect(dict_mongodb) == -1) {
return NULL;
}
dict_mongodb_my_connect(dict_mongodb);

return (DICT_DEBUG(&dict_mongodb->dict));
}
6 changes: 4 additions & 2 deletions src/master/master.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,10 @@ int main(int argc, char **argv)
master_config();
master_sigsetup();
master_flow_init();
msg_info("daemon started -- version %s, configuration %s",
var_mail_version, var_config_dir);
/* msg_info("daemon started -- version %s, configuration %s",
var_mail_version, var_config_dir); */
msg_info("daemon started -- version %s, configuration %s, MongoDB version of https://github.com/digitalturbulence/postfix-mongodb",
var_mail_version, var_config_dir);

/*
* Process events. The event handler will execute the read/write/timer
Expand Down

0 comments on commit 197694e

Please sign in to comment.