// // QQSendMsg // QQSendMsg* qq_sendmsg_new(QQInfo *info, QQMsgType type, const gchar *to_uin) { QQSendMsg *msg = g_slice_new0(QQSendMsg); if(msg == NULL){ g_warning("OOM...(%s, %d)", __FILE__, __LINE__); return NULL; } msg -> contents = g_ptr_array_new(); if(msg -> contents == NULL){ g_warning("OOM...(%s, %d)", __FILE__, __LINE__); g_slice_free(QQSendMsg, msg); return NULL; } gchar buf[20]; g_snprintf(buf, 20, "%ld", ++(info -> msg_id)); msg->type = type; #define NEW_STR(x, y) msg -> x = g_string_new(y) NEW_STR(to_uin, to_uin); NEW_STR(face, info -> me -> face -> str); NEW_STR(msg_id, buf); NEW_STR(clientid, info -> clientid -> str); NEW_STR(psessionid, info -> psessionid -> str); #undef NEW_STR return msg; }
//*,{ // "type":"function", // "name":"setConfig(callback,[filename])", // "text":"读取或设置配置文件,配置文件是一个 Json 格式的文本文件,可以是 utf-8 获取 ansi 编码。", // "param":[ // { // "type":"function", // "name":"callback(cfg)", // "text":"setConfig 函数如果成功,会触发这个回调函数,cfg 是一个对象,它的属性就是配置内容,对这个对象的任何更改最后都会作为 Json 格式保存到配置文件。" // }, // { // "type":"string", // "name":"[filename]", // "text":"配置文件名,缺省是和脚本同路径同名的一个后缀为“.json”的文本文件,如果指定了文件名,则读取和保存对应的文件。" // } // ], // "return":{ // "type":"boolean", // "text":"如果成功打开了配置文件,函数返回 true,否则返回 undefined。" // } //}//* Handle<Value> setConfig(const Arguments& args){ HandleScope stack; while(true){ if(args.Length()<1) break; if(!args[0]->IsFunction()) break; cs::String file; if(args.Length()>1) GetString(args[1],file); cs::Config cfg(file); cs::Json* json = cfg.Lock(); if(!json) break; json->ToString(file,false); Handle<Object> glb = GetGlobal(); Handle<Object> JSON = glb->Get(NEW_STR(JSON))->ToObject(); Handle<Function> parse = Handle<Function>::Cast(JSON->Get(NEW_STR(parse))); Handle<Function> stringify = Handle<Function>::Cast(JSON->Get(NEW_STR(stringify))); Handle<Function> callback = Handle<Function>::Cast(args[0]); Handle<Value> argv[3]; argv[0] = NEW_WSTR(file.Handle()); Handle<Value> v = parse->Call(JSON,1,argv); if(v.IsEmpty()||!v->IsObject()) v = Object::New(); argv[0] = v; CallFunc(glb,callback,1,argv); v = stringify->Call(JSON,1,argv); GetString(v,file); json->Parse(file); return True(); } return Undefined(); }
/* * Init JNI fields, fetch the key stored by Android or generate a new one */ static void AndroidInit(vlc_keystore *p_keystore) { JNIEnv *p_env = GET_ENV(); if (p_env == NULL) return; if (InitJni(p_keystore, p_env) != VLC_SUCCESS) return; jobject jkeystore = NULL, jentry = NULL, jkey = NULL; jstring jstringAlias = NULL, jstringProvider = NULL; jstringAlias = NEW_STR("LibVLCAndroid"); if (CHECK_EXCEPTION()) goto end; jstringProvider = NEW_STR("AndroidKeyStore"); if (CHECK_EXCEPTION()) goto end; jkeystore = CALL_STATICOBJ(KeyStore, KeyStore.getInstance, jstringProvider); if (CHECK_EXCEPTION()) goto end; CALL_VOID(jkeystore, KeyStore.load, NULL); if (CHECK_EXCEPTION()) goto end; jentry = CALL_OBJ(jkeystore, KeyStore.getEntry, jstringAlias, NULL); if (CHECK_EXCEPTION()) goto end; if (jentry != NULL) { jkey = CALL_OBJ(jentry, KeyStore.SecretKeyEntry.getSecretKey); if (CHECK_EXCEPTION()) goto end; } else { jkey = GenerateKey(p_keystore, p_env, jstringAlias, jstringProvider); if (jkey == NULL) goto end; } s_jkey = NEW_GREF(jkey); end: if (jstringAlias != NULL) DEL_LREF(jstringAlias); if (jstringProvider != NULL) DEL_LREF(jstringProvider); if (jkeystore != NULL) DEL_LREF(jkeystore); if (jentry != NULL) DEL_LREF(jentry); if (jkey != NULL) DEL_LREF(jkey); }
/* * Init JNI fields that will be used to fetch the key and crypt/encrypt */ static int InitJni(vlc_keystore *p_keystore, JNIEnv *p_env) { jclass clazz = NULL; GET_CLASS("java/lang/Object"); GET_ID(GetMethodID, Object.toString, "toString", "()Ljava/lang/String;"); GET_CLASS("java/security/KeyStore"); GET_GLOBAL_CLASS(KeyStore); GET_ID(GetStaticMethodID, KeyStore.getInstance, "getInstance", "(Ljava/lang/String;)Ljava/security/KeyStore;"); GET_ID(GetMethodID, KeyStore.load, "load", "(Ljava/security/KeyStore$LoadStoreParameter;)V"); GET_ID(GetMethodID, KeyStore.getEntry, "getEntry", "(Ljava/lang/String;Ljava/security/KeyStore$ProtectionParameter;)" "Ljava/security/KeyStore$Entry;"); GET_CLASS("java/security/KeyStore$SecretKeyEntry"); GET_ID(GetMethodID, KeyStore.SecretKeyEntry.getSecretKey, "getSecretKey", "()Ljavax/crypto/SecretKey;"); GET_CLASS("javax/crypto/spec/IvParameterSpec"); GET_GLOBAL_CLASS(IvParameterSpec); GET_ID(GetMethodID, IvParameterSpec.ctor, "<init>", "([B)V"); GET_CLASS("javax/crypto/Cipher"); GET_GLOBAL_CLASS(Cipher); GET_ID(GetStaticMethodID, Cipher.getInstance, "getInstance", "(Ljava/lang/String;)Ljavax/crypto/Cipher;"); GET_ID(GetMethodID, Cipher.init, "init", "(ILjava/security/Key;Ljava/security/spec/AlgorithmParameterSpec;)V"); GET_ID(GetMethodID, Cipher.doFinal, "doFinal", "([B)[B"); GET_ID(GetMethodID, Cipher.getIV, "getIV", "()[B"); GET_CONST_INT(Cipher.ENCRYPT_MODE, "ENCRYPT_MODE"); GET_CONST_INT(Cipher.DECRYPT_MODE, "DECRYPT_MODE"); DEL_LREF(clazz); jstring VLC_CIPHER = NEW_STR("AES/CBC/PKCS7Padding"); if (CHECK_EXCEPTION()) return VLC_EGENERIC; fields.VLC_CIPHER = NEW_GREF(VLC_CIPHER); DEL_LREF(VLC_CIPHER); return VLC_SUCCESS; }
// // QQGroup // QQGroup* qq_group_new() { QQGroup *grp = g_slice_new0(QQGroup); grp -> members = g_ptr_array_new(); #define NEW_STR(x) grp -> x = g_string_new("") NEW_STR(name); NEW_STR(gid); NEW_STR(gnumber); NEW_STR(createtime); NEW_STR(code); NEW_STR(flag); NEW_STR(owner); NEW_STR(mark); NEW_STR(mask); NEW_STR(memo); NEW_STR(fingermemo); NEW_STR(option); NEW_STR(gclass); NEW_STR(face); NEW_STR(level); #undef NEW_STR return grp; }
// // QQBuddy // QQBuddy* qq_buddy_new() { QQBuddy *bd = g_slice_new0(QQBuddy); bd -> vip_info = -1; bd -> client_type = -1; #define NEW_STR(x) bd -> x = g_string_new("") NEW_STR(uin); NEW_STR(qqnumber); NEW_STR(status); NEW_STR(nick); NEW_STR(markname); NEW_STR(country); NEW_STR(city); NEW_STR(province); NEW_STR(gender); NEW_STR(face); NEW_STR(flag); NEW_STR(phone); NEW_STR(mobile); NEW_STR(email); NEW_STR(college); NEW_STR(occupation); NEW_STR(personal); NEW_STR(homepage); NEW_STR(lnick); #undef NEW_STR qq_buddy_set(bd, "status", "offline"); return bd; }
// // QQRecvMsg // QQRecvMsg* qq_recvmsg_new(QQInfo *info, QQMsgType type) { QQRecvMsg *msg = g_slice_new0(QQRecvMsg); if(msg == NULL){ g_warning("OOM...(%s, %d)", __FILE__, __LINE__); return NULL; } msg -> msg_type = type; #define NEW_STR(x, y) msg -> x = g_string_new(y) NEW_STR(msg_id, ""); NEW_STR(msg_id2, ""); NEW_STR(from_uin, ""); NEW_STR(to_uin, ""); NEW_STR(reply_ip, ""); NEW_STR(group_code, ""); NEW_STR(send_uin, ""); NEW_STR(time, ""); NEW_STR(raw_content, ""); NEW_STR(uin, ""); NEW_STR(status, "offline"); NEW_STR(client_type, ""); #undef NEW_STR msg -> contents = g_ptr_array_new(); return msg; }