ICQ-клиент

Автор: Пользователь скрыл имя, 08 Апреля 2012 в 14:17, курсовая работа

Описание работы

В первые годы существования Всемирной паутины пользователи общались преимущественно через электронную почту, но отправлять письма было неудобно и даже нерационально, если оба собеседника одновременно находились в Интернете. Все изменилось, когда появились первые программы мгновенного общения или, менее официально, мессенджеры или интернет-пейджеры.

Содержание

Введение 5
1 Аналитический обзор литературы
1.1 Анализ предметной области
1.2 Сравнительная характеристика существующих аналогов 8
1.3 Постановка задачи 10
2 Модели, положенные в основу ПС
2.1 Функциональные модели
2.2 Разработка спецификации требований к программному средству 13
3 Разработка программного средства
3.1 Обоснование выбора среды разаработки
3.2 Особенности реализации
3.3 Разработка программной архитектуры
4 Тестирование программного средства
5 Методика работы с программным средством 20
Заключение
Список использованных источников
Приложение A. Листинг программного средства

Работа содержит 1 файл

KursKSIS.doc

— 841.00 Кб (Скачать)

 

        /// <summary>

        /// Requests a list of user interests from the server

        /// </summary>

        /// <exception cref="NotLoggedInException">Thrown when the <see cref="Session"/> is not logged in</exception>

        public void RequestInterestsList()

        {

            if (!LoggedIn)

            {

                throw new NotLoggedInException();

            }

 

            SNAC0F.RequestInterestList(this);

        }

 

        /// <summary>

        /// Sends an icq authorization request

        /// </summary>

        /// <param name="screenname">the destination screenname</param>

        /// <param name="reason">the request reason</param>

        public void SendAuthorizationRequest(string screenname, string reason)

        {

            if (!LoggedIn)

            {

                throw new NotLoggedInException();

            }

            // TODO reason string works only with ASCII encoding until now

            SNAC13.SendAuthorizationRequest(this, screenname, reason);

        }

 

        /// <summary>

        /// Sends an icq authorization response

        /// </summary>

        /// <param name="screenname">the destination screenname</param>

        /// <param name="grantAuthorization">true, if the authorization should be granted, otherwise false</param>

        /// <param name="reason">the reason for the decision</param>

        public void SendAuthorizationResponse(string screenname, bool grantAuthorization, string reason)

        {

            if (!LoggedIn)

            {

                throw new NotLoggedInException();

            }

            SNAC13.SendAuthorizationResponse(this, screenname, grantAuthorization, reason);

        }

 

        /// <summary>

        /// Grants the authorization to another screenname for the future

        /// </summary>

        /// <param name="screenname">The uin/screenname</param>

        /// <param name="reason">The reason message</param>

        /// <remarks>TODO ... seems to be obsolete in the current Oscar version</remarks>

        public void SendFutureAuthorizationGrant(string screenname, string reason)

        {

            if (!LoggedIn)

            {

                throw new NotLoggedInException();

            }

            SNAC13.SendFutureAuthorizationGrant(this, screenname, reason);

        }

 

        /// <summary>

        /// Sends a requests for the server side buddylist. Server should reply with

        /// the buddylist, or with the info that the client side buddylist is up to date

        /// <remarks>TODO have to be tested</remarks>

        /// </summary>

        public void SendContactListCheckout()

        {

            SendContactListCheckout(LastModificationDate);

        }

 

        /// <summary>

        /// Sends a requests for the server side buddylist. Server should reply with

        /// the buddylist, or with the info that the client side buddylist is up to date

        /// </summary>

        /// <param name="lastModificationDate">the date when the client side buddylist was updated the last time</param>

        /// <remarks>TODO have to be tested</remarks>

        public void SendContactListCheckout(DateTime lastModificationDate)

        {

            if (!LoggedIn)

            {

                throw new NotLoggedInException();

            }

            ushort localSSIItemCount = SSI.GetLocalSSIItemCount();

            SNAC13.SendContactListCheckout(this, LastModificationDate, true, localSSIItemCount);

        }

 

        #region File transfer methods

 

        /// <summary>

        /// Send a file to a remote client via a direct connection

        /// </summary>

        /// <param name="recipient">The screenname of the remote client</param>

        /// <param name="filename">The path of the file to send</param>

        /// <returns>A key with which to reference this file transfer, or "" if a warning was

        /// generated during the initialization process</returns>

        /// <exception cref="NotLoggedInException">Thrown when the <see cref="Session"/> is not logged in</exception>

        public Cookie SendFile(string recipient, string filename)

        {

            if (!LoggedIn)

            {

                throw new NotLoggedInException();

            }

 

            FileTransferConnection ftconn =

                Connections.CreateNewFileTransferConnection(DirectConnectionMethod.Direct, DirectConnectRole.Initiator);

            ftconn.Other.ScreenName = recipient;

            ftconn.LocalFileName = filename;

            ftconn.ConnectToServer();

            return ftconn.Cookie;

        }

 

        /// <summary>

        /// Start a DirectIM session with a remote client via a direct connection

        /// </summary>

        /// <param name="recipient">The screenname of the remote client</param>

        /// <param name="message">A message with which to invite the remote client</param>

        /// <returns>A key with which to reference this DirectIM session, or "" if a warning was

        /// generated during the initialization process</returns>

        /// <exception cref="NotLoggedInException">Thrown when the <see cref="Session"/> is not logged in</exception>

        public Cookie StartDirectIM(string recipient, string message)

        {

            if (!LoggedIn)

            {

                throw new NotLoggedInException();

            }

 

            DirectIMConnection dimconn =

                Connections.CreateNewDirectIMConnection(DirectConnectionMethod.Direct, DirectConnectRole.Initiator);

            dimconn.Other.ScreenName = recipient;

            dimconn.Message = message;

            dimconn.ConnectToServer();

            return dimconn.Cookie;

        }

 

        /// <summary>

        /// Send a file to a remote client via an AOL proxy

        /// </summary>

        /// <param name="recipient">The screenname of the remote client</param>

        /// <param name="filename">The path of the file to send</param>

        /// <returns>A key with which to reference this file transfer, or "" if a warning was

        /// generated during the initialization process</returns>

        /// <exception cref="NotLoggedInException">Thrown when the <see cref="Session"/> is not logged in</exception>

        public Cookie SendFileProxied(string recipient, string filename)

        {

            if (!LoggedIn)

            {

                throw new NotLoggedInException();

            }

 

            FileTransferConnection newconn =

                Connections.CreateNewFileTransferConnection(DirectConnectionMethod.Proxied, DirectConnectRole.Initiator);

            newconn.Other.ScreenName = recipient;

            newconn.LocalFileName = filename;

            newconn.ConnectToServer();

            return newconn.Cookie;

        }

 

        /// <summary>

        /// Start a DirectIM session with a remote client via an AOL proxy

        /// </summary>

        /// <param name="recipient">The screenname of the remote client</param>

        /// <param name="message">A message with which to invite the remote client</param>

        /// <returns>A key with which to reference this DirectIM session, or "" if a warning was

        /// generated during the initialization process</returns>

        /// <exception cref="NotLoggedInException">Thrown when the <see cref="Session"/> is not logged in</exception>

        public Cookie StartDirectIMProxied(string recipient, string message)

        {

            if (!LoggedIn)

            {

                throw new NotLoggedInException();

            }

 

            DirectIMConnection dimconn =

                Connections.CreateNewDirectIMConnection(DirectConnectionMethod.Proxied, DirectConnectRole.Initiator);

            dimconn.Other.ScreenName = recipient;

            dimconn.Message = message;

            dimconn.ConnectToServer();

            return dimconn.Cookie;

        }

 

        /// <summary>

        /// Accept an invitation to a DirectIM session

        /// </summary>

        /// <param name="key">The key received in the <see cref="OscarLib_DirectIMRequestReceived"/> event</param>

        public void AcceptDirectIMSession(Cookie key)

        {

            if (!LoggedIn)

            {

                throw new NotLoggedInException();

            }

 

            var conn = Connections.GetDirectConnectionByCookie(key) as DirectIMConnection;

            if (conn != null)

            {

                conn.ConnectToServer();

            }

            else

            {

                throw new Exception("Invalid DirectIM session key: \"" + key + "\"");

            }

        }

 

        /// <summary>

        /// Accept a file being sent to the client

        /// </summary>

        /// <param name="key">The key received in the <see cref="FileTransferRequestReceived"/> event</param>

        /// <param name="savelocation">The path to which to save the file</param>

        /// <exception cref="NotLoggedInException">Thrown when the <see cref="Session"/> is not logged in</exception>

        /// <exception cref="System.Exception">Thrown when <paramref name="key"/> is not a valid file transfer key</exception>

        public void AcceptFileTransfer(Cookie key, string savelocation)

        {

            if (!LoggedIn)

            {

                throw new NotLoggedInException();

            }

 

            var conn = Connections.GetDirectConnectionByCookie(key) as FileTransferConnection;

            if (conn != null)

            {

                conn.LocalFileName = savelocation;

                conn.ConnectToServer();

            }

            else

            {

                throw new Exception("Invalid file transfer key: \"" + key + "\"");

            }

        }

 

        /// <summary>

        /// Cancel a pending or in-progress file transfer

        /// </summary>

        /// <param name="key">The key received with the transfer request</param>

        /// <exception cref="NotLoggedInException">Thrown when the <see cref="Session"/> is not logged in</exception>

        /// <exception cref="System.Exception">Thrown when <paramref name="key"/> is not a valid file transfer key</exception>

        public void CancelFileTransfer(Cookie key)

        {

            if (!LoggedIn)

            {

                throw new NotLoggedInException();

            }

 

            var conn = Connections.GetDirectConnectionByCookie(key) as FileTransferConnection;

            if (conn != null)

            {

                conn.CancelFileTransfer("User cancelled transfer");

            }

        }

 

        /// <summary>

        /// Cancel a pending or in-progress Direct IM session

        /// </summary>

        /// <param name="key">The key received with the connection request</param>

        /// <exception cref="NotLoggedInException">Thrown when the <see cref="Session"/> is not logged in</exception>

        /// <exception cref="System.Exception">Thrown when <paramref name="key"/> is not a valid file transfer key</exception>

        public void CancelDirectIMSession(Cookie key)

        {

            if (!LoggedIn)

            {

                throw new NotLoggedInException();

            }

 

            var conn = Connections.GetDirectConnectionByCookie(key) as DirectIMConnection;

            if (conn != null)

            {

                Messages.SendDirectConnectionCancellation(conn, "User cancelled Direct Connection");

                conn.DisconnectFromServer(false);

            }

        }

 

        #endregion

 

        #endregion

 

        #region Internal methods

 

        /// <summary>

        /// Returns an MD5 hash of the client's password, an authorization key, and a constant string

        /// </summary>

        /// <param name="authkey">The authorization key sent by the server</param>

        /// <returns>A 16-byte MD5 hash</returns>

        /// <remarks>

        /// <para>

        /// The hashing process is fairly simple:

        /// <list>

        /// <item>The authorization key is put into a buffer</item>

        /// <item>The password itself is hashed via MD5 and appended to the buffer</item>

        /// <item>The constant string, "AOL Instant Messenger (SM)", is appended to the buffer in plaintext</item>

        /// <item>The entire buffer is MD5 hashed and returned to the caller</item>

        /// </list>

        /// </para>

        /// <para>

        /// This method exists to prevent the password from having to be passed around in a data structure

        /// </para>

        /// </remarks>

        protected internal byte[] HashPassword(byte[] authkey)

        {

            var md5 = new MD5CryptoServiceProvider();

 

            var stream = new ByteStream();

            stream.WriteByteArray(authkey);

            stream.WriteByteArray(md5.ComputeHash(Encoding.ASCII.GetBytes(_password)));

            stream.WriteString(Constants.AIM_MD5_STRING, Encoding.ASCII);

 

            return md5.ComputeHash(stream.GetBytes());

        }

 

        /// <summary>

        /// Stores data associated with a SNAC request/reply

        /// </summary>

        /// <param name="requestid">A SNAC request ID</param>

        /// <param name="data">The data to be stored</param>

        protected internal void StoreRequestID(uint requestid, object data)

        {

            _requestidstorage.Add(requestid, data);

        }

 

        /// <summary>

        /// Retrieves data associated with a SNAC request/reply

        /// </summary>

        /// <param name="requestid">A SNAC request ID</param>

        /// <returns>The data previously stored by <see cref="StoreRequestID"/></returns>

        protected internal object RetrieveRequestID(uint requestid)

        {

            return _requestidstorage[requestid];

        }

 

 

        /// <summary>

        /// Sets the session's privacy setting sent by the server in SNAC(13,06)

        /// </summary>

        /// <param name="ps">One of the <see cref="PrivacySetting"/> enumeration members</param>

        protected internal void SetPrivacyFromServer(PrivacySetting ps)

        {

            _privacy = ps;

        }

 

        /// <summary>

        /// Sets whether or not the client's idle time is public -- SNAC(13,06)

        /// </summary>

        /// <param name="publicidletime">true if others can see this client's idle time, false otherwise</param>

        protected internal void SetPresence(bool publicidletime)

        {

            _publicidletime = publicidletime;

        }

 

        /// <summary>

        /// Keeps track of the SNAC parameter responses that have been received thus far

        /// </summary>

        protected internal void ParameterSetArrived()

        {

            _parametercount++;

 

            if (_parametercount == 5)

            {

                // We can send more stuff now

            }

        }

 

        #endregion

 

        #region Properties

 

        #region Connection properties

 

        private ProxyType proxySetting = ProxyType.None;

 

        /// <summary>

        /// The username to use for a proxy server

        /// </summary>

        public string ProxyUsername { get; set; }

 

        /// <summary>

        /// The password to use for a proxy server

        /// </summary>

        public string ProxyPassword { get; set; }

 

        /// <summary>

        /// The proxy server to connect through

        /// </summary>

        public string ProxyServer { get; set; }

 

        /// <summary>

        /// The port to connect to on the proxy server

        /// </summary>

        public int ProxyPort { get; set; }

 

        /// <summary>

        /// The <see cref="ProxyType"/> to use for this connection

        /// </summary>

        public ProxyType ProxySetting

        {

            get { return proxySetting; }

            set { proxySetting = value; }

        }

 

        #endregion Connection properties

 

        private Encoding encoding;

 

        /// <summary>

        /// Gets or sets the screen name associated with this session

        /// </summary>

        /// <remarks>

        /// The screen name cannot be set by this property while the client is offline.

        /// When the client is online, setting the screen name by this property changes the

        /// screen name's formatting on the server.

        /// </remarks>

        /// <exception cref="ArgumentException">Thrown when <paramref name="screenname"/> is not

        /// a valid AIM or ICQ screenname.</exception>

        public string ScreenName

        {

            get { return _screenname; }

            set

            {

                if (LoggedIn)

                {

                    if (!(ScreennameVerifier.IsValidAIM(value) || ScreennameVerifier.IsValidICQ(value)))

                    {

                        throw new ArgumentException(value + " is not a valid AIM or ICQ screenname");

Информация о работе ICQ-клиент