Beispiel #1
0
        /// <summary>
        /// Get journals a user has community access to.
        /// </summary>
        /// <param name="username">The user's username.</param>
        /// <param name="password">The user's password.</param>
        /// <param name="serverURL">The server's URL.</param>
        /// <returns></returns>
        static public string[] GetUseJournals(string username, string password, string serverURL)
        {
            ILJServer iLJ;

            XMLStructs.GetChallengeResponse gcr;
            string auth_response;

            XMLStructs.LoginParams   lp;
            XMLStructs.LoginResponse lr;

            try
            {
                iLJ           = LJServerFactory.Create(serverURL);
                gcr           = iLJ.GetChallenge();
                auth_response = MD5Hasher.Compute(gcr.challenge + MD5Hasher.Compute(password));
                lp            = new XMLStructs.LoginParams(username, "challenge", gcr.challenge, auth_response, 1, clientVersion,
                                                           0, 0, 1, 1);
                lr = iLJ.Login(lp);
            }
            catch (CookComputing.XmlRpc.XmlRpcFaultException xfe)
            {
                throw new ExpectedSyncException(ExpectedError.InvalidPassword, xfe);
            }
            catch (System.Net.WebException we)
            {
                throw new ExpectedSyncException(ExpectedError.ServerNotResponding, we);
            }
            catch (CookComputing.XmlRpc.XmlRpcServerException xse)
            {
                throw new ExpectedSyncException(ExpectedError.ServerNotResponding, xse);
            }
            return(lr.usejournals);
        }
Beispiel #2
0
        static private void GetEvents(Journal.OptionsRow or, ILJServer iLJ, ref SyncItemCollection sic,
                                      ref SyncItemCollection deletedsic, ref EventCollection ec)
        {
            // for an explanation of this algorithm, see
            // http://www.livejournal.com/community/lj_clients/143312.html
            // note that this is a very painful algorithm.  it will loop an extra time for each
            // deleted syncitem that getevents doesn't return an event for.  if LJ decides to revise
            // how they return syncitems, this algorithm can be made more efficient.
            int total = sic.Count;

            while (sic.Count > 0)
            {
                SyncItem             oldest     = sic.GetOldest();
                DateTime             oldestTime = DateTime.Parse(oldest.time, CultureInfo.InvariantCulture).AddSeconds(-1);
                GetChallengeResponse gcr        = iLJ.GetChallenge();
                string          auth_response   = MD5Hasher.Compute(gcr.challenge + or.HPassword);
                GetEventsParams gep             = new GetEventsParams(or.UserName, "challenge", gcr.challenge,
                                                                      auth_response, 1, 0, 0, 0, "syncitems", oldestTime.ToString(_datetimeformat), 0, 0, 0, 0,
                                                                      string.Empty, 0, "unix", (or.IsUseJournalNull() ? string.Empty : or.UseJournal));
                GetEventsResponse ger;
                socb(new SyncOperationEventArgs(SyncOperation.GetEvents, total - sic.Count, total));
                ger = iLJ.GetEvents(gep);
                // remove this item in case it isn't returned by getevents
                // this signifies that the item has been deleted
                // this also ensures we don't get stuck in an endless loop
                sic.Remove(oldest);
                sic.RemoveDownloaded(ger.events);
                deletedsic.RemoveDownloaded(ger.events);
                ec.AddRange(ger.events);
            }
        }
Beispiel #3
0
        static private void SyncItems(Journal.OptionsRow or, ILJServer iLJ, ref SyncItemCollection sic,
                                      ref SyncItemCollection deletedsic, ref DateTime lastSync)
        {
            // syncitems returns a "meta" list of what events have changed since the last time we called syncitems
            // note that syncitems may be called more than once
            GetChallengeResponse gcr;
            string            auth_response;
            SyncItemsParams   sip;
            SyncItemsResponse sir;
            int total = -1, count = 0;

            lastSync = (or.IsLastSyncNull() ? DateTime.MinValue : or.LastSync);
            do
            {
                string lastSyncString = (lastSync == DateTime.MinValue ? string.Empty :
                                         lastSync.ToString(_datetimeformat));
                gcr           = iLJ.GetChallenge();
                auth_response = MD5Hasher.Compute(gcr.challenge + or.HPassword);
                sip           = new SyncItemsParams(or.UserName, "challenge", gcr.challenge, auth_response, 1,
                                                    lastSyncString, (or.IsUseJournalNull() ? string.Empty : or.UseJournal));
                sir    = iLJ.SyncItems(sip);
                total  = (total == -1 ? sir.total : total);
                count += sir.count;
                sic.AddRangeLog(sir.syncitems);
                deletedsic.AddRangeLog(sir.syncitems);
                if (sic.GetMostRecentTime() > lastSync)
                {
                    lastSync = sic.GetMostRecentTime();
                }
                socb(new SyncOperationEventArgs(SyncOperation.SyncItems, count, total));
            } while (sir.count < sir.total);
        }
Beispiel #4
0
 /// <summary>
 /// Sets the password of the journal.
 /// </summary>
 /// <param name="password">The new password to set.</param>
 public void SetPassword(string password)
 {
     if (base.Options.Rows.Count < 1)
     {
         throw new InvalidOperationException("Cannot set password without options row");
     }
     base.Options[0].HPassword = MD5Hasher.Compute(password);
 }
Beispiel #5
0
        static private void SessionGenerate(Journal.OptionsRow or, ILJServer iLJ, ref SessionGenerateResponse sgr)
        {
            // a session needs to be generated to talk to the livejournal web server
            // right now there is no export comments method on xmlrpc, so we get comments the ol' fashioned way -
            // with a web request
            GetChallengeResponse gcr  = iLJ.GetChallenge();
            string auth_response      = MD5Hasher.Compute(gcr.challenge + or.HPassword);
            SessionGenerateParams sgp = new SessionGenerateParams(or.UserName, "challenge", gcr.challenge,
                                                                  auth_response, 1, "long", 0);

            sgr = iLJ.SessionGenerate(sgp);
        }
Beispiel #6
0
        static private void Login(Journal.OptionsRow or, ILJServer iLJ, ref LoginResponse lr, ref string communityPicURL)
        {
            // logging in to the server gets back a lot of assorted metadata we need to store
            GetChallengeResponse gcr;
            string      auth_response;
            LoginParams lp;

            gcr           = iLJ.GetChallenge();
            auth_response = MD5Hasher.Compute(gcr.challenge + or.HPassword);
            lp            = new LoginParams(or.UserName, "challenge", gcr.challenge, auth_response, 1, clientVersion,
                                            j.GetMaxMoodID(), 0, 1, 1);
            lr = iLJ.Login(lp);
            // if downloading a community, we want the community's default user pic, not the user's
            if (!or.IsUseJournalNull())
            {
                communityPicURL = Server.GetDefaultPicURL(or.UseJournal, or.ServerURL, true);
            }
        }