Esempio n. 1
0
        /*
         * public http()
         * {
         *      statusCode = 0;
         *      errorString = String.Empty;
         *      contentType = String.Empty;
         * }
         */

        public string binaryStream2MD5File(page p, BinaryReader binStream, string contentType, string contentLength)
        {
            string appPath  = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
            md5    MD5      = new md5();
            string fullPath = appPath + MD5.compute(p._page);

            nsGlobalOutput.output.write("\n + Downloading " + p.GenerateURL() + " ... ");
            nsGlobalOutput.output.write("   - Content-Type: " + contentType);
            nsGlobalOutput.output.write("   - Content-Length: " + contentLength + " bytes \n");

            try
            {
                int    BUFFER_SIZE          = 4096;
                byte[] buf                  = new byte[BUFFER_SIZE];
                System.IO.FileStream stream = new System.IO.FileStream(fullPath, System.IO.FileMode.Create);
                int n = binStream.Read(buf, 0, BUFFER_SIZE);
                while (n > 0)
                {
                    stream.Write(buf, 0, n);
                    n = binStream.Read(buf, 0, BUFFER_SIZE);
                }
                stream.Close();
            }
            catch (Exception e)
            {
                nsGlobalOutput.output.write("Error: " + e.Message);
            }
            finally
            {
                binStream.Close();
            }

            return(fullPath);
        }
Esempio n. 2
0
        public bool addContent2Index(int i_host_id, string i_hostname, string i_page, string i_title, string i_anchorText, uint i_depthLevel, string i_text, string i_cache)
        {
            bool ret = true;
            md5  MD5 = new md5();

            string sql = "INSERT DELAYED INTO pages SET " +
                         "  host_id = " + i_host_id +
                         ", hostname = '" + myMySQLEscapeString(i_hostname) + "'" +
                         ", page='" + myMySQLEscapeString(i_page) + "'" +
                         ", title='" + myMySQLEscapeString(i_title) + "'" +
                         ", anchor_text='" + myMySQLEscapeString(i_anchorText) + "'" +
                         ", date=curdate(),time=curtime()" +
                         ", level=" + i_depthLevel +
                         ",`text`= '" + myMySQLEscapeString(i_text) + "'";


            sql += ",`html_md5`= '" + MD5.compute(i_text) + "' ";


            if (GlobalVars.args.cachingMode == 1)
            {
                sql += ",`cache`= '" + myMySQLEscapeString(i_cache) + "'";
            }
            else if (GlobalVars.args.cachingMode == 2)
            {
                sql += ",`cache`= COMPRESS('" + myMySQLEscapeString(i_cache) + "')";
            }

            GlobalVars.threadsVars.mutexMySQLPageList.WaitOne();
            try
            {
                ret = GlobalVars.mysqlConn.connPageList.executeSQLQuery(sql);
            }
            catch (Exception e)
            {
                nsGlobalOutput.output.write("SQL Error: " + e.Message + "\n\nSQL: -===[\n" + sql.Substring(0, 1000) + "\n]===-\n\n");
                ret = false;
            }
            finally
            {
                GlobalVars.threadsVars.mutexMySQLPageList.ReleaseMutex();
            }
            return(ret);
        }