static int plain_write_attrs(const char *filename, const attrs_type&attributes) { FILE * accountfile; t_hlist * curr; t_attr * attr; char const * key; char const * val; if (!(accountfile = fopen(filename,"w"))) { eventlog(eventlog_level_error, __FUNCTION__, "unable to open file \"%s\" for writing (fopen: %s)",filename,pstrerror(errno)); return -1; } BEGIN(_attr,attributes) { attr=*_attr; // hlist_for_each(curr, attributes) { // attr = hlist_entry(curr, t_attr, link); if (attr_get_key(attr)) key = escape_chars(attr_get_key(attr),strlen(attr_get_key(attr))); else { eventlog(eventlog_level_error, __FUNCTION__, "attribute with NULL key in list"); key = NULL; } if (attr_get_val(attr)) val = escape_chars(attr_get_val(attr),strlen(attr_get_val(attr))); else { eventlog(eventlog_level_error, __FUNCTION__, "attribute with NULL val in list"); val = NULL; } if (key && val) { if (strncmp("BNET\\CharacterDefault\\", key, 20) == 0) { eventlog(eventlog_level_debug, __FUNCTION__, "skipping attribute key=\"%s\"",attr->key.c_str()); } else { eventlog(eventlog_level_debug, __FUNCTION__, "saving attribute key=\"%s\" val=\"%s\"",attr->key.c_str(),attr->val.c_str()); fprintf(accountfile,"\"%s\"=\"%s\"\n",key,val); } } else eventlog(eventlog_level_error, __FUNCTION__,"could not save attribute key=\"%s\"",attr->key.c_str()); if (key) xfree((void *)key); /* avoid warning */ if (val) xfree((void *)val); /* avoid warning */ attr_clear_dirty(attr); }
static void complete_progs(const char *str, assoc_records_t records) { int i; const size_t len = strlen(str); for(i = 0; i < records.count; i++) { char command[NAME_MAX]; (void)extract_cmd_name(records.list[i].command, 1, sizeof(command), command); if(strnoscmp(command, str, len) == 0) { char *const escaped = escape_chars(command, "|"); vle_compl_add_match(escaped); free(escaped); } } }
static int message_telnet_format(t_packet * packet, t_message_type type, t_connection * me, t_connection * dst, char const * text, unsigned int dstflags) { char * msgtemp; if (!packet) { eventlog(eventlog_level_error,"message_telnet_format","got NULL packet"); return -1; } switch (type) { case message_type_uniqueid: if (!text) { eventlog(eventlog_level_error,"message_telnet_format","got NULL text for %s",message_type_get_str(type)); return -1; } if (!(msgtemp = malloc(strlen(text)+32))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"Your unique name: %s\r\n",text); break; case message_type_adduser: if (!me) { eventlog(eventlog_level_error,"message_telnet_format","got NULL connection for %s",message_type_get_str(type)); return -1; } { char const * tname; if(!(tname = conn_get_chatcharname(me, dst))) return -1; if (!(msgtemp = malloc(strlen(tname)+32))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"[%s is here]\r\n",tname); conn_unget_chatcharname(me,tname); } break; case message_type_join: if (!me) { eventlog(eventlog_level_error,"message_telnet_format","got NULL connection for %s",message_type_get_str(type)); return -1; } { char const * tname; if(!(tname = conn_get_chatcharname(me, dst))) return -1; if (!(msgtemp = malloc(strlen(tname)+32))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"[%s enters]\r\n",tname); conn_unget_chatcharname(me,tname); } break; case message_type_part: if (!me) { eventlog(eventlog_level_error,"message_telnet_format","got NULL connection for %s",message_type_get_str(type)); return -1; } { char const * tname; if(!(tname = conn_get_chatcharname(me, dst))) return -1; if(!(msgtemp = malloc(strlen(tname)+32))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"[%s leaves]\r\n",tname); conn_unget_chatcharname(me,tname); } break; case message_type_whisper: if (!me) { eventlog(eventlog_level_error,"message_telnet_format","got NULL connection for %s",message_type_get_str(type)); return -1; } if (!text) { eventlog(eventlog_level_error,"message_telnet_format","got NULL text for %s",message_type_get_str(type)); return -1; } if (dstflags&MF_X) return -1; /* player is ignored */ { char const * tname; char const * newtext; if(!(tname = conn_get_chatcharname(me, dst))) return -1; if((newtext = escape_chars(text,strlen(text)))) { if (!(msgtemp = malloc(strlen(tname)+8+strlen(newtext)+4))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); free((void *)newtext); /* avoid warning */ return -1; } sprintf(msgtemp,"<from %s> %s\r\n",tname,newtext); free((void *)newtext); /* avoid warning */ } else { if (!(msgtemp = malloc(16+strlen(tname)))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"<from %s> \r\n",tname); } conn_unget_chatcharname(me,tname); } break; case message_type_talk: if (!me) { eventlog(eventlog_level_error,"message_telnet_format","got NULL connection for %s",message_type_get_str(type)); return -1; } if (!text) { eventlog(eventlog_level_error,"message_telnet_format","got NULL text for %s",message_type_get_str(type)); return -1; } if (dstflags&MF_X) return -1; /* player is ignored */ { char const * tname; char const * newtext; if(!(tname = conn_get_chatcharname(me, me))) /* FIXME: second should be dst but cache gets in the way */ return -1; if((newtext = escape_chars(text,strlen(text)))) { if (!(msgtemp = malloc(strlen(tname)+4+strlen(newtext)+4))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"<%s> %s\r\n",tname,newtext); free((void *)newtext); /* avoid warning */ } else { if (!(msgtemp = malloc(strlen(tname)+8))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"<%s> \r\n",tname); } conn_unget_chatcharname(me,tname); } break; case message_type_broadcast: if (!text) { eventlog(eventlog_level_error,"message_telnet_format","got NULL text for %s",message_type_get_str(type)); return -1; } if (dstflags&MF_X) return -1; /* player is ignored */ { char const * newtext; if ((newtext = escape_chars(text,strlen(text)))) { if (!(msgtemp = malloc(16+strlen(newtext)+4))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"Broadcast: %s\r\n",newtext); /* FIXME: show source? */ free((void *)newtext); /* avoid warning */ } else { if (!(msgtemp = malloc(16))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"Broadcast: \r\n"); /* FIXME: show source? */ } } break; case message_type_channel: if (!text) { eventlog(eventlog_level_error,"message_telnet_format","got NULL text for %s",message_type_get_str(type)); return -1; } if (!(msgtemp = malloc(strlen(text)+32))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"Joining channel: \"%s\"\r\n",text); break; case message_type_userflags: if (!me) { eventlog(eventlog_level_error,"message_telnet_format","got NULL connection for %s",message_type_get_str(type)); return -1; } /* FIXME: should we show any of these? */ if (!(msgtemp = strdup(""))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } break; case message_type_whisperack: if (!me) { eventlog(eventlog_level_error,"message_telnet_format","got NULL connection for %s",message_type_get_str(type)); return -1; } if (!text) { eventlog(eventlog_level_error,"message_telnet_format","got NULL text for %s",message_type_get_str(type)); return -1; } { char const * tname; char const * newtext; if(!(tname = conn_get_chatcharname(me, dst))) return -1; if ((newtext = escape_chars(text,strlen(text)))) { if (!(msgtemp = malloc(strlen(tname)+8+strlen(newtext)+4))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"<to %s> %s\r\n",tname,newtext); free((void *)newtext); /* avoid warning */ } else { if (!(msgtemp = malloc(strlen(tname)+8+strlen(text)+4))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"<to %s> %s\r\n",tname,text); } conn_unget_chatcharname(me,tname); } break; case message_type_channelfull: /* FIXME */ if (!(msgtemp = strdup(""))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } break; case message_type_channeldoesnotexist: /* FIXME */ if (!(msgtemp = strdup(""))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } break; case message_type_channelrestricted: /* FIXME */ if (!(msgtemp = strdup(""))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } break; case message_type_info: if (!text) { eventlog(eventlog_level_error,"message_telnet_format","got NULL text for %s",message_type_get_str(type)); return -1; } { char const * newtext; if ((newtext = escape_chars(text,strlen(text)))) { if (!(msgtemp = malloc(strlen(newtext)+4))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"%s\r\n",newtext); free((void *)newtext); /* avoid warning */ } else { if (!(msgtemp = malloc(strlen(text)+4))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"%s\r\n",text); } } break; case message_type_error: if (!text) { eventlog(eventlog_level_error,"message_telnet_format","got NULL text for %s",message_type_get_str(type)); return -1; } { char const * newtext; if ((newtext = escape_chars(text,strlen(text)))) { if (!(msgtemp = malloc(8+strlen(newtext)+4))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"ERROR: %s\r\n",newtext); free((void *)newtext); /* avoid warning */ } else { if (!(msgtemp = malloc(8+strlen(text)+4))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"ERROR: %s\r\n",text); } } break; case message_type_emote: if (!me) { eventlog(eventlog_level_error,"message_telnet_format","got NULL connection for %s",message_type_get_str(type)); return -1; } if (!text) { eventlog(eventlog_level_error,"message_telnet_format","got NULL text for %s",message_type_get_str(type)); return -1; } if (dstflags&MF_X) return -1; /* player is ignored */ { char const * tname; char const * newtext; if(!(tname = conn_get_chatcharname(me, me))) /* FIXME: second should be dst but cache gets in the way */ return -1; if ((newtext = escape_chars(text,strlen(text)))) { if (!(msgtemp = malloc(strlen(tname)+4+strlen(newtext)+4))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"<%s %s>\r\n",tname,newtext); free((void *)newtext); /* avoid warning */ } else { if (!(msgtemp = malloc(strlen(tname)+4+strlen(text)+4))) { eventlog(eventlog_level_error,"message_telnet_format","could not allocate memory for msgtemp"); return -1; } sprintf(msgtemp,"<%s %s>\r\n",tname,text); } conn_unget_chatcharname(me,tname); } break; default: eventlog(eventlog_level_error,"message_telnet_format","got bad message type %d",(int)type); return -1; } { int retval; retval = packet_append_ntstring(packet,msgtemp); free(msgtemp); return retval; } }