コード例 #1
0
ファイル: bb_store_file.c プロジェクト: gburiticato/kannel
static int store_file_save_ack(Msg *msg, ack_status_t status)
{
    Msg *mack;
    int ret;

    /* only sms are handled */
    if (!msg || msg_type(msg) != sms)
        return -1;

    if (filename == NULL)
        return 0;

    mack = msg_create(ack);
    if (!mack)
        return -1;

    mack->ack.time = msg->sms.time;
    uuid_copy(mack->ack.id, msg->sms.id);
    mack->ack.nack = status;

    ret = store_save(mack);
    msg_destroy(mack);

    return ret;
}
コード例 #2
0
ファイル: yidb.c プロジェクト: hardeasy/yidb
int set(char *key,char *value,int exptime){
	//store save
	int fieldId = 0;
	long blockPos;

	//printf("store_save \n");

	store_save(key,value,exptime,&fieldId,&blockPos);

	//printf("store return fieldId:%d,blockPos:%d\n", fieldId,blockPos);
	//index
	index_insert(key,fieldId,blockPos);

	return 0;
}
コード例 #3
0
ファイル: program.c プロジェクト: Manasmitha/geany-plugins
void program_finalize(void)
{
	char *configfile = prefs_file_name();
	GKeyFile *config = g_key_file_new();

	save_program_settings();
	g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL);
	store_save(recent_programs, config, "recent", recent_program_save);
	utils_key_file_write_to_file(config, configfile);
	g_key_file_free(config);
	g_free(configfile);

	gtk_widget_destroy(program_dialog);
	stash_foreach((GFunc) stash_group_destroy, NULL);
}
コード例 #4
0
ファイル: bearerbox.c プロジェクト: Jayriq/kannel-gateway
int bb_remove_message(Octstr *message_id)
{
    Msg *msg;
    int ret;

    msg = msg_create(ack);
    msg->ack.nack = ack_failed;
    msg->ack.time = time(NULL);
    uuid_parse(octstr_get_cstr(message_id), msg->ack.id);
    ret = store_save(msg);
    msg_destroy(msg);
    if (ret != 0) {
        error(0, "Could not delete message %s", octstr_get_cstr(message_id));
        return -1;
    }
    return 0;
}
コード例 #5
0
ファイル: bb_boxc.c プロジェクト: Phonebooth/kannel
/*
 * Try to deliver message to internal or smscconn queue
 * and generate ack/nack for smsbox connections.
 */
static void deliver_sms_to_queue(Msg *msg, Boxc *conn)
{
    Msg *mack;
    int rc;

    /*
     * save modifies ID and time, so if the smsbox uses it, save
     * it FIRST for the reply message!!!
     */
    mack = msg_create(ack);
    gw_assert(mack != NULL);
    uuid_copy(mack->ack.id, msg->sms.id);
    mack->ack.time = msg->sms.time;

    store_save(msg);

    rc = smsc2_rout(msg, 0);
    switch(rc) {
        case SMSCCONN_SUCCESS:
           mack->ack.nack = ack_success;
           break;
        case SMSCCONN_QUEUED:
           mack->ack.nack = ack_buffered;
           break;
        case SMSCCONN_FAILED_DISCARDED: /* no router at all */
        case SMSCCONN_FAILED_QFULL: /* queue full */
           warning(0, "Message rejected by bearerbox, %s!",
                             (rc == SMSCCONN_FAILED_DISCARDED) ? "no router" : "queue full");
           /*
            * first create nack for store-file, in order to delete
            * message from store-file.
            */
           store_save_ack(msg, (rc == SMSCCONN_FAILED_QFULL ? ack_failed_tmp : ack_failed));
           mack->ack.nack = (rc == SMSCCONN_FAILED_QFULL ? ack_failed_tmp : ack_failed);

           /* destroy original message */
           msg_destroy(msg);
           break;
    }

    /* put ack into incoming queue of conn */
    send_msg(conn, mack);
    msg_destroy(mack);
}
コード例 #6
0
ファイル: bb_boxc.c プロジェクト: Phonebooth/kannel
static void boxc_receiver(void *arg)
{
    Boxc *conn = arg;
    Msg *msg, *mack;

    /* remove messages from socket until it is closed */
    while (bb_status != BB_DEAD && conn->alive) {

        gwlist_consume(suspended);	/* block here if suspended */

        msg = read_from_box(conn);

        if (msg == NULL) {	/* garbage/connection lost */
            conn->alive = 0;
            break;
        }

        /* we don't accept new messages in shutdown phase */
        if ((bb_status == BB_SHUTDOWN || bb_status == BB_DEAD) && msg_type(msg) == sms) {
            mack = msg_create(ack);
            uuid_copy(mack->ack.id, msg->sms.id);
            mack->ack.time = msg->sms.time;
            mack->ack.nack = ack_failed_tmp;
            msg_destroy(msg);
            send_msg(conn, mack);
            msg_destroy(mack);
            continue;
        }

        if (msg_type(msg) == sms && conn->is_wap == 0) {
            debug("bb.boxc", 0, "boxc_receiver: sms received");

            /* deliver message to queue */
            deliver_sms_to_queue(msg, conn);

            if (conn->routable == 0) {
                conn->routable = 1;
                /* wakeup the dequeue thread */
                gwthread_wakeup(sms_dequeue_thread);
            }
        } else if (msg_type(msg) == wdp_datagram && conn->is_wap) {
            debug("bb.boxc", 0, "boxc_receiver: got wdp from wapbox");

            /* XXX we should block these in SHUTDOWN phase too, but
               we need ack/nack msgs implemented first. */
            gwlist_produce(conn->outgoing, msg);

        } else if (msg_type(msg) == sms && conn->is_wap) {
            debug("bb.boxc", 0, "boxc_receiver: got sms from wapbox");

            /* should be a WAP push message, so tried it the same way */
            deliver_sms_to_queue(msg, conn);

            if (conn->routable == 0) {
                conn->routable = 1;
                /* wakeup the dequeue thread */
                gwthread_wakeup(sms_dequeue_thread);
            }
        } else {
            if (msg_type(msg) == heartbeat) {
                if (msg->heartbeat.load != conn->load)
                    debug("bb.boxc", 0, "boxc_receiver: heartbeat with "
                          "load value %ld received", msg->heartbeat.load);
                conn->load = msg->heartbeat.load;
            }
            else if (msg_type(msg) == ack) {
                if (msg->ack.nack == ack_failed_tmp) {
                    Msg *orig;
                    boxc_sent_pop(conn, msg, &orig);
                    if (orig != NULL) /* retry this message */
                        gwlist_append(conn->retry, orig);
                } else {
                    boxc_sent_pop(conn, msg, NULL);
                    store_save(msg);
                }
                debug("bb.boxc", 0, "boxc_receiver: got ack");
            }
            /* if this is an identification message from an smsbox instance */
            else if (msg_type(msg) == admin && msg->admin.command == cmd_identify) {

                /*
                 * any smsbox sends this command even if boxc_id is NULL,
                 * but we will only consider real identified boxes
                 */
                if (msg->admin.boxc_id != NULL) {

                    /* and add the boxc_id into conn for boxc_status() output */
                    if (conn->boxc_id != NULL) {
                        dict_remove(smsbox_by_id, msg->admin.boxc_id);
                        octstr_destroy(conn->boxc_id);
                    }

                    conn->boxc_id = msg->admin.boxc_id;
                    msg->admin.boxc_id = NULL;

                    /* add this identified smsbox to the dictionary */
                    /* XXX check for equal boxc_id in Dict, otherwise we overwrite it */
                    dict_put(smsbox_by_id, conn->boxc_id, conn);
                    debug("bb.boxc", 0, "boxc_receiver: got boxc_id <%s> from <%s>",
                          octstr_get_cstr(conn->boxc_id),
                          octstr_get_cstr(conn->client_ip));
                }

                conn->routable = 1;
                /* wakeup the dequeue thread */
                gwthread_wakeup(sms_dequeue_thread);
            }
            else
                warning(0, "boxc_receiver: unknown msg received from <%s>, "
                           "ignored", octstr_get_cstr(conn->client_ip));
            msg_destroy(msg);
        }
    }
}
コード例 #7
0
int main(int argc, char **argv)
{
	char id[UUID_STR_LEN + 1];
    int cf_index, ret, type;
    Octstr *os, *store_type, *store_location, *status;
	Msg *msg;
	CfgGroup *grp;

	conf_file = NULL;

    gwlib_init();

    //This can be overwritten with the -v flag at runtime
    log_set_output_level(DEFAULT_LOG_LEVEL);

    cf_index = get_and_set_debugs(argc, argv, check_args);

    if (argv[cf_index] == NULL) {
        print_usage(argv[0]);
        goto error;
    }

    if (conf_file == NULL)
    	conf_file = octstr_create("kannel.conf");

    cfg = cfg_create(conf_file);

    if (cfg_read(cfg) == -1)
    	panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(conf_file));
	info(0, "1");
    grp = cfg_get_single_group(cfg, octstr_imm("core"));
    if (grp == NULL) {
    	printf("FATAL: Could not load Kannel's core group. Exiting.\n");
    	return 2;
    }

    store_location = cfg_get(grp, octstr_imm("store-location"));
    store_type = cfg_get(grp, octstr_imm("store-type"));

    store_init(store_type, store_location, -1, msg_pack, msg_unpack_wrapper);

    switch (command) {
    case COMMAND_LIST:
    	printf("Listing records %d -> %d\n", list_from+1, list_limit);
    	print_header();
		store_load(print_msg);
		if (counter == 0) {
			printf("|%60s%14s%60s|\n", "", "Store is Empty", "");
		}
		print_sep();
		break;
    case COMMAND_DELETE:
    	store_load(msg_count);
    	msg = msg_create(ack);
    	msg->ack.nack = ack_failed;
    	msg->ack.time = time(NULL);
    	uuid_parse(octstr_get_cstr(param_1), msg->ack.id);
    	ret = store_save(msg);
        if (ret == 0) {
        	printf("Deleted message %s\n", octstr_get_cstr(param_1));
        	counter--;
        } else {
        	printf("Could not delete message %s\n", octstr_get_cstr(param_1));
        }
        msg_destroy(msg);
		break;
    case COMMAND_EXPORT:
    	counter = 0;
    	type = 0;
    	list = gwlist_create();
    	store_load(msg_push);
    	printf("Exporting %ld messages...\n", gwlist_len(list));
    	if ((octstr_compare(param_1, octstr_imm("file")) == 0) ||
    		(octstr_compare(param_1, octstr_imm("spool")) == 0)) {
        	store_shutdown();
        	store_init(param_1, param_2, -1, msg_pack, msg_unpack_wrapper);
        	store_load(msg_count);
        	while ((os = gwlist_extract_first(list)) != NULL) {
        		msg = msg_unpack_wrapper(os);
        		if (msg != NULL) {
    				ret = store_save(msg);
    				if (ret == 0) {
    					counter++;
    				} else {
    					printf("Error saving message\n");
    				}
        		} else {
        			printf("Error extracting message\n");
        		}
        		msg_destroy(msg);
        	}
        	status = NULL;
    	} else if (octstr_compare(param_1, octstr_imm("text")) == 0) {
    		status = store_status(BBSTATUS_TEXT);
    	} else if (octstr_compare(param_1, octstr_imm("html")) == 0) {
    		status = store_status(BBSTATUS_HTML);
    	} else if (octstr_compare(param_1, octstr_imm("xml")) == 0) {
    		status = store_status(BBSTATUS_XML);
		} else {
			status = NULL;
		}
    	if (status != NULL) {
    	    file = fopen(octstr_get_cstr(param_2), "w");
    	    if (file == NULL) {
    	        error(errno, "Failed to open '%s' for writing, cannot create output file",
    		      octstr_get_cstr(param_2));
    	        return -1;
    	    }
    	    octstr_print(file, status);
    	    fflush(file);
    	    if (file != NULL)
    	    	fclose(file);
    		//printf("%s", octstr_get_cstr(status));
    	}
    	gwlist_destroy(list, octstr_destroy_item);

		break;
    default:
    	break;
    }

    octstr_destroy(store_type);
    octstr_destroy(store_location);
    cfg_destroy(cfg);
    store_shutdown();
error:
    gwlib_shutdown();

    return 1;
}