/** * Send a status message back to the user who issued the !history command. */ static int command_status(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd, struct cbuffer* buf) { struct cbuffer* msg = cbuf_create(cbuf_size(buf) + strlen(cmd->prefix) + 8); cbuf_append_format(msg, "*** %s: %s", cmd->prefix, cbuf_get(buf)); plugin->hub.send_message(plugin, user, cbuf_get(msg)); cbuf_destroy(msg); cbuf_destroy(buf); return 0; }
static void _pstdout_state_cleanup(pstdout_state_t pstate) { assert(pstate); assert(pstate->magic == PSTDOUT_STATE_MAGIC); if (pstate->p_stdout) cbuf_destroy(pstate->p_stdout); if (pstate->p_stderr) cbuf_destroy(pstate->p_stderr); free(pstate->buffer_stdout); free(pstate->buffer_stderr); memset(pstate, '\0', sizeof(struct pstdout_state)); }
static int command_patternadd(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct patterns_data* pdata = (struct patterns_data*) plugin->ptr; struct cbuffer* buf = cbuf_create(128); struct plugin_command_arg_data* arg1 = (struct plugin_command_arg_data*) list_get_first(cmd->args); struct plugin_command_arg_data* arg2 = (struct plugin_command_arg_data*) list_get_next(cmd->args); struct plugin_command_arg_data* arg3 = (struct plugin_command_arg_data*) list_get_next(cmd->args); struct plugin_command_arg_data* arg4 = (struct plugin_command_arg_data*) list_get_next(cmd->args); char* t = arg1->data.string; enum pattern_types type; if (!pattern_string_to_type(t, &type)) { cbuf_append_format(buf, "*** %s: Wrong pattern type \"%s\". Available types are: MC, PM, NI, UA.", cmd->prefix, t); } else { enum auth_credentials mincred = arg2->data.credentials; enum auth_credentials maxcred = arg3->data.credentials; char* str = arg4->data.string; int rc = sql_execute(pdata, null_callback, NULL, "INSERT INTO patterns VALUES(NULL, '%s', %d, '%s', '%s');", sql_escape_string(str), type, auth_cred_to_string(mincred), auth_cred_to_string(maxcred)); if (rc > 0) cbuf_append_format(buf, "*** %s: Added pattern \"%s\" to %s group.", cmd->prefix, str, pattern_type_to_string(type)); else cbuf_append_format(buf, "*** %s: Unable to add pattern \"%s\".", cmd->prefix, str); } plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); return 0; }
void client_free (Client *client) { if (client == NULL) return; if (client->file) { fflush (client->file); fclose (client->file); client->file = NULL; } oml_free (client->file_name); oml_free (client->downstream_addr); struct header *header = client->headers; while (header) { struct header *next = header->next; header_free (header); header = next; } msg_queue_destroy (client->messages); cbuf_destroy (client->cbuf); pthread_cond_destroy (&client->condvar); pthread_mutex_destroy (&client->mutex); socket_free (client->recv_socket); oml_free (client); }
static int command_hublist(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct extras_data* extrasdata = (struct extras_data*) plugin->ptr; struct cbuffer* buf = cbuf_create(128); sqlite3_stmt *res; int error = 0; int rec_count = 0; const char *tail; char *query = "SELECT * FROM hubs;"; cbuf_append_format(buf, "*** %s:", cmd->prefix); error = sqlite3_prepare_v2(extrasdata->db, query, strlen(query), &res, &tail); while (sqlite3_step(res) == SQLITE_ROW) { cbuf_append_format(buf, "\nID: %d, Address: %s , Name: \"%s\"\n", sqlite3_column_int(res, 0), (char*) sqlite3_column_text(res, 1), (char*) sqlite3_column_text(res, 2)); rec_count++; } if (error != SQLITE_OK || rec_count < 1) { cbuf_append(buf, " No hubs found in hublist."); } sqlite3_finalize(res); plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); return 0; }
static int command_patternexlist(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct patterns_data* pdata = (struct patterns_data*) plugin->ptr; struct cbuffer* buf = cbuf_create(128); sqlite3_stmt *res; int error = 0; const char *tail; char *query = "SELECT * FROM pattern_exceptions;"; cbuf_append_format(buf, "*** %s:\n", cmd->prefix); error = sqlite3_prepare_v2(pdata->db, query, strlen(query), &res, &tail); while (sqlite3_step(res) == SQLITE_ROW) { cbuf_append_format(buf, "ID: %d Pattern ID: %d Exception pattern: \"%s\" Exempt credentials: %s-%s\n", sqlite3_column_int(res, 0), sqlite3_column_int(res, 2), (char*) sqlite3_column_text(res, 1), (char*) sqlite3_column_text(res, 3), (char*) sqlite3_column_text(res, 4)); } sqlite3_finalize(res); plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); return 0; }
void user_login(struct plugin_handle* plugin, struct plugin_user* user) { struct chat_history_data* data = (struct chat_history_data*) plugin->ptr; struct cbuffer* buf = NULL; struct linked_list* found = (struct linked_list*) list_create(); sql_execute(data, get_messages_callback, found, "SELECT from_nick,message, datetime(time, 'localtime') as time FROM chat_history ORDER BY time DESC LIMIT 0,%d;", (int) data->history_connect); if (data->history_connect > 0 && list_size(found) > 0) { buf = cbuf_create(MAX_HISTORY_SIZE); cbuf_append(buf, "Chat history:\n\n"); struct chat_history_line* history_line; history_line = (struct chat_history_line*) list_get_last(found); while (history_line) { cbuf_append_format(buf, "[%s] <%s> %s\n", history_line->time, history_line->from, history_line->message); list_remove(found, history_line); hub_free(history_line); history_line = (struct chat_history_line*) list_get_last(found); } plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); } list_clear(found, &hub_free); list_destroy(found); }
*/JNIEXPORT jint JNICALL Java_com_jiuan_it_ipc_utils_RtspFromFFMPEG_close( JNIEnv *env, jobject obj) { LOGD("%s-------%d进入该函数", __FUNCTION__, __LINE__); if(out_buffer_video) av_free(out_buffer_video); if(out_buffer_audio) av_free(out_buffer_audio); if(img_convert_ctx) sws_freeContext(img_convert_ctx); if(aud_convert_ctx) swr_free(&aud_convert_ctx); if(pFrameYUV) av_frame_free(&pFrameYUV); if(pCodecCtx_video) avcodec_close(pCodecCtx_video); if(pCodecCtx_audio) avcodec_close(pCodecCtx_audio); if(pFormatCtx) avformat_close_input(&pFormatCtx); cbuf_destroy(&m_cbuf_video); cbuf_destroy(&m_cbuf_audio); LOGD("%s-------%d离开该函数", __FUNCTION__, __LINE__); return 1; }
static void _ipmipower_cleanup (void) { int i; cbuf_destroy (ttyin); /* Flush before destroying. */ cbuf_read_to_fd (ttyout, STDOUT_FILENO, -1); cbuf_destroy (ttyout); ipmipower_connection_array_destroy (ics, ics_len); for (i = 0; i < IPMIPOWER_MSG_TYPE_NUM_ENTRIES; i++) hostlist_destroy (output_hostrange[i]); }
static int command_releases(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct extras_data* extrasdata = (struct extras_data*) plugin->ptr; struct cbuffer* buf = cbuf_create(128); sqlite3_stmt *res; int error = 0; int rec_count = 0; const char *tail; char *query = "SELECT * FROM releases;"; cbuf_append_format(buf, "*** %s:", cmd->prefix); error = sqlite3_prepare_v2(extrasdata->db, query, strlen(query), &res, &tail); while (sqlite3_step(res) == SQLITE_ROW) { cbuf_append_format(buf, "\nID: %d\nTitle: %s\nMagnet link: magnet:?xt=urn:tree:tiger:%s\nPublished: %s", sqlite3_column_int(res, 0), (char*) sqlite3_column_text(res, 1), (char*) sqlite3_column_text(res, 2), (char*) sqlite3_column_text(res, 3)); rec_count++; } if (error != SQLITE_OK || rec_count < 1) { cbuf_append(buf, " No releases found."); } sqlite3_finalize(res); plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); return 0; }
static int command_patternexadd(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct patterns_data* pdata = (struct patterns_data*) plugin->ptr; struct cbuffer* buf = cbuf_create(128); struct plugin_command_arg_data* arg1 = (struct plugin_command_arg_data*) list_get_first(cmd->args); struct plugin_command_arg_data* arg2 = (struct plugin_command_arg_data*) list_get_next(cmd->args); struct plugin_command_arg_data* arg3 = (struct plugin_command_arg_data*) list_get_next(cmd->args); struct plugin_command_arg_data* arg4 = (struct plugin_command_arg_data*) list_get_next(cmd->args); int pattern_id = arg1->data.integer; enum auth_credentials mincred = arg2->data.credentials; enum auth_credentials maxcred = arg3->data.credentials; char* str = arg4->data.string; int rc = sql_execute(pdata, null_callback, NULL, "PRAGMA foreign_keys=ON; INSERT INTO pattern_exceptions VALUES(NULL, '%s', %d, '%s', '%s');", sql_escape_string(str), pattern_id, auth_cred_to_string(mincred), auth_cred_to_string(maxcred)); if (rc > 0) cbuf_append_format(buf, "*** %s: Added pattern exception \"%s\" to pattern ID %d.", cmd->prefix, str, pattern_id); else cbuf_append_format(buf, "*** %s: Unable to add pattern exception \"%s\" to pattern ID %d.", cmd->prefix, str, pattern_id); plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); return 0; }
void sched_log_fini(void) { if (!sched_log) return; slurm_mutex_lock(&log_lock); _log_flush(sched_log); xfree(sched_log->argv0); xfree(sched_log->fpfx); if (sched_log->buf) cbuf_destroy(sched_log->buf); if (sched_log->fbuf) cbuf_destroy(sched_log->fbuf); if (sched_log->logfp) fclose(sched_log->logfp); xfree(sched_log); slurm_mutex_unlock(&log_lock); }
static int command_resettopic_handler(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct cbuffer* buf = cbuf_create(128); plugin->hub.set_description(plugin, NULL); cbuf_append_format(buf, "*** %s: Topic reset.", cmd->prefix); plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); return 0; }
void log_fini(void) { if (!log) return; slurm_mutex_lock(&log_lock); _log_flush(log); xfree(log->argv0); xfree(log->fpfx); if (log->buf) cbuf_destroy(log->buf); if (log->fbuf) cbuf_destroy(log->fbuf); if (log->logfp) fclose(log->logfp); xfree(log); xfree(slurm_prog_name); slurm_mutex_unlock(&log_lock); }
static int command_showtopic_handler(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct cbuffer* buf = cbuf_create(128); char* topic = plugin->hub.get_description(plugin); cbuf_append_format(buf, "*** %s: Current topic is: \"%s\"", cmd->prefix, topic); plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); hub_free(topic); return 0; }
void ipmipower_connection_array_destroy(struct ipmipower_connection *ics, unsigned int ics_len) { int i; if (!ics) return; for (i = 0; i < ics_len; i++) { close(ics[i].ipmi_fd); close(ics[i].ping_fd); cbuf_destroy(ics[i].ipmi_in); cbuf_destroy(ics[i].ipmi_out); cbuf_destroy(ics[i].ping_in); cbuf_destroy(ics[i].ping_out); } Free(ics); }
static int command_topic_handler(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct cbuffer* buf = cbuf_create(128); struct plugin_command_arg_data* arg = plugin->hub.command_arg_next(plugin, cmd, plugin_cmd_arg_type_string); char* topic = arg ? arg->data.string : ""; plugin->hub.set_description(plugin, topic); cbuf_append_format(buf, "*** %s: Topic set to \"%s\"", cmd->prefix, topic); plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); return 0; }
static int zio_init_buffer (zio_t *zio) { assert (zio != NULL); assert (zio->magic == ZIO_MAGIC); assert (zio->buf == NULL); if (zio->buf) cbuf_destroy (zio->buf); if (!(zio->buf = cbuf_create (zio->buffersize, 1638400))) return (-1); cbuf_opt_set (zio->buf, CBUF_OPT_OVERWRITE, CBUF_NO_DROP); return (0); }
void user_login(struct plugin_handle* plugin, struct plugin_user* user) { struct chat_history_data* data = (struct chat_history_data*) plugin->ptr; struct cbuffer* buf = NULL; // size_t messages = 0; if (data->history_connect > 0 && list_size(data->chat_history) > 0) { buf = cbuf_create(MAX_HISTORY_SIZE); cbuf_append(buf, "Chat history:\n"); get_messages(data, data->history_connect, buf); plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); } }
int AVPacket_cbuf_free(cbuf_t *cbuf) { AVPacket *pkt = NULL; while (!cbuf_empty(cbuf)) { pkt = (AVPacket *)cbuf_dequeue(cbuf); if (pkt) { av_free_packet(pkt); } } cbuf_destroy(cbuf); cbuf_init(cbuf); return 0; }
void zio_destroy (zio_t *z) { if (z == NULL) return; assert (z->magic == ZIO_MAGIC); if (zio_is_in_handler (z)) { zio_set_destroyed (z); return; } if (z->buf) cbuf_destroy (z->buf); free (z->name); free (z->prefix); z->srcfd = z->dstfd = -1; assert (z->magic = ~ZIO_MAGIC); free (z); }
/** * The callback function for handling the !history command. */ static int command_history(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct chat_history_data* data = (struct chat_history_data*) plugin->ptr; struct cbuffer* buf = cbuf_create(MAX_HISTORY_SIZE); struct linked_list* found = (struct linked_list*) list_create(); struct plugin_command_arg_data* arg = plugin->hub.command_arg_next(plugin, cmd, plugin_cmd_arg_type_integer); int maxlines; if (arg) maxlines = arg->data.integer; else maxlines = data->history_default; sql_execute(data, get_messages_callback, found, "SELECT from_nick,message, datetime(time, 'localtime') as time FROM chat_history ORDER BY time DESC LIMIT 0,%d;", maxlines); size_t linecount = list_size(found); if (linecount > 0) { cbuf_append_format(buf, "*** %s: Chat History:\n\n", cmd->prefix); struct chat_history_line* history_line; history_line = (struct chat_history_line*) list_get_last(found); while (history_line) { cbuf_append_format(buf, "[%s] <%s> %s\n", history_line->time, history_line->from, history_line->message); list_remove(found, history_line); hub_free(history_line); history_line = (struct chat_history_line*) list_get_last(found); } } else { cbuf_append_format(buf, "*** %s: No messages found.", cmd->prefix); } plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); list_clear(found, &hub_free); list_destroy(found); return 0; }
static int command_patternexdel(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct patterns_data* pdata = (struct patterns_data*) plugin->ptr; struct cbuffer* buf = cbuf_create(128); struct plugin_command_arg_data* args = (struct plugin_command_arg_data*) list_get_first(cmd->args); int id = args->data.integer; int rc = sql_execute(pdata, null_callback, NULL, "DELETE FROM pattern_exceptions WHERE id=%d;", id); if (rc > 0) cbuf_append_format(buf, "*** %s: Deleted pattern exception with ID %d.", cmd->prefix, id); else cbuf_append_format(buf, "*** %s: Unable to delete pattern exception with id %d.", cmd->prefix, id); plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); return 0; }
void zio_destroy (zio_t *z) { if (z == NULL) return; assert (z->magic == ZIO_MAGIC); if (zio_is_in_handler (z)) { zio_set_destroyed (z); return; } if (z->buf) cbuf_destroy (z->buf); free (z->name); free (z->prefix); zio_close_src_fd (z); zio_close_dst_fd (z); flux_watcher_destroy (z->reader); flux_watcher_destroy (z->writer); assert ((z->magic = ~ZIO_MAGIC)); free (z); }
static int command_newsadd(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct extras_data* extrasdata = (struct extras_data*) plugin->ptr; struct cbuffer* buf = cbuf_create(128); struct plugin_command_arg_data* arg1 = (struct plugin_command_arg_data*) list_get_first(cmd->args); const char* news_text = sql_escape_string(arg1->data.string); int rc = sql_execute(extrasdata, null_callback, NULL, "INSERT INTO news (id, text) VALUES(NULL, '%s');", news_text); if (rc > 0) cbuf_append_format(buf, "*** %s: News updated.", cmd->prefix); else cbuf_append_format(buf, "*** %s: Unable to update news.", cmd->prefix); plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); return 0; }
static int command_historycleanup(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct chat_history_data* data = (struct chat_history_data*) plugin->ptr; struct cbuffer* buf = cbuf_create(128); int rc = 0; rc = sql_execute(data, null_callback, NULL, "DELETE FROM chat_history;"); if (!rc) cbuf_append_format(buf, "*** %s: Unable to clean chat history table.", cmd->prefix); else cbuf_append_format(buf, "*** %s: Cleaned chat history table.", cmd->prefix); plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); sql_execute(data, null_callback, NULL, "VACUUM;"); return 0; }
static int command_patterntest(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct patterns_data* pdata = (struct patterns_data*) plugin->ptr; struct cbuffer* buf = cbuf_create(128); struct plugin_command_arg_data* arg1 = (struct plugin_command_arg_data*) list_get_first(cmd->args); struct plugin_command_arg_data* arg2 = (struct plugin_command_arg_data*) list_get_next(cmd->args); int id = arg1->data.integer; char* str = arg2->data.string; sqlite3_stmt *res; int error = 0; const char *tail; char query[80]; cbuf_append_format(buf, "*** %s: ", cmd->prefix); int n = sprintf(query, "SELECT regexp FROM patterns WHERE id=%d LIMIT 1;", id); error = sqlite3_prepare_v2(pdata->db, query, n, &res, &tail); if (sqlite3_step(res) == SQLITE_ROW) { if(pattern_match(str, (char*) sqlite3_column_text(res, 0))) cbuf_append_format(buf, "Tested string \"%s\" matches pattern \"%s\".", str, sqlite3_column_text(res, 0)); else cbuf_append_format(buf, "Tested string \"%s\" does not match pattern \"%s\".", str, sqlite3_column_text(res, 0)); } else { cbuf_append_format(buf, "Pattern ID \"%d\" not found.", id); } sqlite3_finalize(res); plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); return 0; }
static int command_userlogcleanup(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct log_data* ldata = (struct log_data*) plugin->ptr; struct cbuffer* buf = cbuf_create(128); struct plugin_command_arg_data* arg = (struct plugin_command_arg_data*) list_get_first(cmd->args); int days = arg->data.integer; int rc = sql_execute(ldata, null_callback, NULL, "DELETE FROM userlog WHERE time < DATETIME('NOW', 'localtime', '-%d days');", days); if (rc > 0) cbuf_append_format(buf, "*** %s: Cleaned log entries older than %d days.", cmd->prefix, days); else cbuf_append_format(buf, "*** %s: Unable to clean log table.", cmd->prefix); plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); sql_execute(ldata, null_callback, NULL, "VACUUM;"); return 0; }
/** * The callback function for handling the !history command. */ static int command_history(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct cbuffer* buf; struct chat_history_data* data = (struct chat_history_data*) plugin->ptr; struct plugin_command_arg_data* arg = plugin->hub.command_arg_next(plugin, cmd, plugin_cmd_arg_type_integer); int maxlines; if (!list_size(data->chat_history)) return command_status(plugin, user, cmd, cbuf_create_const("No messages.")); if (arg) maxlines = arg->data.integer; else maxlines = data->history_default; buf = cbuf_create(MAX_HISTORY_SIZE); cbuf_append_format(buf, "*** %s: Chat History:\n", cmd->prefix); get_messages(data, maxlines, buf); plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); return 0; }
static int command_releaseadd(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct extras_data* extrasdata = (struct extras_data*) plugin->ptr; struct cbuffer* buf = cbuf_create(128); struct plugin_command_arg_data* arg1 = (struct plugin_command_arg_data*) list_get_first(cmd->args); struct plugin_command_arg_data* arg2 = (struct plugin_command_arg_data*) list_get_next(cmd->args); char* tth = strdup(sql_escape_string(arg1->data.string)); char* title = strdup(sql_escape_string(arg2->data.string)); int rc = sql_execute(extrasdata, null_callback, NULL, "INSERT INTO releases (id, title, tth) VALUES(NULL, '%s', '%s');", title, tth); if (rc > 0) cbuf_append_format(buf, "*** %s: Added \"%s\" to releases.", cmd->prefix, title); else cbuf_append_format(buf, "*** %s: Unable to add \"%s\" to releases.", cmd->prefix, title); plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); hub_free(tth); hub_free(title); return 0; }