[bme-develop] Profile information
Status: Planning
Brought to you by:
sirmik
From: Sir M. <obe...@ho...> - 2004-08-13 10:05:40
|
Hi guys, I am doing some work on getting the user's profile information from the server(parsing it)....problem is, it's getting a bit of mess and somewhat duplicated code....not entirely so I can't find a way to do it nicely, maybe you have some ideas for me...the code looks like this: if (strstr(mime,"text/x-msmsgsprofile") !=NULL) { //profile message Profile userProfile; int32 loginStart = msgBody.FindFirst("LoginTime"); if (loginStart != B_ERROR) { loginStart += 9; int32 loginEnd = msgBody.FindFirst("\r\n",loginStart); BString loginTime; msgBody.CopyInto(loginTime,loginStart,loginEnd-loginStart); userProfile.loginTime = atoi(loginTime.String()); } int32 emailEnabledStart = msgBody.FindFirst("EmailEnabled"); if (emailEnabledStart != B_ERROR) { emailEnabledStart += 12; int32 emailEnabledEnd = msgBody.FindFirst("\r\n",emailEnabledStart); BString emailEnabled; msgBody.CopyInto(emailEnabled,emailEnabledStart,emailEnabledEnd-emailEnabledStart); userProfile.emailEnabled = atoi(emailEnabled.String());//bool, check if this works } int32 memberIdHighStart = msgBody.FindFirst("MemberIdHigh"); if (memberIdHighStart != B_ERROR) { memberIdHighStart += 12; int32 memberIdHighEnd = msgBody.FindFirst("\r\n",memberIdHighStart); BString memberIdHigh; msgBody.CopyInto(memberIdHigh,memberIdHighStart,memberIdHighEnd-memberIdHighStart); userProfile.memberIdHigh = atoi(memberIdHigh.String()); } int32 memberIdLowStart = msgBody.FindFirst("MemberIdLow"); if (memberIdLowStart != B_ERROR) { memberIdLowStart += 11; int32 memberIdLowEnd = msgBody.FindFirst("\r\n",memberIdLowStart); BString memberIdLow; msgBody.CopyInto(memberIdLow,memberIdLowStart,memberIdLowEnd-memberIdLowStart); userProfile.memberIdLow = atoi(memberIdLow.String()); } int32 lang_preferenceStart = msgBody.FindFirst("lang_preference"); if (lang_preferenceStart != B_ERROR) { lang_preferenceStart += 15; int32 lang_preferenceEnd = msgBody.FindFirst("\r\n",lang_preferenceStart); BString lang_preference; msgBody.CopyInto(lang_preference,lang_preferenceStart,lang_preferenceEnd-lang_preferenceStart); userProfile.langPreference = atoi(lang_preference.String()); } int32 preferredEmailStart = msgBody.FindFirst("preferredEmail"); if (preferredEmailStart != B_ERROR) { preferredEmailStart += 14; int32 preferredEmailEnd = msgBody.FindFirst("\r\n",preferredEmailStart); msgBody.CopyInto(userProfile.preferredEmail,preferredEmailStart,preferredEmailEnd-preferredEmailStart); } int32 countryStart = msgBody.FindFirst("country"); if (countryStart != B_ERROR) { countryStart += 7; int32 countryEnd = msgBody.FindFirst("\r\n",countryStart); BString country; msgBody.CopyInto(country,countryStart,countryEnd-countryStart); userProfile.country = atoi(country.String()); } int32 postalCodeStart = msgBody.FindFirst("PostalCode"); if (postalCodeStart != B_ERROR) { postalCodeStart += 10; int32 postalCodeEnd = msgBody.FindFirst("\r\n",postalCodeStart); msgBody.CopyInto(userProfile.postalCode,postalCodeStart,postalCodeEnd-postalCodeStart); } int32 genderStart = msgBody.FindFirst("Gender"); if (genderStart != B_ERROR) { genderStart += 6; int32 genderEnd = msgBody.FindFirst("\r\n",genderStart); msgBody.CopyInto(userProfile.gender,genderStart,genderEnd-genderStart); } int32 kidStart = msgBody.FindFirst("Kid"); if (kidStart != B_ERROR) { kidStart += 3; int32 kidEnd = msgBody.FindFirst("\r\n",kidStart); BString kid; msgBody.CopyInto(kid,kidStart,kidEnd-kidStart); userProfile.kid = atoi(kid.String()); //bool, check if works! } int32 ageStart = msgBody.FindFirst("Age"); if (ageStart != B_ERROR) { ageStart += 3; int32 ageEnd = msgBody.FindFirst("\r\n",ageStart); BString age; msgBody.CopyInto(age,ageStart,ageEnd-ageStart); userProfile.age = atoi(age.String()); //bool, check if works! } int32 bDayPreStart = msgBody.FindFirst("BDayPre"); if (bDayPreStart != B_ERROR) { bDayPreStart += 7; int32 bDayPreEnd = msgBody.FindFirst("\r\n",bDayPreStart); msgBody.CopyInto(userProfile.bDayPre,bDayPreStart,bDayPreEnd-bDayPreStart); } int32 birthdayStart = msgBody.FindFirst("Birthday"); if (birthdayStart != B_ERROR) { birthdayStart += 8; int32 birthdayEnd = msgBody.FindFirst("\r\n",birthdayStart); BString birthday; msgBody.CopyInto(birthday,birthdayStart,birthdayEnd-birthdayStart); userProfile.birthday = atoi(birthday.String()); //bool, check if works! } int32 walletStart = msgBody.FindFirst("Wallet"); if (walletStart != B_ERROR) { walletStart += 8; int32 walletEnd = msgBody.FindFirst("\r\n",walletStart); BString wallet; msgBody.CopyInto(wallet,walletStart,walletEnd-walletStart); userProfile.wallet = atoi(wallet.String()); //bool, check if works! } int32 flagsStart = msgBody.FindFirst("Flags"); if (flagsStart != B_ERROR) { flagsStart += 5; int32 flagsEnd = msgBody.FindFirst("\r\n",flagsStart); BString flags; msgBody.CopyInto(flags,flagsStart,flagsEnd-flagsStart); userProfile.flags = atoi(flags.String()); //bool, check if works! } int32 sidStart = msgBody.FindFirst("sid"); if (sidStart != B_ERROR) { sidStart += 3; int32 sidEnd = msgBody.FindFirst("\r\n",sidStart); BString sid; msgBody.CopyInto(sid,sidStart,sidEnd-sidStart); userProfile.sid = atoi(sid.String()); } int32 kvStart = msgBody.FindFirst("kv"); if (kvStart != B_ERROR) { kvStart += 2; int32 kvEnd = msgBody.FindFirst("\r\n",kvStart); BString kv; msgBody.CopyInto(kv,kvStart,kvEnd-kvStart); userProfile.kv = atoi(kv.String()); } int32 mspAuthStart = msgBody.FindFirst("MSPAuth"); if (mspAuthStart != B_ERROR) { mspAuthStart += 7; int32 mspAuthEnd = msgBody.FindFirst("\r\n",mspAuthStart); msgBody.CopyInto(userProfile.mspAuth,mspAuthStart,mspAuthEnd-mspAuthStart); } int32 clientIPStart = msgBody.FindFirst("ClientIP"); if (clientIPStart != B_ERROR) { clientIPStart += 8; int32 clientIPEnd = msgBody.FindFirst("\r\n",clientIPStart); msgBody.CopyInto(userProfile.clientIP,clientIPStart,clientIPEnd-clientIPStart); } int32 clientPortStart = msgBody.FindFirst("ClientPort"); if (clientPortStart != B_ERROR) { clientPortStart += 10; int32 clientPortEnd = msgBody.FindFirst("\r\n",clientPortStart); BString clientPort; msgBody.CopyInto(clientPort,clientPortStart,clientPortEnd-clientPortStart); userProfile.clientPort = atoi(clientPort.String()); } //set the main user's profile Common::yo->setProfile(userProfile); } I thought of putting all information into a map structure...this is very flexible...but then we will get problems with different data types strings, ints, bools and dates....of course we could just store everything as strings but this maybe involves some casting of the information at the places they are needed....would that be a problem? regards, Tim _________________________________________________________________ Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 |