void dkc_compile_error(int line_number, CompileError id, ...) { va_list ap; VWString message; self_check(); va_start(ap, id); dkc_vwstr_clear(&message); format_message(line_number, &dkc_error_message_format[id], &message, ap); fprintf(stderr, "%3d:", line_number); dvm_print_wcs_ln(stderr, message.string); va_end(ap); exit(1); }
static void raw_event(const char *data, int controllerId, int callbackId, void *context) { struct context *ctx = context; struct relay_rule *relay_rules = ctx->relay_rules; if(ctx->debug>1) printf("raw_event: %s\n", data); struct telldus_data d; telldus_data_init(&d,data); int f = 0; for(f=0; f<ctx->num_relay_rules; f++) { int i = 0; int accepted = 1; // ensure all filters match in this relay_rule specification while(relay_rules[f].filters[i].key && relay_rules[f].filters[i].value && accepted) { char expected[256]; telldus_data_get_value(expected, sizeof(expected)-1, relay_rules[f].filters[i].key, &d); accepted &= !strcmp(expected, relay_rules[f].filters[i].value); i++; } int j = 0; if(accepted) { // matched, now format and deliver messages on all associated mqtt_templates while(relay_rules[f].mqtt_template[j].topicformat && relay_rules[f].mqtt_template[j].messageformat && ! ctx->failures) { char topic[1024]; char publish_topic[1024]; char message[256]; format_message(topic, sizeof(topic)-1, relay_rules[f].mqtt_template[j].topicformat, &d); format_message(message, sizeof(topic)-1, relay_rules[f].mqtt_template[j].messageformat, &d); snprintf(publish_topic,sizeof(publish_topic), "%s%s",ctx->pub_prefix,topic); int rc2; static int mid_sent = 0; rc2 = mosquitto_publish(ctx->mosq, &mid_sent, publish_topic, strlen(message), (uint8_t *)message, relay_rules[f].mqtt_template[j].qos, relay_rules[f].mqtt_template[j].retain); if(rc2) { fprintf(stderr, "Error: mosquitto_publish() returned %d: %s.\n", rc2, mosquitto_strerror(rc2)); // ignore failures for now, telldus callbacks can appear before MQTT connection is established // ctx->failures++; } if(ctx->debug>3) fprintf(stderr, "Done with template %d.\n", j); j++; } } } telldus_data_release(&d); }
/* * log an error from an exception object */ void CTcMain::S_log_error(CTcTokFileDesc *linedesc, long linenum, int *err_counter, int *warn_counter, unsigned long options, const int *suppress_list, size_t suppress_cnt, tc_severity_t severity, CVmException *exc) { const char *msg; char msgbuf[1024]; /* show the prefix */ msg = log_msg_internal_1(linedesc, linenum, err_counter, warn_counter, 0, 0, options, suppress_list, suppress_cnt, severity, exc->get_error_code()); /* if the message is suppressed, we're done */ if (msg == 0) return; /* format the message using arguments stored in the exception */ err_format_msg(msgbuf, sizeof(msgbuf), msg, exc); /* print the error */ format_message(msgbuf, options); /* show the suffix */ log_msg_internal_2(options, severity); }
/* * Log an error using va_list arguments */ void CTcMain::S_v_log_error(CTcTokFileDesc *linedesc, long linenum, int *err_counter, int *warn_counter, int *first_error, int *first_warning, unsigned long options, const int *suppress_list, size_t suppress_cnt, tc_severity_t severity, int err, va_list args) { const char *msg; char msgbuf[2048]; /* show the prefix */ msg = log_msg_internal_1(linedesc, linenum, err_counter, warn_counter, first_error, first_warning, options, suppress_list, suppress_cnt, severity, err); /* if the message is suppressed, we're done */ if (msg == 0) return; /* format the message using the va_list argument */ t3vsprintf(msgbuf, sizeof(msgbuf), msg, args); /* display it */ format_message(msgbuf, options); /* show the suffix */ log_msg_internal_2(options, severity); }
/* convert record_header2 -> record_header and fetch external body */ void export_record(const record_header2 &hd2, render_buf &output, input_file &input) { record_header hd; memcpy(hd.key, hd2.key, sizeof(record_header::key)); hd.flags = hd2.flags; hd.crc = hd2.crc; hd.body_size = hd2.body_size; output.put(hd); if (!hd2.is_body_present) { input.set_file_pos(hd2.body_pos); file_size_t sz = hd2.body_size; while (sz != 0) { mem_chunk buf = output.get_free_mem().sub_chunk(0, std::min<file_size_t>(sz, SIZE_MAX)); if (!input.read(buf)) { throw std::runtime_error( format_message( "Data corrupt %s (+%"PRId64")", input.get_file_path().c_str(), input.get_file_pos())); } output.write(buf); sz -= buf.size(); } } }
void go_cmd_context_error_export (GOCmdContext *context, char const *message) { GError *err = format_message (go_error_export (), message); go_cmd_context_error (context, err); g_error_free (err); }
static gboolean received_chat_msg_cb(PurpleAccount *account, char *sender, char *message, PurpleConversation *conv, PurpleMessageFlags flags, gpointer data) { PurpleConvChat *chat = PURPLE_CONV_CHAT(conv); purple_debug_info(PLUGIN_ID, "%s\n", message); /* only listen to rooms on the list */ if (!g_list_find(chatroom_list, chat)) return FALSE; /* stop duplicated messages from QQ Qun */ if (!strcmp(account->protocol_id, "prpl-qq") && (account->alias) && !strcmp(sender, account->alias)) return FALSE; /* if received, push to other chatrooms on the list */ if ( (flags & PURPLE_MESSAGE_RECV) ) { char *msg = format_message(sender, message); void forward_chat_message(gpointer data, gpointer user_data) { PurpleConvChat *chatroom = (PurpleConvChat*)data; if(chatroom != chat) { purple_conv_chat_send(chatroom, msg); } }
parse_exception(Iterator const& begin, Iterator const& end) : parse_exception( format_message(begin == end ? static_cast<boost::optional<char>>(boost::none) : *begin), begin.position(), lexer::position{ begin.position().offset() + 1, begin.position().line() } ) { }
void Handler::on_message(connection_ptr con, message_ptr msg) { if (msg->get_opcode() != websocketpp::frame::opcode::TEXT) return; Log::debug("client <%s>: <message> %s", plain(con).c_str(), msg->get_payload().c_str()); publish(format_message(msg->get_payload())); }
void print_message(int friendnumber, uint8_t * string, uint16_t length) { char name[MAX_NAME_LENGTH]; getname(friendnumber, (uint8_t*)name); char msg[100+length+strlen(name)+1]; time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); char* temp = asctime(timeinfo); size_t len = strlen(temp); temp[len-1] = '\0'; sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp new_lines(format_message((char*)string, friendnumber)); }
void jpeg_error_mgr::output_message(void) { char buffer[JMSG_LENGTH_MAX]; // Create the message format_message(buffer); #ifdef USE_WINDOWS_MESSAGEBOX // Display it in a message dialog box MessageBox(GetActiveWindow(), buffer, "JPEG Library Error", MB_OK | MB_ICONERROR); #else /* Send it to stderr, adding a newline */ fprintf(stderr, "%s\n", buffer); #endif }
mrpc_status_t format_reply_error(struct mrpc_message *request, mrpc_status_t status, struct mrpc_message **result) { struct mrpc_message *msg; if (status == MINIRPC_OK) return MINIRPC_INVALID_ARGUMENT; if (format_message(request->conn, (xdrproc_t)xdr_void, NULL, &msg)) return MINIRPC_ENCODING_ERR; msg->hdr.sequence=request->hdr.sequence; msg->hdr.status=status; msg->hdr.cmd=request->hdr.cmd; *result=msg; return MINIRPC_OK; }
void crb_runtime_error(int line_number, RuntimeError id, ...) { va_list ap; VString message; self_check(); va_start(ap, id); clear_v_string(&message); format_message(&crb_runtime_error_message_format[id], &message, ap); fprintf(stderr, "%3d:%s\n", line_number, message.string); va_end(ap); exit(1); }
void crb_runtime_error(int line_number, RuntimeError id, ...) { va_list ap; VString message; self_check(); va_start(ap, id); crb_vstr_clear(&message); format_message(line_number, &crb_runtime_error_message_format[id], &message, ap); fprintf(stderr, "%3d:", line_number); CRB_print_wcs_ln(stderr, message.string); va_end(ap); exit(1); }
void crb_compile_error(CompileError id, ...) { va_list ap; VString message; int line_number; self_check(); va_start(ap, id); line_number = crb_get_current_interpreter()->current_line_number; clear_v_string(&message); format_message(&crb_compile_error_message_format[id], &message, ap); fprintf(stderr, "%3d:%s\n", line_number, message.string); va_end(ap); exit(1); }
mrpc_status_t format_request(struct mrpc_connection *conn, unsigned cmd, void *data, struct mrpc_message **result) { struct mrpc_message *msg; xdrproc_t type; mrpc_status_t ret; if (conn->set->protocol->sender_request_info(cmd, &type, NULL)) return MINIRPC_ENCODING_ERR; ret=format_message(conn, type, data, &msg); if (ret) return ret; msg->hdr.sequence=g_atomic_int_exchange_and_add(&conn->next_sequence, 1); msg->hdr.status=MINIRPC_PENDING; msg->hdr.cmd=cmd; *result=msg; return MINIRPC_OK; }
mrpc_status_t format_reply(struct mrpc_message *request, void *data, struct mrpc_message **result) { struct mrpc_message *msg; xdrproc_t type; mrpc_status_t ret; if (request->conn->set->protocol-> receiver_reply_info(request->hdr.cmd, &type, NULL)) return MINIRPC_ENCODING_ERR; ret=format_message(request->conn, type, data, &msg); if (ret) return ret; msg->hdr.sequence=request->hdr.sequence; msg->hdr.status=MINIRPC_OK; msg->hdr.cmd=request->hdr.cmd; *result=msg; return MINIRPC_OK; }
void swi_log_trace(const char *module, swi_log_level_t severity, const char *format, ...) { char *user_message = NULL, *formatted_message = NULL; va_list ap; int ret; if (!swi_log_musttrace(module, severity)) return; va_start(ap, format); ret = vasprintf(&user_message, format, ap); (void)ret; formatted_message = format_message(module, severity, user_message); loggers(module, severity, formatted_message); free(formatted_message); free(user_message); va_end(ap); }
void dvm_error(DVM_Executable *exe, Function *func, int pc, RuntimeError id, ...) { va_list ap; VString message; int line_number; self_check(); va_start(ap, id); dvm_vstr_clear(&message); format_message(&dvm_error_message_format[id], &message, ap); if (pc != NO_LINE_NUMBER_PC) { line_number = conv_pc_to_line_number(exe, func, pc); fprintf(stderr, "%3d:", line_number); } dvm_print_wcs_ln(stderr, message.string); va_end(ap); exit(1); }
size_t get_available_mem_size() { const char *p = getenv("AVAILABLE_MEM"); if (!p) { return 8 * GiB; } else { char *endp; double v = strtod(p, &endp); if (endp == p || (*endp && !strchr("kKmMgG", *endp)) || v < 0.0) { throw std::runtime_error( format_message("Invalid settings in env: AVAILABLE_MEM=%s", p)); } switch (*endp) { default: return v; case 'k': case 'K': return v * KiB; case 'm': case 'M': return v * MiB; case 'g': case 'G': return v * GiB; } } }
void print_message(int friendnumber, uint8_t * string, uint16_t length) { new_lines(format_message((char*)string, friendnumber)); }
void line_eval(char *line) { if (line[0] == '/') { char inpt_command = line[1]; char prompt[STRING_LENGTH+2] = "> "; int prompt_offset = 3; strcat(prompt, line); new_lines(prompt); if (inpt_command == 'f') { // add friend command: /f ID int i; char temp_id[128]; for (i = 0; i < 128; i++) temp_id[i] = line[i+prompt_offset]; unsigned char *bin_string = hex_string_to_bin(temp_id); int num = m_addfriend(bin_string, (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); free(bin_string); char numstring[100]; switch (num) { case FAERR_TOOLONG: sprintf(numstring, "[i] Message is too long."); break; case FAERR_NOMESSAGE: sprintf(numstring, "[i] Please add a message to your request."); break; case FAERR_OWNKEY: sprintf(numstring, "[i] That appears to be your own ID."); break; case FAERR_ALREADYSENT: sprintf(numstring, "[i] Friend request already sent."); break; case FAERR_UNKNOWN: sprintf(numstring, "[i] Undefined error when adding friend."); break; default: sprintf(numstring, "[i] Added friend as %d.", num); break; } new_lines(numstring); do_refresh(); } else if (inpt_command == 'd') { doMessenger(); } else if (inpt_command == 'm') { //message command: /m friendnumber messsage size_t len = strlen(line); if(len < 3) return; char numstring[len-3]; char message[len-3]; int i; for (i = 0; i < len; i++) { if (line[i+3] != ' ') { numstring[i] = line[i+3]; } else { int j; for (j = (i+1); j < (len+1); j++) message[j-i-1] = line[j+3]; break; } } int num = atoi(numstring); if (m_sendmessage(num, (uint8_t*) message, strlen(message) + 1) != 1) { new_lines("[i] could not send message"); } else { new_lines(format_message(message, -1)); } } else if (inpt_command == 'n') { uint8_t name[MAX_NAME_LENGTH]; int i = 0; size_t len = strlen(line); for (i = 3; i < len; i++) { if (line[i] == 0 || line[i] == '\n') break; name[i-3] = line[i]; } name[i-3] = 0; setname(name, i - 2); char numstring[100]; sprintf(numstring, "[i] changed nick to %s", (char*)name); new_lines(numstring); } else if (inpt_command == 'l') { print_friendlist(); } else if (inpt_command == 's') { uint8_t status[MAX_STATUSMESSAGE_LENGTH]; int i = 0; size_t len = strlen(line); for (i = 3; i < len; i++) { if (line[i] == 0 || line[i] == '\n') break; status[i-3] = line[i]; } status[i-3] = 0; m_set_statusmessage(status, strlen((char*)status) + 1); char numstring[100]; sprintf(numstring, "[i] changed status to %s", (char*)status); new_lines(numstring); } else if (inpt_command == 'a') { uint8_t numf = atoi(line + 3); char numchar[100]; if (numf >= num_requests || pending_requests[numf].accepted) { sprintf(numchar,"[i] you either didn't receive that request or you already accepted it"); new_lines(numchar); } else { int num = m_addfriend_norequest(pending_requests[numf].id); if (num != -1) { pending_requests[numf].accepted = 1; sprintf(numchar, "[i] friend request %u accepted", numf); new_lines(numchar); sprintf(numchar, "[i] added friendnumber %d", num); new_lines(numchar); } else { sprintf(numchar, "[i] failed to add friend"); new_lines(numchar); } } do_refresh(); } else if (inpt_command == 'h') { //help new_lines(help); } else if (inpt_command == 'i') { //info char idstring[200]; get_id(idstring); new_lines(idstring); } else if (inpt_command == 'q') { //exit endwin(); exit(EXIT_SUCCESS); } else { new_lines("[i] invalid command"); } } else { new_lines("[i] invalid command"); //new_lines(line); } }
/*********************************************************************** * FormatMessageA (KERNEL32.@) * FIXME: missing wrap, */ DWORD WINAPI FormatMessageA( DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPSTR lpBuffer, DWORD nSize, __ms_va_list* args ) { struct format_args format_args; DWORD ret = 0; LPWSTR target; DWORD destlength; LPWSTR from; DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK; TRACE("(0x%x,%p,%d,0x%x,%p,%d,%p)\n", dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args); if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) { if (!lpBuffer) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); return 0; } else *(LPSTR *)lpBuffer = NULL; } if (dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY) { format_args.args = (ULONG_PTR *)args; format_args.list = NULL; format_args.last = 0; } else { format_args.args = NULL; format_args.list = args; format_args.last = 0; } if (width && width != FORMAT_MESSAGE_MAX_WIDTH_MASK) FIXME("line wrapping (%u) not supported.\n", width); from = NULL; if (dwFlags & FORMAT_MESSAGE_FROM_STRING) { DWORD length = MultiByteToWideChar(CP_ACP, 0, lpSource, -1, NULL, 0); from = HeapAlloc( GetProcessHeap(), 0, length * sizeof(WCHAR) ); MultiByteToWideChar(CP_ACP, 0, lpSource, -1, from, length); } else if (dwFlags & (FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_SYSTEM)) { if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) from = load_message( (HMODULE)lpSource, dwMessageId, (WORD)dwLanguageId ); if (!from && (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)) from = load_message( kernel32_handle, dwMessageId, (WORD)dwLanguageId ); if (!from) return 0; } else { SetLastError(ERROR_INVALID_PARAMETER); return 0; } target = format_message( FALSE, dwFlags, from, &format_args ); if (!target) goto failure; TRACE("-- %s\n", debugstr_w(target)); /* Only try writing to an output buffer if there are processed characters * in the temporary output buffer. */ if (*target) { destlength = WideCharToMultiByte(CP_ACP, 0, target, -1, NULL, 0, NULL, NULL); if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) { LPSTR buf = LocalAlloc(LMEM_ZEROINIT, max(nSize, destlength)); WideCharToMultiByte(CP_ACP, 0, target, -1, buf, destlength, NULL, NULL); *((LPSTR*)lpBuffer) = buf; } else { if (nSize < destlength) { SetLastError(ERROR_INSUFFICIENT_BUFFER); goto failure; } WideCharToMultiByte(CP_ACP, 0, target, -1, lpBuffer, destlength, NULL, NULL); } ret = destlength - 1; /* null terminator */ } failure: HeapFree(GetProcessHeap(),0,target); HeapFree(GetProcessHeap(),0,from); if (!(dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY)) HeapFree( GetProcessHeap(), 0, format_args.args ); TRACE("-- returning %u\n", ret); return ret; }
/*********************************************************************** * FormatMessageW (KERNEL32.@) */ DWORD WINAPI FormatMessageW( DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list* args ) { struct format_args format_args; DWORD ret = 0; LPWSTR target; DWORD talloced; LPWSTR from; DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK; TRACE("(0x%x,%p,%d,0x%x,%p,%d,%p)\n", dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args); if (!lpBuffer) { SetLastError(ERROR_INVALID_PARAMETER); return 0; } if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) *(LPWSTR *)lpBuffer = NULL; if (dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY) { format_args.args = (ULONG_PTR *)args; format_args.list = NULL; format_args.last = 0; } else { format_args.args = NULL; format_args.list = args; format_args.last = 0; } if (width && width != FORMAT_MESSAGE_MAX_WIDTH_MASK) FIXME("line wrapping not supported.\n"); from = NULL; if (dwFlags & FORMAT_MESSAGE_FROM_STRING) { from = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpSource) + 1) * sizeof(WCHAR) ); strcpyW( from, lpSource ); } else if (dwFlags & (FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_SYSTEM)) { if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) from = load_message( (HMODULE)lpSource, dwMessageId, (WORD)dwLanguageId ); if (!from && (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)) from = load_message( kernel32_handle, dwMessageId, (WORD)dwLanguageId ); if (!from) return 0; } else { SetLastError(ERROR_INVALID_PARAMETER); return 0; } target = format_message( TRUE, dwFlags, from, &format_args ); if (!target) goto failure; talloced = strlenW(target)+1; TRACE("-- %s\n",debugstr_w(target)); /* Only allocate a buffer if there are processed characters in the * temporary output buffer. If a caller supplies the buffer, then * a null terminator will be written to it. */ if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) { if (*target) { /* nSize is the MINIMUM size */ *((LPVOID*)lpBuffer) = LocalAlloc(LMEM_ZEROINIT, max(nSize, talloced)*sizeof(WCHAR)); strcpyW(*(LPWSTR*)lpBuffer, target); } } else { if (nSize < talloced) { SetLastError(ERROR_INSUFFICIENT_BUFFER); goto failure; } strcpyW(lpBuffer, target); } ret = talloced - 1; /* null terminator */ failure: HeapFree(GetProcessHeap(),0,target); HeapFree(GetProcessHeap(),0,from); if (!(dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY)) HeapFree( GetProcessHeap(), 0, format_args.args ); TRACE("-- returning %u\n", ret); return ret; }
void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) { if (line[0] == '/') { char inpt_command = line[1]; char prompt[STRING_LENGTH + 2] = "> "; strcat(prompt, line); new_lines(prompt); if (inpt_command == 'f') { // add friend command: /f ID int i; char temp_id[128]; for (i = 0; i < 128; i++) temp_id[i] = line[i+3]; int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); char numstring[100]; sprintf(numstring, "[i] added friend %d", num); new_lines(numstring); do_refresh(); } else if (inpt_command == 'd') { doMessenger(); } else if (inpt_command == 'm') { //message command: /m friendnumber messsage size_t len = strlen(line); char numstring[len-3]; char message[len-3]; int i; for (i = 0; i < len; i++) { if (line[i+3] != ' ') { numstring[i] = line[i+3]; } else { int j; for (j = (i+1); j < len; j++) message[j-i-1] = line[j+3]; break; } } int num = atoi(numstring); if (m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { new_lines("[i] could not send message"); } else { new_lines(format_message(message, -1)); } } else if (inpt_command == 'n') { uint8_t name[MAX_NAME_LENGTH]; int i = 0; size_t len = strlen(line); for (i = 3; i < len; i++) { if (line[i] == 0 || line[i] == '\n') break; name[i-3] = line[i]; } name[i-3] = 0; setname(name, i); char numstring[100]; sprintf(numstring, "[i] changed nick to %s", (char*)name); new_lines(numstring); } else if (inpt_command == 'l') { print_friendlist(); } else if (inpt_command == 's') { uint8_t status[MAX_USERSTATUS_LENGTH]; int i = 0; size_t len = strlen(line); for (i = 3; i < len; i++) { if (line[i] == 0 || line[i] == '\n') break; status[i-3] = line[i]; } status[i-3] = 0; m_set_userstatus(status, strlen((char*)status)); char numstring[100]; sprintf(numstring, "[i] changed status to %s", (char*)status); new_lines(numstring); } else if (inpt_command == 'a') { uint8_t numf = atoi(line + 3); char numchar[100]; int num = m_addfriend_norequest(pending_requests[numf]); if (num != -1) { sprintf(numchar, "[i] friend request %u accepted", numf); new_lines(numchar); sprintf(numchar, "[i] added friendnumber %d", num); new_lines(numchar); } else { sprintf(numchar, "[i] failed to add friend"); new_lines(numchar); } do_refresh(); } else if (inpt_command == 'h') { //help new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)"); new_lines("[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)"); } else if (inpt_command == 'i') { //info char idstring0[200]; char idstring1[PUB_KEY_BYTES][5]; char idstring2[PUB_KEY_BYTES][5]; int i; for (i = 0; i < PUB_KEY_BYTES; i++) { if (self_public_key[i] < (PUB_KEY_BYTES/2)) strcpy(idstring1[i],"0"); else strcpy(idstring1[i], ""); sprintf(idstring2[i], "%hhX", self_public_key[i]); } // strcpy(idstring0,"[i] ID: "); int j; for (j = 0; j < PUB_KEY_BYTES; j++) { strcat(idstring0,idstring1[j]); strcat(idstring0,idstring2[j]); } new_lines(idstring0); } else if (inpt_command == 'q') { //exit endwin(); exit(EXIT_SUCCESS); } else { new_lines("[i] invalid command"); } } else { new_lines("[i] invalid command"); //new_lines(line); } }
static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) { connection_data *conn = TLS->ev_base; struct tgl_message *M = C->msg; char *text = NULL; int flags = 0; // only display new messages, ignore updates or deletions if ((M->flags & (TGLMF_EMPTY | TGLMF_DELETED)) || !(M->flags & TGLMF_CREATED) || !M->message || tgp_outgoing_msg (TLS, M) || !tgl_get_peer_type (M->to_id)) { return; } if (M->flags & TGLMF_SERVICE) { text = format_service_msg (TLS, M); flags |= PURPLE_MESSAGE_SYSTEM; } else if (M->media.type == tgl_message_media_document && M->media.document->flags & TGLDF_STICKER) { #ifdef HAVE_LIBWEBP char *filename = C->data; int img = p2tgl_imgstore_add_with_id_webp (filename); if (img <= 0) { failure ("Cannot display sticker, adding to imgstore failed"); return; } used_images_add (conn, img); text = format_img_full (img); flags |= PURPLE_MESSAGE_IMAGES; g_free (filename); #else char *txt_user = p2tgl_strdup_alias (tgl_peer_get (TLS, M->from_id)); text = g_strdup_printf ("%s sent a sticker", txt_user); flags |= PURPLE_MESSAGE_SYSTEM; g_free (txt_user); #endif } else if (M->media.type == tgl_message_media_photo || (M->media.type == tgl_message_media_document_encr && M->media.encr_document->flags & TGLDF_IMAGE)) { char *filename = C->data; int img = p2tgl_imgstore_add_with_id (filename); if (img <= 0) { failure ("Cannot display picture message, adding to imgstore failed."); return; } used_images_add (conn, img); text = format_img_full (img); flags |= PURPLE_MESSAGE_IMAGES; g_free (filename); } else if (M->media.type == tgl_message_media_document) { char *who = p2tgl_strdup_id (M->from_id); if (! tgp_our_msg(TLS, M)) { tgprpl_recv_file (conn->gc, who, M->media.document); } g_free (who); return; } else if (M->media.type == tgl_message_media_document_encr) { char *who = p2tgl_strdup_id (M->to_id); if (! tgp_our_msg(TLS, M)) { tgprpl_recv_encr_file (conn->gc, who, M->media.encr_document); } g_free (who); return; } else { text = format_message (M); flags |= PURPLE_MESSAGE_RECV; } if (! text || ! *text) { warning ("No text to display"); return; } switch (tgl_get_peer_type (M->to_id)) { case TGL_PEER_CHAT: { if (chat_show (conn->gc, tgl_get_peer_id (M->to_id))) { p2tgl_got_chat_in (TLS, M->to_id, M->from_id, text, flags, M->date); } pending_reads_add (conn->pending_reads, M->to_id); break; } case TGL_PEER_ENCR_CHAT: { p2tgl_got_im (TLS, M->to_id, text, flags, M->date); pending_reads_add (conn->pending_reads, M->to_id); break; } case TGL_PEER_USER: { if (tgp_our_msg (TLS, M)) { flags |= PURPLE_MESSAGE_SEND; flags &= ~PURPLE_MESSAGE_RECV; p2tgl_got_im_combo (TLS, M->to_id, text, flags, M->date); } else { p2tgl_got_im (TLS, M->from_id, text, flags, M->date); pending_reads_add (conn->pending_reads, M->from_id); } break; } } if (p2tgl_status_is_present (purple_account_get_active_status (conn->pa)) && p2tgl_send_notifications(conn->pa)) { pending_reads_send_all (conn->pending_reads, conn->TLS); } g_free (text); }
void print_message(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) { new_lines(format_message(m, (char *)string, friendnumber)); }
/* ========================================================================== * */ int main(int argc,char **argv) { int got; canmsg_t rx[RXBUFFERSIZE]; int i; printf("usage: %s <devices>]\n", argv[0]); printf(" e.g.:\n"); printf(" %s /dev/can0 .... \n", argv[0]); printf(" wait for CAN messages using select()\n"); printf(" DLC in () Standard CAN frame, in [] for CAN FD frames\n"); printf(" bit rate used is bit rate set in /proc/sys/dev/Can/Baud\n"); printf(" bit rates used: "); fflush(stdout); system("cat /proc/sys/dev/Can/Baud"); if (argc < 2) { char *argv[] = { "", STDDEV}; argc = 2; get_device_names(argc, argv); } else { get_device_names(argc, argv); } #if DEBUG for(i = 0; i < current_open; i++) { printf("> device %s using fd %d\n", devname[i], fd[i]); } #endif /* prepare clean up console mode at exit */ atexit(clean); /* switch terminal in raw mode */ i = system("stty cbreak -echo"); if(i != 0) { fprintf(stderr, " system(stty) returns %d\n", i); fflush(stderr); } int maxfd = fd[current_open - 1] + 1; int quit = 0; while(!quit) { FD_ZERO(&rfds); for (i = 0; i < current_open; i++) { FD_SET(fd[i], &rfds); /* watch on every fd for CAN */ } FD_SET(0, &rfds); /* watch on fd for stdin */ /* no wait for something to happen */ if( select(maxfd, &rfds, NULL, NULL, NULL ) > 0 ) for (i = 0; i < current_open; i++) { /* check all open file descriptors */ if( FD_ISSET(fd[i], &rfds) ) { got = read(fd[i], &rx, 1); if( got > 0) { format_message(i, &rx[0]); } else { printf("Received with ret=%d\n", got); fflush(stdout); } } } if( FD_ISSET(0, &rfds) ) { int c, i; /* it was the stdio terminal fd */ i = read(0 , &c, 1); /* printf(" key = %x\n", c); */ switch(c & 0xff) { /* should work with utf8 and 8859 */ case 'l': system("clear"); break; case 'c': printf( "--------------------------------------------------\n"); break; case 'q': /* quit */ quit = 1; break; /* while loop */ case '?': case 'h': printf(" -c draw a \"cut\" line\n"); printf(" -l erase screen\n"); break; } } /* stdio fd */ } for (i = 0; i < current_open; i++) { close(fd[i]); } return 0; }
static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) { connection_data *conn = TLS->ev_base; struct tgl_message *M = C->msg; char *text = NULL; int flags = 0; // Filter message updates and deletes, are not created and // all messages in general that were already displayed, or shouldn't be displayed if ((M->flags & (FLAG_MESSAGE_EMPTY | FLAG_DELETED)) || !(M->flags & FLAG_CREATED) || !M->message || our_msg (TLS, M) || !tgl_get_peer_type (M->to_id)) { return; } if (M->service) { text = format_service_msg (TLS, M); flags |= PURPLE_MESSAGE_SYSTEM; } else if (M->media.type == tgl_message_media_document) { char *who = p2tgl_strdup_id (M->from_id); if (! out_msg(TLS, M)) { tgprpl_recv_file (conn->gc, who, &M->media.document); } g_free (who); return; } else if (M->media.type == tgl_message_media_document_encr) { char *who = p2tgl_strdup_id (M->from_id); if (! out_msg(TLS, M)) { tgprpl_recv_encr_file (conn->gc, who, &M->media.encr_document); } g_free (who); } else if (M->media.type == tgl_message_media_photo) { char *filename = C->data; int imgStoreId = p2tgl_imgstore_add_with_id (filename); if (imgStoreId <= 0) { failure ("Cannot display picture message, adding to imgstore failed."); return; } used_images_add (conn, imgStoreId); text = format_img_full (imgStoreId); flags |= PURPLE_MESSAGE_IMAGES; } else { text = format_message (M); flags |= PURPLE_MESSAGE_RECV; } if (! text || ! *text) { warning ("No text to display"); return; } switch (tgl_get_peer_type (M->to_id)) { case TGL_PEER_CHAT: { if (chat_show (conn->gc, tgl_get_peer_id (M->to_id))) { p2tgl_got_chat_in (TLS, M->to_id, M->from_id, text, flags, M->date); } pending_reads_add (conn->pending_reads, M->to_id); break; } case TGL_PEER_ENCR_CHAT: { p2tgl_got_im (TLS, M->to_id, text, flags, M->date); pending_reads_add (conn->pending_reads, M->to_id); break; } case TGL_PEER_USER: { if (out_msg (TLS, M)) { flags |= PURPLE_MESSAGE_SEND; flags &= ~PURPLE_MESSAGE_RECV; p2tgl_got_im_combo (TLS, M->to_id, text, flags, M->date); } else { p2tgl_got_im (TLS, M->from_id, text, flags, M->date); pending_reads_add (conn->pending_reads, M->from_id); } break; } } if (p2tgl_status_is_present (purple_account_get_active_status (conn->pa))) { pending_reads_send_all (conn->pending_reads, conn->TLS); } g_free (text); }
allocation_exception(memsize size, const char* message = nullptr) : std::runtime_error {format_message(size, message)} { // }