/* Concatenate a string representing the state of a client in an human * readable format, into the sds string 's'. */ sds catClientInfoString(sds s, client *client) { char flags[16], events[3], *p; int emask; p = flags; if (client->flags & CLIENT_CLOSE_AFTER_REPLY) *p++ = 'c'; if (client->flags & CLIENT_CLOSE_ASAP) *p++ = 'A'; if (p == flags) *p++ = 'N'; *p++ = '\0'; emask = client->fd == -1 ? 0 : aeGetFileEvents(server.el,client->fd); p = events; if (emask & AE_READABLE) *p++ = 'r'; if (emask & AE_WRITABLE) *p++ = 'w'; *p = '\0'; return sdscatfmt(s, "id=%U fd=%i name=%s age=%I idle=%I flags=%s qbuf=%U qbuf-free=%U obl=%U cmd=%s", (unsigned long long) client->id, client->fd, client->name ? (char*)client->name : "", (long long)(server.unixtime - client->ctime), (long long)(server.unixtime - client->lastinteraction), flags, (unsigned long long) sdslen(client->querybuf), (unsigned long long) sdsavail(client->querybuf), (unsigned long long) client->bufpos, client->lastcmd ? client->lastcmd->name : "NULL"); }
/* Format a command according to the Redis protocol using an sds string and * sdscatfmt for the processing of arguments. This function takes the * number of arguments, an array with arguments and an array with their * lengths. If the latter is set to NULL, strlen will be used to compute the * argument lengths. */ int redisFormatSdsCommandArgv(sds *target, int argc, const char **argv, const size_t *argvlen) { sds cmd; unsigned long long totlen; int j; size_t len; /* Abort on a NULL target */ if (target == NULL) return -1; /* Calculate our total size */ totlen = 1+countDigits(argc)+2; for (j = 0; j < argc; j++) { len = argvlen ? argvlen[j] : strlen(argv[j]); totlen += bulklen(len); } /* Use an SDS string for command construction */ cmd = sdsempty(); if (cmd == NULL) return -1; /* We already know how much storage we need */ cmd = sdsMakeRoomFor(cmd, totlen); if (cmd == NULL) return -1; /* Construct command */ cmd = sdscatfmt(cmd, "*%i\r\n", argc); for (j=0; j < argc; j++) { len = argvlen ? argvlen[j] : strlen(argv[j]); cmd = sdscatfmt(cmd, "$%T\r\n", len); cmd = sdscatlen(cmd, argv[j], len); cmd = sdscatlen(cmd, "\r\n", sizeof("\r\n")-1); } assert(sdslen(cmd)==totlen); *target = cmd; return totlen; }
int master_init(vr_conf *conf) { rstatus_t status; uint32_t j; sds *host, listen_str; vr_listen **vlisten; int threads_num; int filelimit; master.cbsul = NULL; pthread_mutex_init(&master.cbsullock, NULL); conf_server_get(CONFIG_SOPN_THREADS,&threads_num); filelimit = threads_num*2+CONFIG_MIN_RESERVED_FDS; vr_eventloop_init(&master.vel,filelimit); master.vel.thread.fun_run = master_thread_run; darray_init(&master.listens,darray_n(&cserver->binds),sizeof(vr_listen*)); for (j = 0; j < darray_n(&cserver->binds); j ++) { host = darray_get(&cserver->binds,j); listen_str = sdsdup(*host); listen_str = sdscatfmt(listen_str, ":%i", cserver->port); vlisten = darray_push(&master.listens); *vlisten = vr_listen_create(listen_str); if (*vlisten == NULL) { darray_pop(&master.listens); log_error("Create listen %s failed", listen_str); sdsfree(listen_str); return VR_ERROR; } sdsfree(listen_str); } for (j = 0; j < darray_n(&master.listens); j ++) { vlisten = darray_get(&master.listens, j); status = vr_listen_begin(*vlisten); if (status != VR_OK) { log_error("Begin listen to %s failed", (*vlisten)->name); return VR_ERROR; } } master.cbsul = dlistCreate(); if (master.cbsul == NULL) { log_error("Create list failed: out of memory"); return VR_ENOMEM; } setup_master(); return VR_OK; }
json_value *caryll_gpos_mark_to_ligature_to_json(otl_subtable *st) { subtable_gpos_mark_to_ligature *subtable = &(st->gpos_mark_to_ligature); json_value *_subtable = json_object_new(3); json_value *_marks = json_object_new(subtable->marks->numGlyphs); json_value *_bases = json_object_new(subtable->bases->numGlyphs); for (uint16_t j = 0; j < subtable->marks->numGlyphs; j++) { json_value *_mark = json_object_new(3); sds markClassName = sdscatfmt(sdsempty(), "ac_%i", subtable->markArray->records[j].markClass); json_object_push(_mark, "class", json_string_new_length((uint32_t)sdslen(markClassName), markClassName)); sdsfree(markClassName); json_object_push(_mark, "x", json_integer_new(subtable->markArray->records[j].anchor.x)); json_object_push(_mark, "y", json_integer_new(subtable->markArray->records[j].anchor.y)); json_object_push(_marks, subtable->marks->glyphs[j].name, preserialize(_mark)); } for (uint16_t j = 0; j < subtable->bases->numGlyphs; j++) { mark_to_ligature_base *base = subtable->ligArray[j]; json_value *_base = json_array_new(base->componentCount); for (uint16_t k = 0; k < base->componentCount; k++) { json_value *_bk = json_object_new(subtable->classCount); for (uint16_t m = 0; m < subtable->classCount; m++) { if (base->anchors[k][m].present) { json_value *_anchor = json_object_new(2); json_object_push(_anchor, "x", json_integer_new(base->anchors[k][m].x)); json_object_push(_anchor, "y", json_integer_new(base->anchors[k][m].y)); sds markClassName = sdscatfmt(sdsempty(), "ac_%i", m); json_object_push_length(_bk, (uint32_t)sdslen(markClassName), markClassName, _anchor); sdsfree(markClassName); } } json_array_push(_base, _bk); } json_object_push(_bases, subtable->bases->glyphs[j].name, preserialize(_base)); } json_object_push(_subtable, "classCount", json_integer_new(subtable->classCount)); json_object_push(_subtable, "marks", _marks); json_object_push(_subtable, "bases", _bases); return _subtable; }
/* * see list of pictures availiable--file dictated in "go" script */ void preview(UR_OBJECT user) { #if !!0 static const char usage[] = "Usage: preview [<picture>]\n"; #endif sds filename; char line[100]; FILE *fp; DIR *dirp; struct dirent *dp; int cnt, total; if (word_count < 2) { /* open the directory file up */ dirp = opendir(PICTFILES); if (!dirp) { write_user(user, "No list of the picture files is availiable.\n"); return; } *line = '\0'; cnt = total = 0; /* go through directory and list files */ for (dp = readdir(dirp); dp; dp = readdir(dirp)) { if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) { continue; } if (!total++) { write_user(user, "+----------------------------------------------------------------------------+\n"); write_user(user, "| ~OL~FCPictures available to view~RS |\n"); write_user(user, "+----------------------------------------------------------------------------+\n"); } sprintf(text, "%-12.12s ", dp->d_name); strcat(line, text); if (++cnt == 5) { write_user(user, align_string(0, 78, 1, "|", " %s", line)); *line = '\0'; cnt = 0; } } closedir(dirp); if (total) { if (cnt) { write_user(user, align_string(0, 78, 1, "|", " %s", line)); } write_user(user, "+----------------------------------------------------------------------------+\n"); write_user(user, align_string(0, 78, 1, "|", " There are %d picture%s ", total, PLTEXT_S(total))); write_user(user, "+----------------------------------------------------------------------------+\n\n"); } else { write_user(user, "There are no pictures available to be viewed.\n"); } return; } if (strpbrk(word[1], "./")) { write_user(user, "Sorry, there is no picture with that name.\n"); return; } filename = sdscatfmt(sdsempty(), "%s/%s", PICTFILES, word[1]); fp = fopen(filename, "r"); if (!fp) { write_user(user, "Sorry, there is no picture with that name.\n"); return; } fclose(fp); write_user(user, "You ~OL~FGpreview the following picture...\n\n"); switch (more(user, user->socket, filename)) { case 0: break; case 1: user->misc_op = 2; break; } sdsfree(filename); }