Example #1
0
/*
 * show_binding:  Given an unsigned character 'X' in the meta map 'Y', this
 * function will display to the screen the status of that bindings in a 
 * human-readable way.
 */
static void 	show_binding (int meta, uc c)
{
	char	meta_str[8];

	*meta_str = 0;
	if (meta < 1 || meta > MAX_META)
		meta = 0;
	else
		sprintf(meta_str, "META%d-", meta);

	if (keys[meta] && KEY(meta, c))
	{
#ifdef GUI
		if(meta == MAX_META && c < MAX_MOUSE)
			say("%s is bound to %s %s", mouse_actions[c],
				key_names[(*keys[meta])[c]->key_index].name,
				SAFE(KEY(meta, c)->stuff));
		else if (KEY(meta, c)->key_index < 0)
#else
			if (KEY(meta, c)->key_index < 0)
#endif
			say("%s%s is bound to META%d_CHARACTER",
				meta_str, 
				display_key(c),
				-(KEY(meta, c)->key_index));
		else
			say("%s%s is bound to %s %s", 
				meta_str, 
				display_key(c),
				key_names[KEY(meta, c)->key_index].name, 
				SAFE(KEY(meta, c)->stuff));
	}
	else
		say("%s%s is bound to NOTHING", meta_str, display_key(c));
}
Example #2
0
int OpenCL::init() {
#ifdef __APPLE__
	dp_queue = gcl_create_dispatch_queue(CL_DEVICE_TYPE_GPU, NULL);
	if (dp_queue == NULL) {
		dp_queue = gcl_create_dispatch_queue(CL_DEVICE_TYPE_CPU, NULL);
	}
	device = gcl_get_device_id_with_dispatch_queue(dp_queue);
#else
	this->set_best_device();
#endif /* __APPLE__ */
	char device_name[256];
	char device_version[256];
	SAFE(clGetDeviceInfo(device, CL_DEVICE_NAME, 256, device_name, NULL));
	SAFE(clGetDeviceInfo(device, CL_DEVICE_VERSION, 256, device_version, NULL));

	std::cout << "Selected platform:\t" << device_version << std::endl;
	std::cout << "Selected device:\t" << device_name << std::endl;

#ifndef __APPLE__
	SAFE_REF(context = clCreateContext(0, 1, &device, NULL, NULL, &err));
	SAFE_REF(commands = clCreateCommandQueue(context, device, 0, &err));

	std::vector<std::string> source_paths;
	source_paths.push_back("../src/kernel/kernel.cl");
	SAFE(this->load_kernels(source_paths));
#endif /* not __APPLE__ */
	return CL_SUCCESS;
}
Example #3
0
int main(int argc, char **argv)
{
    if (argc < 3) {
        fprintf(stderr, "usage: %s infile outfile {o|m} [res_pic.png] [intermid_pic.png\n");
        return 2;
    }

    int err;
    int is_in_fmc  = (strstr(argv[1], ".mtx") != NULL);
    int is_out_fmc = (strstr(argv[2], ".mtx") != NULL);
    int type = (argv[3][0] == 'o') ? ALG_ORIG : ALG_MULT;

    TMatrix_DCSR _A,  *A  = &_A;
    TMatrix_DCSR _B,  *B  = &_B;
    TWGraph      _gr, *gr = &_gr;
    if (is_in_fmc) err = matrix_load_fmc(A, argv[1]);
    else err = matrix_load(A, argv[1]);
    if (err != ERROR_NO_ERROR)
        PRINT_ERROR_MESSAGE_AND_EXIT(err);

    int size = A->size;
    int *xadj, *adjncy;
    int *perm, *invp;

    if (!perm || !invp)
        PRINT_ERROR_MESSAGE_AND_EXIT(ERROR_MEMORY_ALLOCATION);

    switch (type) {
        case ALG_ORIG: do_orig(A, &xadj, &adjncy); break;
        case ALG_MULT: do_mult(A, &xadj, &adjncy); break;
    }

    TWGraph igr = { NULL, adjncy, xadj, NULL, size, xadj[size] };

    tnd_perm(&igr, &perm, &invp);

    SAFE(build_graph(gr, A));
    SAFE(graph_reorder(gr, perm, invp));
    SAFE(build_matrix(gr, B, 1));

    if (argc > 4) matrix_portrait(B, argv[4], 0, 0, NULL);
    if (is_out_fmc) matrix_save_fmc(B, argv[2]);
    else matrix_save(B, argv[2]);

    free(xadj);
    free(adjncy);
    if (argc > 5) {
        switch (type) {
            case ALG_ORIG: do_orig(B, &xadj, &adjncy); break;
            case ALG_MULT: do_mult(B, &xadj, &adjncy); break;
        }
        igr = (TWGraph){ NULL, adjncy, xadj, NULL, size, 0 };
        graph_portrait(&igr, argv[5]);
    }

    return 0;
}
Example #4
0
static void
update_location(GntFileSel *sel)
{
	char *old;
	const char *tmp;
	tmp = sel->suggest ? sel->suggest :
		(const char*)gnt_tree_get_selection_data(sel->dirsonly ? GNT_TREE(sel->dirs) : GNT_TREE(sel->files));
	old = g_strdup_printf("%s%s%s", SAFE(sel->current), SAFE(sel->current)[1] ? G_DIR_SEPARATOR_S : "", tmp ? tmp : "");
	gnt_entry_set_text(GNT_ENTRY(sel->location), old);
	g_free(old);
}
Example #5
0
void main_loop()
{
	int child_count = 0;
	int stat_pipe[2];
	int ret;
	int status;
	pid_t child;
	unsigned long usec_start, usec;
	unsigned long child_count_sig;

	usec_start = current_time_usec();
	do {
		SAFE(pipe(stat_pipe));

		child_count++;
		count_ope += NSCENAR;
		fflush(stdout);
		child = fork();
		if (child == 0) {
			close(stat_pipe[0]);
			do_child();
			SAFE(write(stat_pipe[1], &count_sig,
				sizeof(count_sig)));
			close(stat_pipe[1]);
			pthread_exit(0);
			UNRESOLVED(0, "Should not be reached");
			exit(0);
		}
		close(stat_pipe[1]);
		SAFE(read(stat_pipe[0], &child_count_sig, sizeof(count_sig)));
		close(stat_pipe[0]);
		count_sig += child_count_sig;

		ret = waitpid(child, &status, 0);
		if (ret != child)
			UNRESOLVED(errno, "Waitpid returned the wrong PID");

		if (!WIFEXITED(status)) {
			output("status: %d\n", status);
			FAILED("Child exited abnormally");
		}

		if (WEXITSTATUS(status) != 0) {
			output("exit status: %d\n", WEXITSTATUS(status));
			FAILED("An error occured in child");
		}

		usec = current_time_usec();
	} while ((usec - usec_start) < RUN_TIME_USEC);
	output("Test spawned %d child processes.\n", child_count);
	output("Test finished after %lu usec.\n", usec - usec_start);
}
Example #6
0
 int initialize(int ndims, const mkldnn_dims_t dims, mkldnn_data_type_t dt,
         mkldnn_format_tag_t tag, mkldnn_engine_t engine) {
     mkldnn_memory_desc_t xmd;
     DNN_SAFE(mkldnn_memory_desc_init_by_tag(&xmd, ndims, dims, dt, tag), CRIT);
     SAFE(initialize(xmd, engine), CRIT);
     return OK;
 }
Example #7
0
/*
 * save_bindings: This writes all the key bindings for ircII to the given
 * FILE pointer suitable for being /LOADed again in the future.
 */
void 	save_bindings (FILE *fp, int do_all)
{
	int	meta, j;
	int	charsize = charset_size();
	char	meta_str[10];

	*meta_str = 0;
	for (meta = 0; meta <= MAX_META; meta++)
	{
		if (meta != 0)
			sprintf(meta_str, "META%d-", meta);

		for (j = 0; j < charsize; j++)
		{
			if (keys[meta] && KEY(meta, j) && KEY(meta, j)->changed)
			{
				if (KEY(meta, j)->key_index < 0)
				    fprintf(fp, "BIND %s%s META%d\n", 
					meta_str, 
					display_key(j), 
					-(KEY(meta, j)->key_index));
				else
				    fprintf(fp, "BIND %s%s %s %s\n", 
					meta_str, 
					display_key(j), 
					key_names[KEY(meta, j)->key_index].name,
					SAFE(KEY(meta, j)->stuff));
			}
		}
	}
}
Example #8
0
 int initialize(int ndims, const mkldnn_dims_t dims, mkldnn_data_type_t dt,
         const mkldnn_dims_t strides, mkldnn_engine_t engine) {
     mkldnn_memory_desc_t xmd;
     DNN_SAFE(mkldnn_memory_desc_init_by_strides(
                 &xmd, ndims, dims, dt, strides), CRIT);
     SAFE(initialize(xmd, engine), CRIT);
     return OK;
 }
Example #9
0
int bench(int argc, char **argv, bool main_bench) {
    for (int arg = 0; arg < argc; ++arg) {
        if (!strncmp("--batch=", argv[arg], 8))
            SAFE(batch(argv[arg] + 8, bench), CRIT);
        else if (!strncmp("--cfg=", argv[arg], 6))
            cfg = str2cfg(argv[arg] + 6);
        else if (!strncmp("--match=", argv[arg], 8))
            pattern = argv[arg] + 8;
        else if (!strncmp("--mb=", argv[arg], 5))
            mb = atoi(argv[arg] + 5);
        else if (!strncmp("--dir=", argv[arg], 6))
            dir = str2dir(argv[arg] + 6);
        else if (!strncmp("--alg=", argv[arg], 6))
            alg = str2alg(argv[arg] + 6);
        else if (!strncmp("--attr=", argv[arg], 7))
            SAFE(str2attr(&attr, argv[arg] + 7), CRIT);
        else if (!strncmp("--skip-impl=", argv[arg], 12))
            skip_impl = argv[arg] + 12;
        else if (!strncmp("--allow-unimpl=", argv[arg], 15))
            allow_unimpl = str2bool(argv[arg] + 15);
        else if (!strncmp("--perf-template=", argv[arg], 16))
            perf_template = argv[arg] + 16;
        else if (!strcmp("--reset", argv[arg]))
            reset_parameters();
        else if (!strncmp("--mode=", argv[arg], 7))
            bench_mode = str2bench_mode(argv[arg] + 7);
        else if (!strncmp("-v", argv[arg], 2))
            verbose = atoi(argv[arg] + 2);
        else if (!strncmp("--verbose=", argv[arg], 10))
            verbose = atoi(argv[arg] + 10);
        else {
            desc_t c;
            bool is_deconv = 0;
            if (str2desc(&c, argv[arg], is_deconv) == FAIL) {
                fprintf(stderr, "driver: unknown option: `%s`, exiting...\n",
                        argv[arg]);
                exit(2);
            }
            check_correctness(&c);
        }
    }

    return OK;
}
plString plNetServerSessionInfo::AsString() const
{
    const char * spacer = kEmpty;

    plStringStream ss;

    ss << "[";

    if (HasServerType())
    {
        ss  << spacer
            << "T:"
            << plNetServerConstants::GetServerTypeStr(fServerType);
        spacer = kComma;
    }
    if (HasServerName())
    {
        ss  << spacer
            << "N:"
            << SAFE(fServerName.c_str());
        spacer = kComma;
    }
    if (HasServerGuid())
    {
        ss  << spacer
            << "G:"
            << fServerGuid.AsString();
        spacer = kComma;
    }
    if (HasServerAddr() || HasServerPort())
    {
        ss  << spacer
            << "A:["
            << SAFE(fServerAddr.c_str())
            << ":"
            << fServerPort
            << "]";
        spacer = kComma;
    }
    ss  << "]";

    return ss.GetString();
}
Example #11
0
void OpenCL::set_best_device() {
	cl_uint num_plats;
	SAFE(clGetPlatformIDs(0, NULL, &num_plats));

	cl_platform_id plat[num_plats];
	SAFE(clGetPlatformIDs(num_plats, plat, NULL));

	float max_ver;
	for (int i = 0; i < num_plats; i++) {
		cl_uint num_devices;
		SAFE(clGetDeviceIDs(plat[i], CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices));
		cl_device_id devices[num_devices];
		SAFE(clGetDeviceIDs(plat[i], CL_DEVICE_TYPE_ALL, num_devices, devices, NULL));

		size_t plat_info_length;
		SAFE(clGetPlatformInfo(plat[i], CL_PLATFORM_VERSION, 0, NULL, &plat_info_length));
		char plat_version[plat_info_length];
		SAFE(clGetPlatformInfo(plat[i], CL_PLATFORM_VERSION, plat_info_length, plat_version, NULL));

		std::string version(plat_version);
		std::cout << version << std::endl;
		float ver = atof(version.substr(7,3).c_str());
		if (ver > max_ver && num_devices > 0) {
			max_ver = ver;
			device = devices[0];
		} else {
			std::cout<<"No GPU found with OpenCL implementation."<<std::endl;
			exit(EXIT_FAILURE);
		}
	}
}
Example #12
0
static void
selection_changed(GntWidget *widget, gpointer old, gpointer current, gpointer null)
{
	PurplePlugin *plugin = current;
	char *text;
	GList *list = NULL, *iter = NULL;

	if (!plugin)
		return;

	/* If the selected plugin was unseen before, mark it as seen. But save the list
	 * only when the plugin list is closed. So if the user enables a plugin, and it
	 * crashes, it won't get marked as seen so the user can fix the bug and still
	 * quickly find the plugin in the list.
	 * I probably mean 'plugin developers' by 'users' here. */
	list = g_object_get_data(G_OBJECT(widget), "seen-list");
	if (list)
		iter = g_list_find_custom(list, plugin->path, (GCompareFunc)strcmp);
	if (!iter) {
		list = g_list_prepend(list, g_strdup(plugin->path));
		g_object_set_data(G_OBJECT(widget), "seen-list", list);
	}

	/* XXX: Use formatting and stuff */
	gnt_text_view_clear(GNT_TEXT_VIEW(plugins.aboot));
	text = g_strdup_printf(_("Name: %s\nVersion: %s\nDescription: %s\nAuthor: %s\nWebsite: %s\nFilename: %s\n"),
			SAFE(_(plugin->info->name)), SAFE(_(plugin->info->version)), SAFE(_(plugin->info->description)),
			SAFE(_(plugin->info->author)), SAFE(_(plugin->info->homepage)), SAFE(plugin->path));
	gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(plugins.aboot),
			text, GNT_TEXT_FLAG_NORMAL);
	gnt_text_view_scroll(GNT_TEXT_VIEW(plugins.aboot), 0);
	g_free(text);
	decide_conf_button(plugin);
}
Example #13
0
DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
	struct libtrace_udp *udp = (struct libtrace_udp*)packet;
	printf(" UDP:");
	if (SAFE(udp, source)) {
		struct servent *ent=getservbyport(udp->source,"udp");
		if(ent) {
			printf(" Source %i (%s)",htons(udp->source),ent->s_name);
		} else {
			printf(" Source %i",htons(udp->source));
		}
	}
	else {
		printf("\n");
		return;
	}
	if (SAFE(udp, dest)) {
		struct servent *ent=getservbyport(udp->dest,"udp");
		if(ent) {
			printf(" Dest %i (%s)",htons(udp->dest),ent->s_name);
		} else {
			printf(" Dest %i",htons(udp->dest));
		}
	}
	else {
		printf("\n");
		return;
	}
	printf("\n UDP:");
	DISPLAYS(udp, len," Len %u");
	DISPLAYS(udp, check," Checksum %u");
	printf("\n");
	if (htons(udp->source) < htons(udp->dest)) 
		decode_next(packet+sizeof(*udp),len-sizeof(*udp),"udp",htons(udp->source));
	else
		decode_next(packet+sizeof(*udp),len-sizeof(*udp),"udp",htons(udp->dest));
	return;
}
Example #14
0
static void
selection_changed(GntWidget *widget, gpointer old, gpointer current, gpointer null)
{
	PurplePlugin *plugin = current;
	PurplePluginInfo *info;
	char *text, *authors = NULL;
	const char * const *authorlist;
	GList *list = NULL, *iter = NULL;

	if (!plugin)
		return;

	info = purple_plugin_get_info(plugin);
	authorlist = purple_plugin_info_get_authors(info);

	if (authorlist)
		authors = g_strjoinv(", ", (gchar **)authorlist);

	/* If the selected plugin was unseen before, mark it as seen. But save the list
	 * only when the plugin list is closed. So if the user enables a plugin, and it
	 * crashes, it won't get marked as seen so the user can fix the bug and still
	 * quickly find the plugin in the list.
	 * I probably mean 'plugin developers' by 'users' here. */
	list = g_object_get_data(G_OBJECT(widget), "seen-list");
	if (list)
		iter = g_list_find_custom(list, purple_plugin_get_filename(plugin),
					(GCompareFunc)strcmp);
	if (!iter) {
		list = g_list_prepend(list, g_strdup(purple_plugin_get_filename(plugin)));
		g_object_set_data(G_OBJECT(widget), "seen-list", list);
	}

	/* XXX: Use formatting and stuff */
	gnt_text_view_clear(GNT_TEXT_VIEW(plugins.aboot));
	text = g_strdup_printf((g_strv_length((gchar **)authorlist) > 1 ?
			_("Name: %s\nVersion: %s\nDescription: %s\nAuthors: %s\nWebsite: %s\nFilename: %s\n") :
			_("Name: %s\nVersion: %s\nDescription: %s\nAuthor: %s\nWebsite: %s\nFilename: %s\n")),
			SAFE(_(purple_plugin_info_get_name(info))),
			SAFE(_(purple_plugin_info_get_version(info))),
			SAFE(_(purple_plugin_info_get_description(info))),
			SAFE(authors),
			SAFE(_(purple_plugin_info_get_website(info))),
			SAFE(purple_plugin_get_filename(plugin)));

	gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(plugins.aboot),
			text, GNT_TEXT_FLAG_NORMAL);
	gnt_text_view_scroll(GNT_TEXT_VIEW(plugins.aboot), 0);

	g_free(text);
	g_free(authors);

	decide_conf_button(plugin);
}
Example #15
0
void save_exceptions()
{
    dbFILE *f;
    int i;
    static time_t lastwarn = 0;

    if (!
        (f = open_db(s_OperServ, ExceptionDBName, "w", EXCEPTION_VERSION)))
        return;
    SAFE(write_int16(nexceptions, f));
    for (i = 0; i < nexceptions; i++) {
        SAFE(write_string(exceptions[i].mask, f));
        SAFE(write_int16(exceptions[i].limit, f));
        SAFE(write_buffer(exceptions[i].who, f));
        SAFE(write_string(exceptions[i].reason, f));
        SAFE(write_int32(exceptions[i].time, f));
        SAFE(write_int32(exceptions[i].expires, f));
    }
    close_db(f);
}
Example #16
0
void load_exceptions()
{
    dbFILE *f;
    int i;
    uint16 n;
    uint16 tmp16;
    uint32 tmp32;

    if (!
        (f = open_db(s_OperServ, ExceptionDBName, "r", EXCEPTION_VERSION)))
        return;
    switch (i = get_file_version(f)) {
    case 9:
    case 8:
    case 7:
        SAFE(read_int16(&n, f));
        nexceptions = n;
        exceptions = scalloc(sizeof(Exception) * nexceptions, 1);
        if (!nexceptions) {
            close_db(f);
            return;
        }
        for (i = 0; i < nexceptions; i++) {
            SAFE(read_string(&exceptions[i].mask, f));
            SAFE(read_int16(&tmp16, f));
            exceptions[i].limit = tmp16;
            SAFE(read_buffer(exceptions[i].who, f));
            SAFE(read_string(&exceptions[i].reason, f));
            SAFE(read_int32(&tmp32, f));
            exceptions[i].time = tmp32;
            SAFE(read_int32(&tmp32, f));
            exceptions[i].expires = tmp32;
        }
        break;

    default:
        fatal("Unsupported version (%d) on %s", i, ExceptionDBName);
    }                           /* switch (ver) */

    close_db(f);
}
Example #17
0
int bench(int argc, char **argv, bool main_bench) {
    for (int arg = 0; arg < argc; ++arg) {
        if (!strncmp("--batch=", argv[arg], 8))
            SAFE(batch(argv[arg] + 8, bench), CRIT);
        else if (!strncmp("--dir=", argv[arg], 6))
            dir = str2dir(argv[arg] + 6);
        else if (!strncmp("--dt=", argv[arg], 5))
            dt = str2dt(argv[arg] + 5);
        else if (!strncmp("--tag=", argv[arg], 6))
            tag = str2tag(argv[arg] + 6);
        else if (!strncmp("--axis=", argv[arg], 7))
            axis = atoi(argv[arg] + 7);
        else if (!strncmp("--group=", argv[arg], 8))
            group = atoi(argv[arg] + 8);
        else if (!strncmp("--match=", argv[arg], 8))
            pattern = argv[arg] + 8;
        else if (!strncmp("--mode=", argv[0], 7))
            bench_mode = str2bench_mode(argv[0] + 7);
        else if (!strcmp("--reset", argv[arg]))
            reset_parameters();
        else if (!strncmp("-v", argv[arg], 2))
            verbose = atoi(argv[arg] + 2);
        else if (!strncmp("--verbose=", argv[arg], 10))
            verbose = atoi(argv[arg] + 10);
        else {
            if (!strncmp("--", argv[arg], 2)) {
                fprintf(stderr, "driver: unknown option: `%s`, exiting...\n",
                        argv[arg]);
                exit(2);
            }
            dims = str2dims(argv[arg]);
            check_correctness();
        }
    }

    return OK;
}
Example #18
0
void save_ns_dbase(void)
{
    dbFILE *f;
    int i;
    NickInfo *ni;
    char **access;
    static time_t lastwarn = 0;

    if (!(f = open_db(s_NickServ, NickDBName, "w")))
	return;
    for (ni = firstnick(); ni; ni = nextnick()) {
	SAFE(write_int8(1, f));
	SAFE(write_buffer(ni->nick, f));
	SAFE(write_buffer(ni->pass, f));
	SAFE(write_string(ni->url, f));
	SAFE(write_string(ni->email, f));
	SAFE(write_string(ni->last_usermask, f));
	SAFE(write_string(ni->last_realname, f));
	SAFE(write_string(ni->last_quit, f));
	SAFE(write_int32(ni->time_registered, f));
	SAFE(write_int32(ni->last_seen, f));
	SAFE(write_int16(ni->status, f));
	if (ni->link) {
	    SAFE(write_string(ni->link->nick, f));
	    SAFE(write_int16(ni->linkcount, f));
	    SAFE(write_int16(ni->channelcount, f));
	} else {
	    SAFE(write_string(NULL, f));
	    SAFE(write_int16(ni->linkcount, f));
	    SAFE(write_int32(ni->flags, f));
	    SAFE(write_ptr(ni->suspendinfo, f));
	    if (ni->suspendinfo) {
		SAFE(write_buffer(ni->suspendinfo->who, f));
		SAFE(write_string(ni->suspendinfo->reason, f));
		SAFE(write_int32(ni->suspendinfo->suspended, f));
		SAFE(write_int32(ni->suspendinfo->expires, f));
	    }
	    SAFE(write_int16(ni->accesscount, f));
	    for (i=0, access=ni->access; i<ni->accesscount; i++, access++)
		SAFE(write_string(*access, f));
	    SAFE(write_int16(ni->channelcount, f));
	    SAFE(write_int16(ni->channelmax, f));
	    SAFE(write_int16(ni->language, f));
	}
    } /* for (ni) */
    {
	/* This is an UGLY HACK but it simplifies loading.  It will go away
	 * in the next file version */
	static char buf[256];
	SAFE(write_buffer(buf, f));
    }
    close_db(f);
    return;

  fail:
    restore_db(f);
    log_perror("Write error on %s", NickDBName);
    if (time(NULL) - lastwarn > WarningTimeout) {
	wallops(NULL, "Write error on %s: %s", NickDBName,
		strerror(errno));
	lastwarn = time(NULL);
    }
}
//============================================================================
plString plAgeInfoStruct::AsString() const
{
    const char * spacer = kEmpty;

    plStringStream ss;

    ss << "[";

    if (HasAgeFilename())
    {
        ss  << spacer
            << "FName:"
            << SAFE(GetAgeFilename());
        spacer = kComma;
    }
    if (HasAgeInstanceName())
    {
        ss  << spacer
            << "IName:"
            << SAFE(GetAgeInstanceName());
        spacer = kComma;
    }
    if (HasAgeInstanceGuid())
    {
        ss  << spacer
            << "Guid:"
            << fAgeInstanceGuid.AsString();
        spacer = kComma;
    }
    if (HasAgeUserDefinedName())
    {
        ss  << spacer
            << "UName:"
            << SAFE(GetAgeUserDefinedName());
        spacer = kComma;
    }
    if (HasAgeSequenceNumber())
    {
        ss  << spacer
            << "Seq:"
            << GetAgeSequenceNumber();
        spacer = kComma;
    }
    if (HasAgeDescription())
    {
        ss  << spacer
            << "Desc:"
            << SAFE(GetAgeDescription());
        spacer = kComma;
    }
    if (HasAgeLanguage())
    {
        ss  << spacer
            << "Lang:"
            << GetAgeLanguage();
        spacer = kComma;
    }
    ss  << "]";

    return ss.GetString();
}
Example #20
0
void perf_report(const prb_t *p, const res_t *r, const char *pstr) {
    const auto &t = r->timer;
    const int max_len = 400;
    int rem_len = max_len - 1;
    char buffer[max_len], *buf = buffer;

#   define DPRINT(...) do { \
        int l = snprintf(buf, rem_len, __VA_ARGS__); \
        buf += l; rem_len -= l; \
    } while(0)

    auto modifier2mode = [](char c) {
        if (c == '-') return benchdnn_timer_t::min;
        if (c == '0') return benchdnn_timer_t::avg;
        if (c == '+') return benchdnn_timer_t::max;
        return benchdnn_timer_t::min;
    };

    auto modifier2unit = [](char c) {
        if (c == 'K') return 1e3;
        if (c == 'M') return 1e6;
        if (c == 'G') return 1e9;
        return 1e0;
    };

    double ops = 2. * p->oc * p->mb * p->ic * p->ih * p->iw * p->id;

    const char *pt = perf_template;
    char c;

    while ((c = *pt++) != '\0') {
        if (c != '%') { *buf++ = c; rem_len--; continue; }

        c = *pt++;

        benchdnn_timer_t::mode_t mode = benchdnn_timer_t::min;
        double unit = 1e0;

        if (c == '-' || c == '0' || c == '+') {
            mode = modifier2mode(c);
            c = *pt++;
        }

        if (c == 'K' || c == 'M' || c == 'G') {
            unit = modifier2unit(c);
            c = *pt++;
        }

        if (c == 'd')
            DPRINT("%s", pstr);
        else if (c == 'D')
            DPRINT("" IFMT "," IFMT "," IFMT "," IFMT "," IFMT "," IFMT "",
                    p->mb, p->oc, p->ic, p->id, p->ih, p->iw);
        else if (c == 'n')
            DPRINT("%s", p->name);
        else if (c == 'z')
            DPRINT("%s", dir2str(p->dir));
        else if (c == 'q')
            DPRINT("%s", cfg2str(p->cfg));
        else if (c == 't')
            DPRINT("%g", t.ms(mode) / unit);
        else if (c == 'O')
            DPRINT("%g", ops / unit);
        else if (c == 'p')
            DPRINT("%g", ops / t.ms(mode) / unit * 1e3);
        else
            []() { SAFE(FAIL, CRIT); return 0; }();
    }

    *buf = '\0';
    assert(rem_len >= 0);

#   undef DPRINT
    print(0, "%s\n", buffer);
}
Example #21
0
void save_os_dbase(void)
{
    int i;
    dbFILE *f;
    static time_t lastwarn = 0;
    Akill *ak;
    SXLine *sx;

    if (!(f = open_db(s_OperServ, OperDBName, "w", OPER_VERSION)))
        return;
    SAFE(write_int32(maxusercnt, f));
    SAFE(write_int32(maxusertime, f));

    SAFE(write_int16(akills.count, f));
    for (i = 0; i < akills.count; i++) {
        ak = akills.list[i];

        SAFE(write_string(ak->user, f));
        SAFE(write_string(ak->host, f));
        SAFE(write_string(ak->by, f));
        SAFE(write_string(ak->reason, f));
        SAFE(write_int32(ak->seton, f));
        SAFE(write_int32(ak->expires, f));
    }

    SAFE(write_int16(sglines.count, f));
    for (i = 0; i < sglines.count; i++) {
        sx = sglines.list[i];

        SAFE(write_string(sx->mask, f));
        SAFE(write_string(sx->by, f));
        SAFE(write_string(sx->reason, f));
        SAFE(write_int32(sx->seton, f));
        SAFE(write_int32(sx->expires, f));
    }

    SAFE(write_int16(sqlines.count, f));
    for (i = 0; i < sqlines.count; i++) {
        sx = sqlines.list[i];

        SAFE(write_string(sx->mask, f));
        SAFE(write_string(sx->by, f));
        SAFE(write_string(sx->reason, f));
        SAFE(write_int32(sx->seton, f));
        SAFE(write_int32(sx->expires, f));
    }

    SAFE(write_int16(szlines.count, f));
    for (i = 0; i < szlines.count; i++) {
        sx = szlines.list[i];

        SAFE(write_string(sx->mask, f));
        SAFE(write_string(sx->by, f));
        SAFE(write_string(sx->reason, f));
        SAFE(write_int32(sx->seton, f));
        SAFE(write_int32(sx->expires, f));
    }

    close_db(f);

}
Example #22
0
void load_os_dbase(void)
{
    dbFILE *f;
    int16 i, ver;
    uint16 tmp16, n;
    uint32 tmp32;
    char *s;
    int failed = 0;

    if (!(f = open_db(s_OperServ, OperDBName, "r", OPER_VERSION)))
        return;

    ver = get_file_version(f);

    if (ver <= 9) {
        NickAlias *na;

        SAFE(read_int16(&n, f));
        for (i = 0; i < n && !failed; i++) {
            SAFE(read_string(&s, f));
            if (s) {
                na = findnick(s);
                if (na) {
                    na->nc->flags |= NI_SERVICES_ADMIN;
                    if (slist_indexof(&servadmins, na) == -1)
                        slist_add(&servadmins, na);
                }
                free(s);
            }
        }
        if (!failed)
            SAFE(read_int16(&n, f));
        for (i = 0; i < n && !failed; i++) {
            SAFE(read_string(&s, f));
            if (s) {
                na = findnick(s);
                if (na) {
                    na->nc->flags |= NI_SERVICES_OPER;
                    if (slist_indexof(&servopers, na) == -1)
                        slist_add(&servopers, na);
                }
                free(s);
            }
        }
    }

    if (ver >= 7) {
        uint32 tmp32;
        SAFE(read_int32(&maxusercnt, f));
        SAFE(read_int32(&tmp32, f));
        maxusertime = tmp32;
    }

    if (ver <= 10)
        load_old_akill();
    else {
        Akill *ak;

        read_int16(&tmp16, f);
        slist_setcapacity(&akills, tmp16);

        for (i = 0; i < akills.capacity; i++) {
            ak = scalloc(sizeof(Akill), 1);

            SAFE(read_string(&ak->user, f));
            SAFE(read_string(&ak->host, f));
            SAFE(read_string(&ak->by, f));
            SAFE(read_string(&ak->reason, f));
            SAFE(read_int32(&tmp32, f));
            ak->seton = tmp32;
            SAFE(read_int32(&tmp32, f));
            ak->expires = tmp32;

            slist_add(&akills, ak);
        }
    }

    if (ver >= 11) {
        SXLine *sx;

        read_int16(&tmp16, f);
        slist_setcapacity(&sglines, tmp16);

        for (i = 0; i < sglines.capacity; i++) {
            sx = scalloc(sizeof(SXLine), 1);

            SAFE(read_string(&sx->mask, f));
            SAFE(read_string(&sx->by, f));
            SAFE(read_string(&sx->reason, f));
            SAFE(read_int32(&tmp32, f));
            sx->seton = tmp32;
            SAFE(read_int32(&tmp32, f));
            sx->expires = tmp32;

            slist_add(&sglines, sx);
        }

        if (ver >= 13) {
            read_int16(&tmp16, f);
            slist_setcapacity(&sqlines, tmp16);

            for (i = 0; i < sqlines.capacity; i++) {
                sx = scalloc(sizeof(SXLine), 1);

                SAFE(read_string(&sx->mask, f));
                SAFE(read_string(&sx->by, f));
                SAFE(read_string(&sx->reason, f));
                SAFE(read_int32(&tmp32, f));
                sx->seton = tmp32;
                SAFE(read_int32(&tmp32, f));
                sx->expires = tmp32;

                slist_add(&sqlines, sx);
            }
        }

        read_int16(&tmp16, f);
        slist_setcapacity(&szlines, tmp16);

        for (i = 0; i < szlines.capacity; i++) {
            sx = scalloc(sizeof(SXLine), 1);

            SAFE(read_string(&sx->mask, f));
            SAFE(read_string(&sx->by, f));
            SAFE(read_string(&sx->reason, f));
            SAFE(read_int32(&tmp32, f));
            sx->seton = tmp32;
            SAFE(read_int32(&tmp32, f));
            sx->expires = tmp32;

            slist_add(&szlines, sx);
        }
    }

    close_db(f);

}
Example #23
0
static void load_old_akill(void)
{
    dbFILE *f;
    int i, j;
    uint16 tmp16;
    uint32 tmp32;
    char buf[NICKMAX], mask2[BUFSIZE], *mask, *s;
    Akill *ak, *entry;

    if (!
        (f =
         open_db("AKILL", AutokillDBName ? AutokillDBName : "akill.db",
                 "r", 9)))
        return;

    get_file_version(f);

    read_int16(&tmp16, f);
    slist_setcapacity(&akills, tmp16);

    for (j = 0; j < akills.capacity; j++) {
        ak = scalloc(sizeof(Akill), 1);

        SAFE(read_string(&mask, f));
        s = strchr(mask, '@');
        *s = 0;
        s++;
        ak->user = sstrdup(mask);
        ak->host = sstrdup(s);
        SAFE(read_string(&ak->reason, f));
        SAFE(read_buffer(buf, f));
        if (!*buf)
            ak->by = sstrdup("<unknown>");
        else
            ak->by = sstrdup(buf);
        SAFE(read_int32(&tmp32, f));
        ak->seton = tmp32 ? tmp32 : time(NULL);
        SAFE(read_int32(&tmp32, f));
        ak->expires = tmp32;

        /* Sanity checks *sigh* */

        /* No nicknames allowed! */
        if (strchr(ak->user, '!')) {
            xanadu_cmd_remove_akill(ak->user, ak->host);
            free(ak);
            continue;
        }

        snprintf(mask2, sizeof(mask2), "%s@%s", ak->user, ak->host);

        /* Is the mask already in the AKILL list? */
        if (slist_indexof(&akills, mask2) != -1) {
            free(ak);
            continue;
        }

        /* Checks whether there is an AKILL that already covers
         * the one we want to add, and whether there are AKILLs
         * that would be covered by this one. Expiry time
         * does *also* matter.
         */

        if (akills.count > 0) {

            for (i = akills.count - 1; i >= 0; i--) {

                char amask[BUFSIZE];

                entry = akills.list[i];

                if (!entry)
                    continue;

                snprintf(amask, sizeof(amask), "%s@%s", entry->user,
                         entry->host);

                if (match_wild_nocase(amask, mask2)
                    && (entry->expires >= ak->expires
                        || entry->expires == 0)) {
                    xanadu_cmd_remove_akill(ak->user, ak->host);
                    free(ak);
                    ak = NULL;
                    break;
                }

                if (match_wild_nocase(mask2, amask)
                    && (entry->expires <= ak->expires || ak->expires == 0))
                    slist_delete(&akills, i);
            }

        }

        if (ak)
            slist_add(&akills, ak);
    }

    close_db(f);
}
Example #24
0
static void load_old_ns_dbase(dbFILE *f, int ver)
{
    struct nickinfo_ {
	NickInfo *next, *prev;
	char nick[NICKMAX];
	char pass[PASSMAX];
	char *last_usermask;
	char *last_realname;
	time_t time_registered;
	time_t last_seen;
	long accesscount;
	char **access;
	long flags;
	time_t id_stamp;
	unsigned short memomax;
	unsigned short channelcount;
	char *url;
	char *email;
    } old_nickinfo;

    int i, j, c;
    NickInfo *ni, **last, *prev;
    int failed = 0;

    for (i = 33; i < 256 && !failed; i++) {
	last = &nicklists[i];
	prev = NULL;
	while ((c = getc_db(f)) != 0) {
	    if (c != 1)
		fatal("Invalid format in %s", NickDBName);
	    SAFE(read_variable(old_nickinfo, f));
	    if (debug >= 3)
		log("debug: load_old_ns_dbase read nick %s", old_nickinfo.nick);
	    ni = scalloc(sizeof(NickInfo), 1);
	    *last = ni;
	    last = &ni->next;
	    ni->prev = prev;
	    prev = ni;
	    strscpy(ni->nick, old_nickinfo.nick, NICKMAX);
	    strscpy(ni->pass, old_nickinfo.pass, PASSMAX);
	    ni->time_registered = old_nickinfo.time_registered;
	    ni->last_seen = old_nickinfo.last_seen;
	    ni->accesscount = old_nickinfo.accesscount;
	    ni->flags = old_nickinfo.flags;
	    ni->channelcount = 0;
	    ni->channelmax = CSMaxReg;
	    ni->language = DEF_LANGUAGE;
	    /* ENCRYPTEDPW and VERBOTEN moved from ni->flags to ni->status */
	    if (ni->flags & 4)
		ni->status |= NS_VERBOTEN;
	    if (ni->flags & 8)
		ni->status |= NS_ENCRYPTEDPW;
	    ni->flags &= ~0xE000000C;
#ifdef USE_ENCRYPTION
	    if (!(ni->status & (NS_ENCRYPTEDPW | NS_VERBOTEN))) {
		if (debug)
		    log("debug: %s: encrypting password for `%s' on load",
				s_NickServ, ni->nick);
		if (encrypt_in_place(ni->pass, PASSMAX) < 0)
		    fatal("%s: Can't encrypt `%s' nickname password!",
				s_NickServ, ni->nick);
		ni->status |= NS_ENCRYPTEDPW;
	    }
#else
	    if (ni->status & NS_ENCRYPTEDPW) {
		/* Bail: it makes no sense to continue with encrypted
		 * passwords, since we won't be able to verify them */
		fatal("%s: load database: password for %s encrypted "
		          "but encryption disabled, aborting",
		          s_NickServ, ni->nick);
	    }
#endif
	    if (old_nickinfo.url)
		SAFE(read_string(&ni->url, f));
	    if (old_nickinfo.email)
		SAFE(read_string(&ni->email, f));
	    SAFE(read_string(&ni->last_usermask, f));
	    if (!ni->last_usermask)
		ni->last_usermask = sstrdup("@");
	    SAFE(read_string(&ni->last_realname, f));
	    if (!ni->last_realname)
		ni->last_realname = sstrdup("");
	    if (ni->accesscount) {
		char **access, *s;
		if (ni->accesscount > NSAccessMax)
		    ni->accesscount = NSAccessMax;
		access = smalloc(sizeof(char *) * ni->accesscount);
		ni->access = access;
		for (j = 0; j < ni->accesscount; j++, access++)
		    SAFE(read_string(access, f));
		while (j < old_nickinfo.accesscount) {
		    SAFE(read_string(&s, f));
		    if (s)
			free(s);
		    j++;
		}
	    }
	    ni->id_stamp = 0;
	    if (ver < 3) {
		ni->flags |= NI_MEMO_SIGNON | NI_MEMO_RECEIVE;
	    } else if (ver == 3) {
		if (!(ni->flags & (NI_MEMO_SIGNON | NI_MEMO_RECEIVE)))
		    ni->flags |= NI_MEMO_SIGNON | NI_MEMO_RECEIVE;
	    }
	} /* while (getc_db(f) != 0) */
	*last = NULL;
    } /* for (i) */
}
Example #25
0
unsigned long current_time_usec()
{
	struct timeval now;
	SAFE(gettimeofday(&now, NULL));
	return now.tv_sec * 1000000 + now.tv_usec;
}
Example #26
0
 /* FIXME: ugly RT assert... need better mkldnn memory handling */
 dnn_mem_t &operator=(const dnn_mem_t &rhs)
 { []() { SAFE(FAIL, CRIT); return 0; }(); return *this; }
Example #27
0
static void *
pidgin_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed,
					   const char **subjects, const char **froms,
					   const char **tos, const char **urls)
{
	GtkWidget *dialog = NULL;
	char *notification;
	PurpleAccount *account;
	PidginNotifyMailData *data = NULL, *data2;
	gboolean new_data;

	/* Don't bother updating if there aren't new emails and we don't have any displayed currently */
	if (count == 0 && mail_dialog == NULL)
		return NULL;

	account = purple_connection_get_account(gc);
	dialog = pidgin_get_mail_dialog();  /* This creates mail_dialog if necessary */

	mail_dialog->total_count += count;
	if (detailed) {
		while (count--) {
			char *to_text = NULL;
			char *from_text = NULL;
			char *subject_text = NULL;
			char *tmp;
			gboolean first = TRUE;

			if (tos != NULL) {
				tmp = g_markup_escape_text(*tos, -1);
				to_text = g_strdup_printf("<b>%s</b>: %s\n", _("Account"), tmp);
				g_free(tmp);
				first = FALSE;
				tos++;
			}
			if (froms != NULL) {
				tmp = g_markup_escape_text(*froms, -1);
				from_text = g_strdup_printf("%s<b>%s</b>: %s\n", first ? "<br>" : "", _("Sender"), tmp);
				g_free(tmp);
				first = FALSE;
				froms++;
			}
			if (subjects != NULL) {
				tmp = g_markup_escape_text(*subjects, -1);
				subject_text = g_strdup_printf("%s<b>%s</b>: %s", first ? "<br>" : "", _("Subject"), tmp);
				g_free(tmp);
				first = FALSE;
				subjects++;
			}
#define SAFE(x) ((x) ? (x) : "")
			notification = g_strdup_printf("%s%s%s", SAFE(to_text), SAFE(from_text), SAFE(subject_text));
#undef SAFE
			g_free(to_text);
			g_free(from_text);
			g_free(subject_text);

			/* If we don't keep track of this, will leak "data" for each of the notifications except the last */
			data2 = pidgin_notify_add_mail(mail_dialog->treemodel, account, notification, urls ? *urls : NULL, 0, FALSE, &new_data);
			if (new_data) {
				if (data)
					data->purple_has_handle = FALSE;
				data = data2;
			}
			g_free(notification);

			if (urls != NULL)
				urls++;
		}
	} else {
		if (count > 0) {
			notification = g_strdup_printf(ngettext("%s has %d new message.",
							   "%s has %d new messages.",
							   (int)count),
							   *tos, (int)count);
			data2 = pidgin_notify_add_mail(mail_dialog->treemodel, account, notification, urls ? *urls : NULL, count, FALSE, &new_data);
			if (new_data) {
				if (data)
					data->purple_has_handle = FALSE;
				data = data2;
			}
			g_free(notification);
		} else {
			GtkTreeIter iter;

			/* Clear out all mails for the account */
			pidgin_notify_add_mail(mail_dialog->treemodel, account, NULL, NULL, 0, TRUE, NULL);

			if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(mail_dialog->treemodel), &iter)) {
				/* There is no API to clear the headline specifically */
				/* This will trigger reset_mail_dialog() */
				pidgin_blist_set_headline(NULL, NULL, NULL, NULL, NULL);
				return NULL;
			}
		}
	}

	if (!GTK_WIDGET_VISIBLE(dialog)) {
		GdkPixbuf *pixbuf = gtk_widget_render_icon(dialog, PIDGIN_STOCK_DIALOG_MAIL,
							   gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL), NULL);
		char *label_text = g_strdup_printf(ngettext("<b>%d new email.</b>",
							    "<b>%d new emails.</b>",
							    mail_dialog->total_count), mail_dialog->total_count);
		mail_dialog->in_use = TRUE;     /* So that _set_headline doesn't accidentally
										   remove the notifications when replacing an
										   old notification. */
		pidgin_blist_set_headline(label_text,
					    pixbuf, G_CALLBACK(gtk_widget_show_all), dialog,
					    (GDestroyNotify)reset_mail_dialog);
		mail_dialog->in_use = FALSE;
		g_free(label_text);
		if (pixbuf)
			g_object_unref(pixbuf);
	} else if (!GTK_WIDGET_HAS_FOCUS(dialog))
		pidgin_set_urgent(GTK_WINDOW(dialog), TRUE);

	return data;
}
Example #28
0
void load_ns_dbase(void)
{
    dbFILE *f;
    int ver, i, j, c;
    NickAlias *na, **nalast, *naprev;
    NickCore *nc, **nclast, *ncprev;
    int failed = 0;
    uint16 tmp16;
    uint32 tmp32;
    char *s, *pass;

    if (!(f = open_db(s_NickServ, NickDBName, NICK_VERSION)))
        return;

    ver = get_file_version(f);

    if (ver <= 11) {
//        close_db(f);
//        load_old_ns_dbase();
        printf("old database gtfo !\n");
        return;
    }

    /* First we load nick cores */
    for (i = 0; i < 1024 && !failed; i++) {
    
    
        nclast = &nclists[i];
        ncprev = NULL;

        while ((c = getc_db(f)) == 1) {
            if (c != 1)
                printf("Invalid format in %s", NickDBName);

            nc = scalloc(1, sizeof(NickCore));
            *nclast = nc;
            nclast = &nc->next;
            nc->prev = ncprev;
            ncprev = nc;

            slist_init(&nc->aliases);

            SAFE(read_string(&nc->display, f));
            printf("%s", nc->display);
            if (ver < 14) {
                SAFE(read_string(&pass, f));
                if (pass) {
                    memset(nc->pass, 0, PASSMAX);
                    memcpy(nc->pass, pass, strlen(pass));
                } else
                    memset(nc->pass, 0, PASSMAX);
            } else
                SAFE(read_buffer(nc->pass, f));
//            printf(" %s", nc->pass);
            SAFE(read_string(&nc->email, f));
//            printf(" %s", nc->email);
            SAFE(read_string(&nc->greet, f));
//            printf(" %s", nc->greet);
            SAFE(read_int32(&nc->icq, f));
//            printf(" %d", nc->icq);
            SAFE(read_string(&nc->url, f));
//	    printf(" %s\n", nc->url);
            SAFE(read_int32(&nc->flags, f));
            if (!NSAllowKillImmed)
                nc->flags &= ~NI_KILL_IMMED;
            SAFE(read_int16(&nc->language, f));

            /* Add services opers and admins to the appropriate list, but
               only if the database version is more than 10. */
/*            if (nc->flags & NI_SERVICES_ADMIN)
                slist_add(&servadmins, nc);
            if (nc->flags & NI_SERVICES_OPER)
                slist_add(&servopers, nc); */ 
                
// OSEF des axx Sop et Sadmin !

            SAFE(read_int16(&nc->accesscount, f));
            if (nc->accesscount) {
                char **access;
                access = scalloc(sizeof(char *) * nc->accesscount, 1);
                nc->access = access;
                for (j = 0; j < nc->accesscount; j++, access++)
                    SAFE(read_string(access, f));
            }

            SAFE(read_int16(&tmp16, f));
            nc->memos.memocount = (int16) tmp16;
            SAFE(read_int16(&tmp16, f));
            nc->memos.memomax = (int16) tmp16;
            if (nc->memos.memocount) {
                Memo *memos;
                memos = scalloc(sizeof(Memo) * nc->memos.memocount, 1);
                nc->memos.memos = memos;
                for (j = 0; j < nc->memos.memocount; j++, memos++) {
                    SAFE(read_int32(&memos->number, f));
                    SAFE(read_int16(&memos->flags, f));
                    SAFE(read_int32(&tmp32, f));
                    memos->time = tmp32;
                    SAFE(read_buffer(memos->sender, f));
                    SAFE(read_string(&memos->text, f));
                    memos->moduleData = NULL;
                }
            }

            SAFE(read_int16(&nc->channelcount, f));
            SAFE(read_int16(&tmp16, f));
            nc->channelmax = CSMaxReg;

            if (ver < 13) {
                /* Used to be dead authentication system */
                SAFE(read_int16(&tmp16, f));
                SAFE(read_int32(&tmp32, f));
                SAFE(read_int16(&tmp16, f));
                SAFE(read_string(&s, f));
            }

        }                       /* while (getc_db(f) != 0) */
        *nclast = NULL;
    }                           /* for (i) */

    for (i = 0; i < 1024 && !failed; i++) {
        nalast = &nalists[i];
        naprev = NULL;
        while ((c = getc_db(f)) == 1) {
            if (c != 1)
                printf("Invalid format in %s", NickDBName);

            na = scalloc(1, sizeof(NickAlias));

            SAFE(read_string(&na->nick, f));

            SAFE(read_string(&na->last_usermask, f));
            SAFE(read_string(&na->last_realname, f));
            SAFE(read_string(&na->last_quit, f));

            SAFE(read_int32(&tmp32, f));
            na->time_registered = tmp32;
            SAFE(read_int32(&tmp32, f));
            na->last_seen = tmp32;
            SAFE(read_int16(&na->status, f));
            na->status &= ~NS_TEMPORARY;

            SAFE(read_string(&s, f));
            na->nc = findcore(s);
            free(s);

            slist_add(&na->nc->aliases, na);

            if (!(na->status & NS_VERBOTEN)) {
                if (!na->last_usermask)
                    na->last_usermask = sstrdup("");
                if (!na->last_realname)
                    na->last_realname = sstrdup("");
            }

            na->nc->flags &= ~NI_SERVICES_ROOT;

            *nalast = na;
            nalast = &na->next;
            na->prev = naprev;
            naprev = na;

        }                       /* while (getc_db(f) != 0) */

        *nalast = NULL;
    }                           /* for (i) */

//    close_db(f);
// nevermind wasting memory

    for (i = 0; i < 1024; i++) {
        NickAlias *next;

        for (na = nalists[i]; na; na = next) {
            next = na->next;
            /* We check for coreless nicks (although it should never happen) */
            if (!na->nc) {
                printf("%s: while loading database: %s has no core! We delete it (here just ignore it !).", s_NickServ, na->nick);
//                delnick(na);
                continue;
            }

            /* Add the Services root flag if needed. */
/*            for (j = 0; j < RootNumber; j++)
                if (!stricmp(ServicesRoots[j], na->nick))
                    na->nc->flags |= NI_SERVICES_ROOT; */
// OSEF de savoir si Paul Pierre ou Jacques est Services Root !                    
                    
        }
    }
}
Example #29
0
NickInfo *load_nick(dbFILE *f, int ver)
{
    NickInfo *ni;
    int32 tmp32;
    int i;

    ni = scalloc(sizeof(NickInfo), 1);
    SAFE(read_buffer(ni->nick, f));
    SAFE(read_buffer(ni->pass, f));
    SAFE(read_string(&ni->url, f));
    SAFE(read_string(&ni->email, f));
    SAFE(read_string(&ni->last_usermask, f));
    if (!ni->last_usermask)
	ni->last_usermask = sstrdup("@");
    SAFE(read_string(&ni->last_realname, f));
    if (!ni->last_realname)
	ni->last_realname = sstrdup("");
    SAFE(read_string(&ni->last_quit, f));
    SAFE(read_int32(&tmp32, f));
    ni->time_registered = tmp32;
    SAFE(read_int32(&tmp32, f));
    ni->last_seen = tmp32;
    SAFE(read_int16(&ni->status, f));
    ni->status &= ~NS_TEMPORARY;
#ifdef USE_ENCRYPTION
    if (!(ni->status & (NS_ENCRYPTEDPW | NS_VERBOTEN))) {
	if (debug)
	    log("debug: %s: encrypting password for `%s' on load",
		s_NickServ, ni->nick);
	if (encrypt_in_place(ni->pass, PASSMAX) < 0)
	    fatal("%s: Can't encrypt `%s' nickname password!",
		  s_NickServ, ni->nick);
	ni->status |= NS_ENCRYPTEDPW;
    }
#else
    if (ni->status & NS_ENCRYPTEDPW) {
	/* Bail: it makes no sense to continue with encrypted
	 * passwords, since we won't be able to verify them */
	fatal("%s: load database: password for %s encrypted "
	      "but encryption disabled, aborting",
	      s_NickServ, ni->nick);
    }
#endif
    /* Store the _name_ of the link target in ni->link for now;
     * we'll resolve it after we've loaded all the nicks */
    SAFE(read_string((char **)&ni->link, f));
    /* We actually recalculate link and channel counts later, but leave
     * them in for now to avoid changing the data file format */
    SAFE(read_int16(&ni->linkcount, f));
    if (ni->link) {
	SAFE(read_int16(&ni->channelcount, f));
	/* No other information saved for linked nicks, since
	 * they get it all from their link target */
	ni->channelmax = CSMaxReg;
	ni->language = DEF_LANGUAGE;
    } else {
	SAFE(read_int32(&ni->flags, f));
	if (!NSAllowKillImmed)
	    ni->flags &= ~NI_KILL_IMMED;
	if (ver >= 9) {
	    read_ptr((void **)&ni->suspendinfo, f);
	} else if (ver == 8 && (ni->flags & 0x10000000)) {
	    /* In version 8, 0x10000000 was NI_SUSPENDED */
	    ni->suspendinfo = (SuspendInfo *)1;
	}
	if (ni->suspendinfo) {
	    SuspendInfo *si = smalloc(sizeof(*si));
	    SAFE(read_buffer(si->who, f));
	    SAFE(read_string(&si->reason, f));
	    SAFE(read_int32(&tmp32, f));
	    si->suspended = tmp32;
	    SAFE(read_int32(&tmp32, f));
	    si->expires = tmp32;
	    ni->suspendinfo = si;
	}
	SAFE(read_int16(&ni->accesscount, f));
	if (ni->accesscount) {
	    char **access;
	    access = smalloc(sizeof(char *) * ni->accesscount);
	    ni->access = access;
	    for (i = 0; i < ni->accesscount; i++, access++)
		SAFE(read_string(access, f));
	}
	SAFE(read_int16(&ni->channelcount, f));
	SAFE(read_int16(&ni->channelmax, f));
	if (ver <= 8) {
	    /* Fields not initialized or updated properly */
	    /* These will be updated by load_cs_dbase() */
	    ni->channelcount = 0;
	    if (ver == 5)
		ni->channelmax = CSMaxReg;
	}
	SAFE(read_int16(&ni->language, f));
	if (!langtexts[ni->language])
	    ni->language = DEF_LANGUAGE;
    }
    /* Link and channel counts are recalculated later */
    ni->linkcount = 0;
    ni->channelcount = 0;
    ni->historycount = 0;
    return ni;
}
Example #30
0
 dnn_mem_t(const dnn_mem_t &rhs)
 { []() { SAFE(FAIL, CRIT); return 0; }(); }