void qq_account_insert_index_node(qq_account* ac, const LwqqBuddy* b, const LwqqGroup* g) { #if QQ_USE_FAST_INDEX if (!ac || (!b && !g)) return; index_node* node = s_malloc0(sizeof(*node)); int type = b ? NODE_IS_BUDDY : NODE_IS_GROUP; node->type = type; if (type == NODE_IS_BUDDY) { node->node = b; const LwqqBuddy* buddy = b; g_hash_table_insert(ac->fast_index.uin_index, s_strdup(buddy->uin), node); if (buddy->qqnumber) g_hash_table_insert(ac->fast_index.qqnum_index, s_strdup(buddy->qqnumber), node); } else { node->node = g; const LwqqGroup* group = g; g_hash_table_insert(ac->fast_index.uin_index, s_strdup(group->gid), node); if (group->account) g_hash_table_insert(ac->fast_index.qqnum_index, s_strdup(group->account), node); } #endif }
struct device_t * device_new (struct udev_device *dev) { struct device_t *device; const char *dev_type; const char *dev_idtype; device = malloc(sizeof(struct device_t)); device->udev = dev; device->devnode = s_strdup(udev_device_get_devnode(dev)); device->filesystem = s_strdup(udev_device_get_property_value(dev, "ID_FS_TYPE")); dev_type = udev_device_get_devtype(dev); dev_idtype = udev_device_get_property_value(dev, "ID_TYPE"); device->type = DEVICE_UNK; if (!device->filesystem) { device_destroy(device); return NULL; } if (!strcmp(dev_type, "partition")|| !strcmp(dev_type, "disk") || !strcmp(dev_idtype, "floppy")) { device->type = DEVICE_VOLUME; } else if (!strcmp(dev_idtype, "cd")) { device->type = DEVICE_CD; } if (device->type == DEVICE_UNK) { device_destroy(device); return NULL; } device->has_media = device_has_media(device); device->fstab_entry = fstab_search(g_fstab, device); device->mountpoint = NULL; if (device->has_media) { if (device->fstab_entry) { device->mountpoint = s_strdup(device->fstab_entry->path); } else { device->mountpoint = device_create_mountpoint(device); } } device->mounted = device_is_mounted(device->devnode); if (!device_register(device)) { device_destroy(device); return NULL; } return device; }
int mkpath(const char *s, mode_t mode){ char *q, *r = NULL, *path = NULL, *up = NULL; int rv; rv = -1; if (strcmp(s, ".") == 0 || strcmp(s, "/") == 0) return (0); path=s_strdup(s); q = s_strdup(s); r = s_dirname(q); up = s_strdup(r); if ((mkpath(up, mode) == -1) && (errno != EEXIST)) goto out; if ((mkdir(path, mode) == -1) && (errno != EEXIST)) rv = -1; else rv = 0; out: if (up != NULL) free(up); free(q); free(path); free(r); return (rv); }
int fstab_parse (struct fstab_t *fstab) { FILE *f; struct mntent *mntent; struct fstab_node_t *node; struct fstab_node_t *last; f = setmntent(FSTAB_PATH, "r"); if (!f) return 0; while ((mntent = getmntent(f))) { node = malloc(sizeof(struct fstab_node_t)); node->next = NULL; node->node = s_strdup(mntent->mnt_fsname); node->path = s_strdup(mntent->mnt_dir); node->type = s_strdup(mntent->mnt_type); node->opts = s_strdup(mntent->mnt_opts); if (!fstab->head) { fstab->head = node; } else { last = fstab->head; while (last->next) { last = last->next; } last->next = node; } } endmntent(f); return 1; }
char *s_basename(char *path) { char *tmpstr; char *rdir; char *retstr; tmpstr = s_strdup(path); rdir = basename(tmpstr); retstr = s_strdup(rdir); free(tmpstr); return retstr; }
void insert(int intarget) { size_t nmemb; PATTERN_ *p; char **p2; str2pattern (); nmemb = n_patterns; p = lfind (buffer2, patterns, &nmemb, sizeof (PATTERN_), lfindpat); if (! p) { if (n_patterns == max_patterns) { max_patterns += 32; patterns = (PATTERN_ *) s_realloc (patterns, max_patterns * sizeof (PATTERN_)); } patterns [n_patterns].s = s_strdup (buffer2); patterns [n_patterns].n_forms = 0; patterns [n_patterns].max_forms = 0; patterns [n_patterns].i = 0; patterns [n_patterns].o = 0; patterns [n_patterns].used = 0; patterns [n_patterns].rejected = 0; patterns [n_patterns].forms = NULL; p = &(patterns [n_patterns]); n_patterns++; } if (intarget) p->i++; else p->o++; if (p->i + p->o >= minvar) p->used = 1; p2 = NULL; if (p->n_forms > 0) { nmemb = p->n_forms; p2 = lfind (buffer, p->forms, &nmemb, sizeof (char *), searchcmp); } if (! p2) { if (p->n_forms == p->max_forms) { p->max_forms += 32; p->forms = (char **) s_realloc (p->forms, p->max_forms * sizeof (char *)); } p->forms[p->n_forms] = s_strdup (buffer); p->n_forms++; } }
char *s_dirname(char *path) { char *tmpstr; char *rdir; char *retstr; if (NULL == path) return NULL; tmpstr = s_strdup(path); rdir = dirname(tmpstr); retstr = s_strdup(rdir); free(tmpstr); return retstr; }
/* * Append the string pointed to by "str" to the string pointed to by "orig" * adding the delimeter "delim" in between. * * Return a pointer to the new string or NULL, if we were passed a bad string. */ static char * append_str(char *orig, char *str, char *delim) { char *newstr; int len; if ((str == NULL) || (delim == NULL)) return (NULL); if ((orig == NULL) || (*orig == NULL)) { /* * Return a pointer to a copy of the path so a caller can * always rely upon being able to free() a returned pointer. */ return (s_strdup(str)); } len = strlen(orig) + strlen(str) + strlen(delim) + 1; if ((newstr = malloc(len)) == NULL) { bam_error(NO_MEM, len); bam_exit(1); } (void) snprintf(newstr, len, "%s%s%s", orig, delim, str); return (newstr); }
/* | Adds a logging category | | Returns true if OK. */ static bool add_logcat( const char *name, int priority ) { struct logcat *lc; if( !strcmp( "all", name ) ) { settings.log_level = 99; return true; } if( !strcmp( "scarce", name ) ) { settings.log_level = LOG_WARNING; return true; } // categories must start with a capital letter. if( name[ 0 ] < 'A' || name[ 0 ] > 'Z' ) { return false; } if( !logcats[ name[ 0 ]- 'A' ] ) { // an empty capital letter lc = logcats[name[0]-'A'] = s_calloc(2, sizeof(struct logcat)); } else { // length of letter list int ll = 0; // counts list length for( lc = logcats[name[0]-'A']; lc->name; lc++ ) { ll++; } // enlarges list logcats[ name[ 0 ] - 'A'] = s_realloc( logcats[ name[ 0 ]-'A' ], ( ll + 2 ) * sizeof( struct logcat ) ); // goes to the list end for( lc = logcats[ name[ 0 ] - 'A']; lc->name; lc++ ) { if( !strcmp( name, lc->name ) ) { // already there return true; } } } lc->name = s_strdup( name ); lc->priority = priority; // terminates the list lc[ 1 ].name = NULL; return true; }
S_API SObject *SObjectSetString(const char *s, s_erc *error) { SString *self; S_CLR_ERR(error); if (s == NULL) { S_CTX_ERR(error, S_ARGERROR, "SObjectSetString", "Argument \"s\" is NULL"); return NULL; } self = S_NEW(SString, error); if (S_CHK_ERR(error, S_FAILURE, "SObjectSetString", "Failed to create new SString object")) return NULL; self->s = s_strdup(s, error); if (S_CHK_ERR(error, S_CONTERR, "SObjectSetString", "Failed to copy string")) { S_DELETE(self, "SObjectSetString", error); return NULL; } return S_OBJECT(self); }
/** * Insert a string after given string list element. Return reference * to inserted string element. */ S_API const s_str_list_element *s_str_list_insert_after(s_str_list_element *self, const char *string, s_erc *error) { const s_str_list_element *el; char *new_string; S_CLR_ERR(error); if ((self == NULL) || (string == NULL)) return NULL; new_string = s_strdup(string, error); if (S_CHK_ERR(error, S_CONTERR, "s_str_list_insert_after", "Call to \"s_strdup\" failed")) return NULL; el = s_list_insert_after(self, new_string, error); if (S_CHK_ERR(error, S_CONTERR, "s_str_list_insert_after", "Call to \"s_list_insert_after\" failed")) { S_FREE(new_string); return NULL; } return el; }
/** * Replace the string list element's string. The replaced string is * freed. */ S_API void s_str_list_element_replace(s_str_list_element *self, const char *string, s_erc *error) { char *replaced; char *new_string; S_CLR_ERR(error); if ((self == NULL) || (string == NULL)) return; new_string = s_strdup(string, error); if (S_CHK_ERR(error, S_CONTERR, "s_str_list_element_replace", "Call to \"s_strdup\" failed")) return; replaced = s_list_element_replace(self, new_string, error); if (S_CHK_ERR(error, S_CONTERR, "s_str_list_element_replace", "Call to \"s_list_element_replace\" failed")) { S_FREE(new_string); return; } S_FREE(replaced); }
/* * Replace the substring "old_str" in a path with the substring "new_str" * * Return a pointer to the modified string. */ static char * modify_path(char *path, char *old_str, char *new_str) { char *newpath; char *pc; int len; /* * Return a pointer to a copy of the path so a caller can always rely * upon being able to free() a returned pointer. */ if ((pc = strstr(path, old_str)) == NULL) return (s_strdup(path)); /* * Allocate space for duplicate of path with name changes and * NULL terminating byte */ len = strlen(path) - strlen(old_str) + strlen(new_str) + 1; if ((newpath = malloc(len)) == NULL) { bam_error(NO_MEM, len); bam_exit(1); } (void) strlcpy(newpath, path, (pc - path) + 1); pc += strlen(old_str); (void) strcat(newpath, new_str); (void) strcat(newpath, pc); return (newpath); }
qq_account* qq_account_new(PurpleAccount* account) { qq_account* ac = g_malloc0(sizeof(qq_account)); ac->account = account; ac->magic = QQ_MAGIC; ac->flag = 0; //this is auto increment sized array . so don't worry about it. const char* username = purple_account_get_username(account); const char* password = purple_account_get_password(account); ac->qq = lwqq_client_new(username,password); ac->js = lwqq_js_init(); ac->sys_log = purple_log_new(PURPLE_LOG_SYSTEM, "system", account, NULL, time(NULL), NULL); ac->font.family = s_strdup("宋体"); ac->font.size = 12; ac->font.style = 0; //lwqq_async_set(ac->qq,1); #if QQ_USE_FAST_INDEX ac->qq->find_buddy_by_uin = find_buddy_by_uin; ac->qq->find_buddy_by_qqnumber = find_buddy_by_qqnumber; ac->fast_index.uin_index = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free); ac->fast_index.qqnum_index = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,NULL); #endif ac->qq->dispatch = qq_dispatch; return ac; }
static void upload_file_init(PurpleXfer* xfer) { void** data = xfer->data; qq_account* ac = data[0]; LwqqClient* lc = ac->qq; LwqqMsgOffFile* file = s_malloc0(sizeof(*file)); file->from = s_strdup(lc->myself->uin); file->to = s_strdup(purple_xfer_get_remote_user(xfer)); file->name = s_strdup(purple_xfer_get_local_filename(xfer)); xfer->start_time = time(NULL); data[1] = file; data[2] = xfer; //lwqq_async_add_event_listener( background_upload_file(lc,file,file_trans_on_progress,xfer); //send_file,data); }
void check_add_file(char *filename) { const char *bn; if (filename == NULL || *filename == '\0') return; if (access(filename, R_OK) < 0) { warn("could not open file: %s", filename); return; } if (fileidx == filecnt) { filecnt *= 2; files = (fileinfo_t*) s_realloc(files, filecnt * sizeof(fileinfo_t)); } if (*filename != '/') { files[fileidx].path = absolute_path(filename); if (files[fileidx].path == NULL) { warn("could not get absolute path of file: %s\n", filename); return; } } files[fileidx].loaded = false; files[fileidx].name = s_strdup(filename); if (*filename == '/') files[fileidx].path = files[fileidx].name; if ((bn = strrchr(files[fileidx].name , '/')) != NULL && bn[1] != '\0') files[fileidx].base = ++bn; else files[fileidx].base = files[fileidx].name; fileidx++; }
struct str_list_* str_list_prepend(struct str_list_* list,const char* str) { struct str_list_* ret = s_malloc0(sizeof(struct str_list_)); ret->str = s_strdup(str); ret->next = list; return ret; }
char * device_create_mountpoint (struct device_t *device) { char tmp[256]; char *c; strcpy(tmp, "/media/"); if (udev_device_get_property_value(device->udev, "ID_FS_LABEL") != NULL) strcat(tmp, udev_device_get_property_value(device->udev, "ID_FS_LABEL")); else if (udev_device_get_property_value(device->udev, "ID_FS_UUID") != NULL) strcat(tmp, udev_device_get_property_value(device->udev, "ID_FS_UUID")); else if (udev_device_get_property_value(device->udev, "ID_SERIAL") != NULL) strcat(tmp, udev_device_get_property_value(device->udev, "ID_SERIAL")); /* Replace the whitespaces */ for (c = (char*)&tmp; *c; c++) { if (*c == ' ') *c = '_'; } /* It can't fail as every disc should have at least the serial */ return s_strdup(tmp); }
static ssize_t strdata_from_buf(uint8_t *buf, size_t nbytes, size_t n, ...) { const char **cur; uint16_t magic; ssize_t avail; size_t slen; va_list ap; #define BUF_WALK(bytes) \ do { \ buf += bytes; \ avail -= bytes; \ \ if (avail < 0) \ return -1; \ } while (0) #define CONSUME_BYTES(nb) \ ({ \ uint8_t *obuf = buf; \ BUF_WALK(nb); \ obuf; \ }) #define CONSUME_TYPE(type) \ *((type *) ({ \ CONSUME_BYTES(sizeof(type)); \ })) avail = nbytes; va_start(ap, n); while (n--) { cur = va_arg(ap, const char **); *cur = NULL; slen = CONSUME_TYPE(size_t); *cur = (char *) CONSUME_BYTES(slen); magic = CONSUME_TYPE(uint16_t); if (magic != IPC_MAGIC) { *cur = NULL; return -1; } /* null-terminate the string (this is a little hack) */ *(buf - 2) = '\0'; *cur = s_strdup(*cur); } va_end(ap); #undef CONSUME_TYPE #undef CONSUME_BYTES #undef BUF_WALK return nbytes - avail; }
struct ir_ncode *defineCode(char *key, char *val, struct ir_ncode *code) { memset(code, 0, sizeof(*code)); code->name = s_strdup(key); code->code = s_strtocode(val); LOGPRINTF(3, " %-20s 0x%016llX", code->name, code->code); return (code); }
void openread (char const *s) { filename = s_strdup (s); lineno = 0; fp = fopen (filename, "r"); if (! fp) errit ("Opening file \"%s\": %s", filename, strerror (errno)); }
static int check_need_verify_back(LwqqHttpRequest* req) { int err = LWQQ_EC_OK; LwqqClient* lc = req->lc; if(req->failcode != LWQQ_CALLBACK_VALID){ err = LWQQ_EC_NETWORK_ERROR; lc->args->login_ec = err; vp_do_repeat(lc->events->login_complete, NULL); goto done; } lwqq__jump_if_http_fail(req, err); /** * * The http message body has two format: * * ptui_checkVC('1','9ed32e3f644d968809e8cbeaaf2cce42de62dfee12c14b74','\x00\x00\x00\x00\x04\x7e\x73\xb2'); * ptui_checkVC('0','!IJG', '\x00\x00\x00\x00\x54\xb3\x3c\x53'); * The former means we need verify code image and the second * parameter is vc_type. * The later means we don't need the verify code image. The second * parameter is the verify code. The vc_type is in the header * "Set-Cookie". */ int need_vf; char param2[256]; char param3[256]; sscanf(req->response,"ptui_checkVC('%d','%[^']','%[^']');",&need_vf,param2,param3); lc->vc = s_malloc0(sizeof(*lc->vc)); lc->vc->uin = s_strdup(param3); lc->vc->str = s_strdup(param2); lc->vc->lc = lc; if (need_vf == 0) { /* We need get the ptvfsession from the header "Set-Cookie" */ lwqq_log(LOG_NOTICE, "Verify code: %s\n", lc->vc->str); } else if (need_vf == 1) { err = LWQQ_EC_LOGIN_NEED_VC; lwqq_log(LOG_NOTICE, "We need verify code image: %s\n", lc->vc->str); } done: lwqq_http_request_free(req); return err; }
VAR * create_var(const char * var_name) { VAR * v; v = (VAR*)calloc(sizeof(VAR),1); v->name = s_strdup(var_name); v->value = 0.0; list_push(&list_var,v); return v; }
char *string_toupper(const char *str) { char *newstr, *p; p = newstr = s_strdup(str); while(*p) { *p=toupper(*p); p++; } return newstr; }
struct ir_ncode *defineCode(char *key, char *val, struct ir_ncode *code) { code->name=s_strdup(key); code->code=s_strtocode(val); # ifdef LONG_IR_CODE LOGPRINTF(3," %-20s 0x%016llX",code->name, code->code); # else LOGPRINTF(3," %-20s 0x%016lX",code->name, code->code); # endif return(code); }
GROUP_ *newgroup () { GROUP_ *tmp; tmp = (GROUP_ *) s_malloc (sizeof (GROUP_)); tmp->members = s_strdup (members); tmp->n = 0; tmp->value = 0.0; tmp->left = tmp->right = NULL; return tmp; }
/** * I hacked the javascript file named comm.js, which received from tencent * server, and find that f**k tencent has changed encryption algorithm * for password in webqq3 . The new algorithm is below(descripted with javascript): * var M=C.p.value; // M is the qq password * var I=hexchar2bin(md5(M)); // Make a md5 digest * var H=md5(I+pt.uin); // Make md5 with I and uin(see below) * var G=md5(H+C.verifycode.value.toUpperCase()); * * @param pwd User's password * @param vc Verify Code. e.g. "!M6C" * @param uin A string like "\x00\x00\x00\x00\x54\xb3\x3c\x53", NB: it * must contain 8 hexadecimal number, in this example, it equaled * to "0x0,0x0,0x0,0x0,0x54,0xb3,0x3c,0x53" * * @return Encoded password on success, else NULL on failed */ static char *lwqq_enc_pwd(const char *pwd, const char *vc, const char *uin) { int i; int uin_byte_length; char buf[128] = {0}; unsigned char sig[32]; char _uin[9] = {0}; if (!pwd || !vc || !uin) { lwqq_log(LOG_ERROR, "Null parameterment\n"); return NULL; } /* Calculate the length of uin (it must be 8?) */ uin_byte_length = strlen(uin) / 4; /** * Ok, parse uin from string format. * "\x00\x00\x00\x00\x54\xb3\x3c\x53" -> {0,0,0,0,54,b3,3c,53} */ for (i = 0; i < uin_byte_length ; i++) { char u[5] = {0}; char tmp; strncpy(u, uin + i * 4 + 2, 2); errno = 0; tmp = strtol(u, NULL, 16); if (errno) { return NULL; } _uin[i] = tmp; } /* Equal to "var I=hexchar2bin(md5(M));" */ md5_buffer(pwd,strlen(pwd),sig); memcpy(buf,sig,sizeof(sig)); /* Equal to "var H=md5(I+pt.uin);" */ memcpy(buf + 16, _uin, uin_byte_length); md5_buffer(buf, 16 + uin_byte_length, sig); md5_sig_to_string(sig,buf,sizeof(buf)); /* Equal to var G=md5(H+C.verifycode.value.toUpperCase()); */ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s", vc); upcase_string(buf, strlen(buf)); md5_buffer(buf, strlen(buf), sig); md5_sig_to_string(sig,buf,sizeof(buf)); upcase_string(buf, strlen(buf)); /* OK, seems like every is OK */ return s_strdup(buf); }
void printhash(char *msg, unsigned char *bhash) { char *ascii_hash = NULL; int n; char *p1, *p2; for (n = 0; n < config->hashlen ; n++) { p1 = as_sprintf("%02X", bhash[n]); if (n == 0) { ascii_hash = s_strdup(p1); } else { p2 = s_strdup(ascii_hash); free(ascii_hash); ascii_hash = as_sprintf("%s%s", p2, p1); free(p2); } free(p1); } printf("%s : %s\n", msg, ascii_hash); free(ascii_hash); }
/* * Set "token" to be the the string starting from the pointer "str" delimited * by any character in the string "delim" or the end of the string, but IGNORE * any characters between single or double quotes. * * Return a pointer to the next non-whitespace character after the delimiter * or NULL if we hit the end of the string. Also return NULL upon failure to * find any characters from the delimeter string or upon failure to allocate * memory for the new token string. */ static char * get_token(char **token, char *str, char *delim) { char *dp; char *start = str; unsigned len; *token = NULL; if ((str == NULL) || (*str == NULL)) return (NULL); do { if ((*str == '\'') || (*str == '"')) { char quote = *str++; while ((*str != NULL) && (*str != quote)) str++; /* no matching quote found in string */ if (*str++ == NULL) return (NULL); } /* look for a character from the delimiter string */ for (dp = delim; ((*dp != NULL) && (*dp != *str)); dp++) ; if (*dp != NULL) { len = str - start + 1; /* found a delimiter, so create a token string */ if ((*token = malloc(len)) == NULL) { bam_error(NO_MEM, len); bam_exit(1); } (void) strlcpy(*token, start, len); while (isspace((int)*++str)) ; return (str); } } while (*str++ != NULL); /* if we hit the end of the string, the token is the whole string */ *token = s_strdup(start); return (NULL); }
static int get_login_sig_back(LwqqHttpRequest* req) { LwqqErrorCode err = LWQQ_EC_OK; LwqqClient* lc = req->lc; lwqq__jump_if_http_fail(req, err); if(!req->response){err = LWQQ_EC_ERROR;goto done;} char* beg = strstr(req->response,"var g_login_sig="); char login_sig[256]; sscanf(beg,"var g_login_sig=encodeURIComponent(\"%[^\"]\")",login_sig); lwqq_override(lc->login_sig, s_strdup(login_sig)); done: lwqq_http_request_free(req); return err; }